哪种编程语言最适合实现Windows窗体对话框?(Which programming language is most fit for implementing a windows form dial

编程入门 行业动态 更新时间:2024-10-22 05:14:57
哪种编程语言最适合实现Windows窗体对话框?(Which programming language is most fit for implementing a windows form dialog?)

如何?

我想用几个按钮实现一个足够简单的对话框。

And how?

I want to implement an simple enough dialog with several buttons.

最满意答案

在Windows中运行一些简单对话框和一些相关代码的最简单方法之一是AutoHotKey 。 它也是免费的啤酒。

这是一个宏脚本环境,您可以将小程序编写为脚本(并将它们挂钩到键,这就是它的名称和原始目的)。

AHK是一种类似BASIC的小型脚本语言,它简单易用。 对于你想做的大多数小项目都足够好。


一个用例/经验

我根本不是Windows程序员; 我曾经在Delphi中编程,但现在我主要使用Java。 最近我的女朋友需要一些黑客攻击:她买了一个带有注册码的产品,其中一部分钥匙被贴上污迹。 我们需要的是一个程序来强制尝试程序注册对话框中所有可能丢失的字母/数字。 合法的黑客行为,如果你愿意的话。

我考虑过在Delphi中这样做,然后我开始思考哪些神秘的系统调用我需要进入另一个程序的GUI并将文本戳入输入对话框......结果在AHK中非常容易。 我需要大约10分钟来编写我的黑客程序,并且花了大约5分钟才找到正确的密钥。

如果我没记错的话,我的小程序甚至包括一个对话框,用于指定我们对密钥的了解,以及哪些地方必须是反复试验的。 当然还有一个“开始”按钮。


以示例更新

我真的希望我仍然拥有我上面描述的那个小剧本,但已经好几年了,我已经扔掉了。

我在网上挖出这个小宝石:

这是一个工作示例脚本,它使用计时器更改MsgBox对话框中按钮的名称。 虽然按钮名称已更改,但IfMsgBox命令仍需要按原始名称引用按钮。

#SingleInstance SetTimer, ChangeButtonNames, 50 MsgBox, 4, Add or Delete, Choose a button: IfMsgBox, YES MsgBox, You chose Add. else MsgBox, You chose Delete. return ChangeButtonNames: IfWinNotExist, Add or Delete return ; Keep waiting. SetTimer, ChangeButtonNames, off WinActivate ControlSetText, Button1, &Add ControlSetText, Button2, &Delete return

我同意这是一个愚蠢无用的计划; 我发现很难在网上找到有用的小例子。 编写AHK脚本的大多数人似乎喜欢在他们的作品中悬挂花边和口哨,直到他们最终成为完整的应用程序,不再适合作为小例子。

但是,很多有用的代码片段可以在AHK的教程和概述中找到:

http://www.autohotkey.com/docs/Tutorial.htm

他们谈论的大部分内容都是将某些功能悬挂在某些键上。 这就是AHK的开始,但同时它也是一种(大多数)成熟的Windows编程语言。 因此,不要过多关注关键映射的东西。

这是一个可爱的小脚本来运行记事本,然后发出一个消息框:

RunWait Notepad MsgBox The user has finished (Notepad has been closed).

这是一个小对话框,可以从用户那里获得一些输入:

MsgBox, 4, , Would you like to continue? IfMsgBox, No return ; Otherwise, the user picked yes. MsgBox You pressed YES.

One of the easiest ways to get some simple dialogs and a bit of associated code running in Windows is AutoHotKey. It's free-as-in-beer, too.

It's a macro script environment where you can write little programs as scripts (and hook them to keys, that's where it got its name and original purpose).

AHK is a BASIC-like tiny scripting language that's all about simplicity and ease of use. Good enough for most small projects you'd care to do.


One use case/experience

I'm not a Windows programmer at all; I used to program in Delphi a bit, but now I'm mostly working in Java. Recently my girlfriend needed a bit of hacking: She bought a product with a registration key, and part of that key was smudged off the sticker. What we needed was a program to brute-force try all the possible missing letters/numbers in the program's registration dialog. Legitimate hacking, if you will.

I considered doing this in Delphi, then I started thinking about which arcane system calls I'd be needing to reach into the GUI of another program and to poke text into the input dialog... it turned out to be very easy in AHK. I needed about 10 minutes to write my hacking program, and it took about 5 minutes to find the right key.

If I remember correctly, my little program even included a dialog for specifying what we knew of the key, and which places had to be trial-and-errored. And of course a "start" button.


Update with example

I really wish I still had that little script I wrote as described above, but it's been several years and I've thrown it away.

I dug up this little gem on the net:

This is a working example script that uses a timer to change the names of the buttons in a MsgBox dialog. Although the button names are changed, the IfMsgBox command still requires that the buttons be referred to by their original names.

#SingleInstance SetTimer, ChangeButtonNames, 50 MsgBox, 4, Add or Delete, Choose a button: IfMsgBox, YES MsgBox, You chose Add. else MsgBox, You chose Delete. return ChangeButtonNames: IfWinNotExist, Add or Delete return ; Keep waiting. SetTimer, ChangeButtonNames, off WinActivate ControlSetText, Button1, &Add ControlSetText, Button2, &Delete return

I agree that this is a silly and useless program; I found it quite hard to find useful small examples on the 'net. Most of the people who write AHK scripts seem to enjoy hanging bells and whistles off their creations until they end up being full-fledged applications and no longer suitable as small examples.

A lot of useful snippets of code, though, can be found in AHK's Tutorial and overview:

http://www.autohotkey.com/docs/Tutorial.htm

Much of what they talk about is hanging certain capabilities off certain keys. This is how AHK started, but meanwhile it's a (mostly) full-fledged Windows programming language. So don't pay too much attention to the key mapping stuff.

Here's a cute little script to run Notepad and then issue a message box:

RunWait Notepad MsgBox The user has finished (Notepad has been closed).

Here's a small dialog to get some input from a user:

MsgBox, 4, , Would you like to continue? IfMsgBox, No return ; Otherwise, the user picked yes. MsgBox You pressed YES.

更多推荐

本文发布于:2023-07-18 04:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1154892.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗体   最适合   哪种   对话框   编程语言

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!