views:

101

answers:

2

And how?

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

+2  A: 

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.
Carl Smotricz
Can you provide a simple demo?I've never heard of this language.
I have done so now.
Carl Smotricz
+3  A: 

vb.net or c#.net both use .net framework. You can create a windows forms project that has rich user interface for buttons,forms,labels,grids... it is also very simple to start with using visual studio beucase visual studio has options to write parts of the code for you.

Microgen
And they are free download at: http://www.microsoft.com/exPress/
Nifle