Archive: Changing default button fuctions in nsDialogPage


Changing default button fuctions in nsDialogPage
Hey guys

Ok, so I am a super n00b at this...so bear with me.

What I am aiming to do is create a single custom page which has two buttons - each of them point to a different installer (the other installers already work - I didn't make them though).

I have looked at a few tutorials and have managed to make a blank custom page using 'Page custom nsDialogsPage'. This gives me a blank page with two buttons - Cancel and Quit. I have figured out how to add the code for the other two buttons I want which point to the other installers.

My question is...how do I change the function or text of the two default buttons - Cancel and Quit? It would be nice to keep the Quit button and change the text of the Cancel button to 'More'. Also, I would like the 'More' button to open a webpage, but I don't want the webpage to open when I click on the red X in the upper corner of the window.


You can get those buttons using...


GetDlgItem $0 $HWNDPARENT 3 ; Back Button
GetDlgItem $1 $HWNDPARENT 1 ; Next/Close Button
GetDlgItem $2 $HWNDPARENT 2 ; Cancel Button


You can change the text on them using...

SendMessage $0 ${WM_SETTEXT} 0 "STR:Your Text Here"


You can hide them using..

ShowWindow $0 ${SW_HIDE} ; ${SW_SHOW}


Disable using..

EnableWindow $0 0 ; 1


But you can't really modify their behavior.
If the 'Quit' button you mention is actually the 'Next' button, you could just create another custom page after the one you've already made, and launch the webpage in that new custom page.
The red X is hooked up to the Cancel button, which you could re-label Quit if you'd like.

Ok, awesome. Thanks for the reply!

After I posted this I mucked around a bit more and came to the conclusion you mentioned - to hook up the Next button to open a blank page which launches the webpage. So, yay for figuring that out.

After the code to launch the webpage I added a Call to relauch my original page so my installer would stop closing on me. So now the fuction for the 'Next' button looks like this:

Function Next
ExecShell "open" "http://www.yahoo.com"
Call nsDialogsWelcome
FunctionEnd

When this runs the webpage opens and the original installer page opens (like I want it to), but the 'Next' and Quit buttons are now gone and replaced by a single Back button. Clicking this Back button takes me to the original installer page, but minus the 'next' and quit buttons. All I want is for the original installer window to remain up when the 'Next' button is clicked and for a webpage to open. Am I coding this completely wrong to do what I want?


my mistake - better off using this:


!addplugindir "."
!addincludedir "."

!include "nsDialogs.nsh"
!include "winmessages.nsh"
!include "logiclib.nsh"

; !include "MUI2.nsh"

OutFile "test.exe"

var dialog
var hwnd
var null

Page Custom page.custom page.custom.next

Function page.custom
nsDialogs::Create 1018
Pop $dialog

${NSD_CreateButton} 0 0 50% 10% "A"
Pop $hwnd
${NSD_OnClick} $hwnd page.custom.buttonA.onclick
${NSD_CreateButton} 50% 0 50% 10% "B"
Pop $hwnd
${NSD_OnClick} $hwnd page.custom.buttonB.onclick

GetDlgItem $0 $HWNDPARENT 3 ; Back Button
GetDlgItem $1 $HWNDPARENT 1 ; Next/Close Button
GetDlgItem $2 $HWNDPARENT 2 ; Cancel Button

${NSD_SetText} $1 "More Info..."

nsDialogs::Show
FunctionEnd
Function page.custom.buttonA.onclick
MessageBox MB_OK "A"
FunctionEnd
Function page.custom.buttonB.onclick
MessageBox MB_OK "B"
FunctionEnd

Function page.custom.next
ExecShell "open" "http://www.winamp.com/"
Abort
FunctionEnd

Section
SectionEnd

; !insertmacro MUI_LANGUAGE "English"

So that 'page.custom.next' is called in the first Custom Page's 'leave' callback. 'page.custom.next' then calls 'Abort' to prevent the Next click from actually moving on to the next page / closing the installer (if the last page).

Thanks Animaether...That is exactly what I am looking for!! That was also a much easier way to do what I wanted. There was easily double that code on my end to get the same effect.

I do have another question. I copy n pasted your example and complied it and the installer did not close when clicking the More Info button (YAY). When I re-edited my code to match yours the More Info button closed the installer (BOO).

I am curious as to what exactly tells the installer not to close when that button is clicked. From what you are saying it sounds like that 'Abort' call in the Next function should do that.

My next function looks like this:

Function page.custom.next
ExecShell "open" "http://www.yahoo.com"
Abort
FunctionEnd

Same as yours, but just pointing to Yahoo. Is there some sort of parameter that is critical to call outside of this function in order to get my desired effect? Now, I am just curious.


It looks like I jsut answered my own question. I started playing around with my code and I had this setup on my end.

Page custom page.custom
Page custom page.custom.next

And you had:

Page custom page.custom page.custom.next


I changed mine to look like yours and the installer no longer closed when clicking the More Info button (YAY). Why is that? Is it because I do not want to go to a second page therefor I do not define a second page? I assumed the 'page.custom.next' was defining a 2nd page.


it -was- defining a 2nd page (with that second "Page custom page.custom.next" line), but now we're just re-using it (with different code inside that function) as the first page's 'leave' function.

A custom page basically has 2 functions... 1 function to create it, and another when the user leaves it by pressing the Next button (or 'close' if it's so-labeled.. still the same button).

If you don't need another page - then there's no real use in creating one; just handle it in the current page's leave function :)


Interesting...good to know! Thanks a lot for the help! :D