Skip to content
⌘ NSIS Forum Archive

Setting Focus

13 posts

Tanerax#

Setting Focus

I went through the forum looking and havn't managed to find a post regarding my particular circumstances to setting focus with custom dialogs.

I am looking for a way to change the focus of the "Install" to default to "Back" on the buttons at the bottom of the screen. For one of my custom dialogs.
Red Wine#
Instructor has wrote a very nice example at this thread,

Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.


You need only the SetFocus call with system plugin
Tanerax#
That has information on changing information on stuff located in the custom dialog but how do I get focus to a button that belongs to the ui (back button) ?
Red Wine#
Just found a thread that is identical to your request,

Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.
Tanerax#
Originally posted by Red Wine
back button id is 3, so GetDlgItem $0 $HWNDPARENT 3
I currently running with

GetDlgItem $r2 $HWNDPARENT 3
System::Call "user32::SetFocus(i r2)"

When I messagebox the $r2 value it comes out as the right handle according to my spy++ app but I can't seem to get this to actually set focus to cancel.

Is it possible that the installer is setting the Install Button to focus after the fact? thus overriding it?
Tanerax#
Originally posted by kichik
$R2 and $2 are not the same. For the System plug-in r2 is $2 and R2 is $R2.
So then the following should work?

GetDlgItem $2 $HWNDPARENT 3
System::Call "user32::SetFocus(i r2)"

Back is still not getting selected as a focus.. 🙁
kichik#
Hmm... You probably want to set it as the default button and not have focus on it. For that, there's WM_NEXTDLGCTL. Include WinMessages.nsh and use:
GetDlgItem $2 $HWNDPARENT 3
SendMessage $HWNDPARENT ${WM_NEXTDLGCTL} $2 1
Tanerax#
I am loading up a custom dialog using InstallOptions::initdialog so its after loading that, and before InstallOptions::show
Tanerax#
Originally posted by kichik
Hmm... You probably want to set it as the default button and not have focus on it. For that, there's WM_NEXTDLGCTL. Include WinMessages.nsh and use:
GetDlgItem $2 $HWNDPARENT 3
SendMessage $HWNDPARENT ${WM_NEXTDLGCTL} $2 1
Actually that worked perfectly thanks a bunch.