Archive: change default push button


change default push button
  Hi there,

I am using MUI2 and created a textfield and a button on a custom page.

If the user writes something into the textfield I would like the button to be pushed as soon as return/enter is pushed. (much like the behavior of "run.exe")

${NSD_CreateText} 35% 0 25% 12u ""
Pop $SearchField
${NSD_CreateButton} 60% 0 5% 12u "="
Pop $SearchBTN


After reading documentations and forum post for hours I believe "DM_SETDEFID" (!define DM_SETDEFID 0x401) to be the solution I need. But I cannot get it to work. Maybe I am even using 'SendMessage' wrong.

Could somebody profide an example or post an idea on how to solve this?

http://forums.winamp.com/showthread.php?t=334783


@jpderuiter
already tried this before but with no luck.



Just wrote a basic script I would like you to take a look at please.
I believe I am totally missing something here ...


;--------------------------------

;Include

!include "MUI2.nsh"
!include "nsDialogs.nsh"
!include "LogicLib.nsh"
!include "winmessages.nsh"


>;--------------------------------
;General

Name "ChangeDefaultButton"
OutFile "ChangeDefaultButton.exe"

InstallDir "$EXEDIR"

RequestExecutionLevel user


>;--------------------------------
;Variables

Var Dialog
Var SearchBox
Var SearchBTN


>;--------------------------------
;Definitions

!define DM_SETDEFID 0x401


>;--------------------------------
;Pages

Page custom nsDialogsSearchPage "SearchPage_leave"
!insertmacro MUI_PAGE_INSTFILES


>;--------------------------------
;Languages

!insertmacro MUI_LANGUAGE "English"


>;--------------------------------
;Sections

Section DummySection

SectionEnd


>;--------------------------------
;Functions

>Function nsDialogsSearchPage

!insertmacro MUI_HEADER_TEXT "SearchPage" "Is ENTER working for you?"

nsDialogs::Create 1018
Pop $Dialog

${If} $Dialog == error
Abort
${EndIf}


${
NSD_CreateText} 20% 40% 40% 12u ""
Pop $SearchBox

${NSD_CreateButton} 60% 40% 10% 12u "search"
Pop $SearchBTN

${NSD_OnClick} $SearchBTN OnClick_Search

# with $HWNDPARENT there will be no errorsound while pushing enter; but it will not activate SearchBTN either
# if $HWNDPARENT is replaced by $SearchBox, NEXT/INSTALL button becomes the default button again
SendMessage $HWNDPARENT ${DM_SETDEFID} $SearchBTN 0

# just so you can write directly into searchBox when the page is created:
SendMessage $HWNDPARENT ${WM_NEXTDLGCTL} $SearchBox 1

nsDialogs::Show

FunctionEnd

>Function SearchPage_Leave

Abort

FunctionEnd

>Function OnClick_Search

MessageBox MB_OK "SearchBTN was clicked ..."

>FunctionEnd
>

The WPARAM (first parameter) for the DM_SETDEFID message should not be the button handle, it has to be the button id.

For your example program, that is 1201. The thread that jpderuiter pointed out to you makes that clear (the original poster in that thread did the same mistake). Your program will work when you change line 81 to read

SendMessage $HWNDPARENT ${DM_SETDEFID} 1201 0
The first control you created (the edit box) will be 1200, then they count up from there.

Don

Thank you very much!
It's working almost perfectly!

My appologies for asking a already answered question a second time --> I did not get the "$mui.Button.Back.Id", sorry for that.


Just one thing that still confuses me:
With this method all non-buttons (texts, layers...) get the default pushable button set to the specified ID. I believe I have to change the 'HWNDPARENT'-part but neither ID nor $SearchField seems to work...
Is it possible to just change the default button of one 'edit' field?


The default button is a dialog setting, it applies to the entire dialog. (That's why the SetDefaultId message name begins with DM - Dialog Message).

You could change the default button as the user navigates around on the form, but you'll need to capture events that occur when controls get and lose focus. I don't know if NsDialogs gives you that fine a level of control.

Don


Thanks for your help and clarification! I really appreciate it!