- NSIS Discussion
- nsDialog Finishing Touches
Archive: nsDialog Finishing Touches
Fightin_Foo
4th December 2007 14:34 UTC
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.
kichik
4th December 2007 14:51 UTC
- Set focus to it using something similar to SetFocus.
- Send WM_NEXTDLGCTL to $HWNDPARENT, passing the button's HWND as the first parameter and 1 as the second. That might do it.
- Send it again but pass the HWND of the next button.
Fightin_Foo
4th December 2007 15:25 UTC
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.
kichik
4th December 2007 15:29 UTC
Well, to send a message you use SendMessage and for the value of WM_NEXTDLGCTL you need WinMessages.nsh. What else?
Fightin_Foo
4th December 2007 16:11 UTC
I didn't know about WinMessages.nsh and had never used SendMessage before. What is the wparam and lparam that the help refers to?
kichik
4th December 2007 16:20 UTC
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.
Fightin_Foo
4th December 2007 16:48 UTC
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.
kichik
4th December 2007 17:59 UTC
You already have that HWND. You get it from nsDialogs when you create it. It's pushed on the stack.
Fightin_Foo
4th December 2007 20:00 UTC
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?
kichik
4th December 2007 20:45 UTC
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.
Fightin_Foo
4th December 2007 21:03 UTC
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?
kichik
4th December 2007 21:06 UTC
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.
Fightin_Foo
4th December 2007 22:15 UTC
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?
kichik
5th December 2007 18:41 UTC
Make sure you first send the message and only then call SetFocus as the message also sets the focus.
Fightin_Foo
5th December 2007 19:57 UTC
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.
ClayDowling
5th December 2007 20:46 UTC
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.
kichik
5th December 2007 20:58 UTC
Attach the script so I can see what's wrong.
Fightin_Foo
5th December 2007 22:58 UTC
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.
pospec
6th December 2007 15:53 UTC
I think that nobody here will work for your company FOR FREE. Maybe your company should ask AfrowUK for a script ;)
kichik
6th December 2007 23:36 UTC
Send WM_NEXTDLGCTL before disabling the next button. If that doesn't work, reproduce the script outside of its context.