Archive: nsDialog Finishing Touches


nsDialog Finishing Touches
Hello everybody, I am trying to use nsDialogs that will ask the user for a product key. I've pretty much got it to look the way I want, but does anybody know how to:

1.) Make the cursor appear in a text box so that a user can just start typing.

2.) Make it so hitting enter hits an OK button. I created the OK button it is not one of the ones that appear at the bottom.

3.) Make so after enter has been hit (the OK button) the focus moves to the next/install button. So you can just hit enter again to move to the next page if you want.

Thanks for the help everyone.


  1. Set focus to it using something similar to SetFocus.
  2. Send WM_NEXTDLGCTL to $HWNDPARENT, passing the button's HWND as the first parameter and 1 as the second. That might do it.
  3. Send it again but pass the HWND of the next button.

Thanks for the tips Kichik, but can you elaborate a little on how to do them? This is my first attempt with nsDialogs and I am a little confused.


Well, to send a message you use SendMessage and for the value of WM_NEXTDLGCTL you need WinMessages.nsh. What else?


I didn't know about WinMessages.nsh and had never used SendMessage before. What is the wparam and lparam that the help refers to?


Every message has an opening for two parameters. The first being wParam and the second being lParam (more here). I referred to those two as the first parameter and the second parameter in my reply. If you look up WM_NEXTDLGCTL in MSDN, you'll find reference to wParam and lParam explaining every possible value.


Okay so I think I'm begining to understand sending the message, so I can make hitting enter activate my OK button. How do I get my OK button's handle? I've tried the method described in the help with: FindWindow $1 "#32770" "" $HWNDPARENT to select the inner dialog and then using GetDlgItem but I am having no luck.


You already have that HWND. You get it from nsDialogs when you create it. It's pushed on the stack.


Thanks, Kichik I've gotten the buttons to be the focus and even enable and disable them to make it clearer. I have just one last thing to figure out.

I have the focus on the text box (by using SendMessage like with the buttons) so you can just start typing. I want to have it when you hit enter the OK button is hit. Do you know how to detect the enter key?


You don't need to detect the enter key. You just need to tell the dialog which button is the default. That is done using WM_NEXTDLGCTL. To set focus to the text box, you should use SetFocus() and not WM_NEXTDLGCTL.


I am not using any ini page files (that I know of at least) so how do I use SetFocus, and what is the number that the setfocus function wants?


Just call user32::SetFocus(), not Function SetFocus. You don't need the rest unless you have caret drawing problems and even then ShowCaret() should suffice.


Okay I tried the user32::SetFocus and I got it to set the focus on the text box, but when I include the SendMessage code only the text box or the button get focus (makes sense), but hitting enter after typing a key does nothing. Is there perhaps a way just to attach a function or event to the enter key?


Make sure you first send the message and only then call SetFocus as the message also sets the focus.


I am sending the message to make the OK button default, then I call SetFocus to make the focus the text box, and hitting enter after typing in a key doesn't do anything I have to tab down to the OK button and hit space. Hitting enter when the OK button is the focus doesn't activate it.


Fightin_Foo,

If you can hold on until next week, I can save you the grief. The registration plugin (see the plugins repository on the wiki) will start using nsDialogs with the release that's coming.


Attach the script so I can see what's wrong.


I cannot attach the script due to a confidentially agreement with my company. So I will just have to say what I am doing.

Create the label, text box, and ok button, moving them to the spot that I want them. I disable the back button, disable the next button, and send the message to make the OK button default, call setfocus to get focus on the text box.

When the text box is changed a function is called that gets the text and copies it to a variable

When the ok button is clicked it checks the key. If the key is valid it disables the ok button (enablewindow), enables the next button, and then sets focus on the next button (sendmessage)

Hopefully that is enough info to for you.


I think that nobody here will work for your company FOR FREE. Maybe your company should ask AfrowUK for a script ;)


Send WM_NEXTDLGCTL before disabling the next button. If that doesn't work, reproduce the script outside of its context.