Archive: Override <Cancel> button action?


Override <Cancel> button action?
Hi all,

There *has* to be a thread that has this already, but for the life of me, I cannot find it!

What I want to do, is change the <Cancel> button to be <Skip> instead.

I was able to change the text of the button just fine.

But I am unable to figure out how to get the *action* of the button to not act like <Cancel> but instead to act like something else, or to call a special function instead...

I even tried tossing in a hook into ".onUserAbort", which kinda works, but not really.
I suspect there is a much easier way to do this, but I just cannot figure it out...

Any thoughts? Suggestions?

Thanks!
Scott


Post a sample code where ".onUserAbort" does not work as you expect it to do.


Hi Red Wine,

Okay.
I am using UMUI, which allows me to define a custom function for abort.
(I suspect MUI does too)

I do:
!define MUI_CUSTOMFUNCTION_ABORT "CustomAbort"

The function I use is:

Function CustomAbort
${If} "$CANCEL_IS_REALLY_SKIP" == "1"
Abort
${Endif}

${If} "$CANCEL_IS_REALLY_SKIP" != "1"
!ifdef MUI_FINISHPAGE_ABORTWARNINGCHECK
StrCmp $MUI_NOABORTWARNING "1" mui.quit
!endif

MessageBox MB_YESNO|MB_ICONEXCLAMATION "Are you sure you want to quit ${APP_NAME}?" IDYES mui.quit

Abort
mui.quit:
${Endif}
FunctionEnd


I have 2 problems with doing this...

1) "Abort" just returns without bailing. I need it to either call my "Show" or "Leave" function for that InstallOption/custom page.
This would allow me to "skip" over the current page, if needed.
If I do nothing in there, the Installer quits with no message, which I guess we should expect.

2) The harder part.
I need to keep track whether the page they are on wants the "cancel" to act like a real <Cancel> button or it should act like a <Skip> button...

Or maybe this can be solved by doing a GETTEXT off the button when in my custom abort function?

Thanks!
Scott


I don't understand sorry...
Is it a custom page the page you want to skip?
If so things are easier, because after the plugin call you pop from stack "back" "cancel" or "success"


Hi Red Wine,

Yes this is all in a custom page (using InstallOptions).

I just now added a lame check in my "CustomAbort" function to see if the <Cancel> button has text "cancel" or "Skip >"

By doing this:

GetDlgItem $1 $HWNDPARENT 2
StrCpy $4 ""
System::Call "user32::SendMessage(i,i,i,i)i (r1,${WM_GETTEXT}, 10,t.r3).r4"

${If} "$3" == "Skip >"
Abort
${Endif}


This works.

So now when I click on "Skip >" (ie, the <Cancel> button renamed), my script does that "Abort" above.
This is good.

Now, how do I notify the "custom" page that the user pressed <Skip> ?
We return an "Abort", but how do I get this?
If I return an "Abort", does my "Leave" custom function get called?

Thanks again for your quick responses!
Scott


You don't really need this:

GetDlgItem $1 $HWNDPARENT 2
StrCpy $4 ""
System::Call "user32::SendMessage(i,i,i,i)i (r1,${WM_GETTEXT}, 10,t.r3).r4"

${If} "$3" == "Skip >"
Abort
${Endif}

Actually it's the custom page who notifies you which button is pressed, try this:
InstallOptions::Dialog "$PLUGINSDIR\custom.ini"
pop $0
messagebox mb_ok "$0"

Also review the documentation would be a good idea. ;)

Hi Red Wine,

I think I am not describing the situation right. =)

In my Installer, I need the <cancel> button to sometimes act like a real "cancel" button, ie, bail out of the Installer.

But there are a couple "custom" pages where I need to override the <cancel> button, and its actions.

Since the <Cancel> button seems to be a "global" thing, where if the user presses it, it always calls the global
"onUserAbort" function.

Because of this, I need to determine whether the current "cancel" button is really <Cancel>, or is overridden with a <Skip> instead.

If its a <Cancel>, It should bail like it normally should.
However, if its a <Skip>, I need to *not* bail, but instead, do some custom stuff, and then skip to the next page. (ie, almost like they pressed <Next>).

I am able to trap the <Skip> in the global "onUserAbort" function, and instead of doing an "Abort", I now do a "Return".

This allows me to do the Pop after the SHOW like you suggest, and I get "cancel".

This is good.

But it seems like no matter what I do after this Pop,
the Installer always wants to quit!
I don't want it to quit, but instead, shift to the next dialog...
(ie, it should act like the user pressed <Next>)

Scott


I got it now, the plugin return won't help because is called after the function .onuserabort, but this seems to work

!define CUST_INI "$PLUGINSDIR\custom.ini"

var page_id

InstallDir "$EXEDIR"
outfile 'test.exe'

page custom CreateCustom LeaveCustom
page components
page directory
page instfiles

section boo

sectionend

Function .onInit
InitPluginsDir
WriteINIStr "${CUST_INI}" "Settings" "NumFields" "1"
WriteINIStr "${CUST_INI}" "field 1" "type" "text"
WriteINIStr "${CUST_INI}" "field 1" "left" "50"
WriteINIStr "${CUST_INI}" "field 1" "right" "-50"
WriteINIStr "${CUST_INI}" "field 1" "top" "40"
WriteINIStr "${CUST_INI}" "field 1" "bottom" "52"
WriteINIStr "${CUST_INI}" "field 1" "state" "sample text"
FunctionEnd

Function CreateCustom
StrCpy $page_id "custom"
push $0
InstallOptions::Dialog "${CUST_INI}"
pop $0
pop $0
FunctionEnd

function LeaveCustom
StrCpy $page_id ""
functionend

function .onuserabort
StrCmp $page_id "custom" 0 end
SendMessage $HWNDPARENT "0x408" "1" ""
abort
end:
functionend

Also take a look here,

http://nsis.sourceforge.net/Go_to_a_NSIS_page

Bingo!

That is *exactly* what I was looking for.
That URL is perfect!
It works exactly like I wanted it to.

Thanks again!
Scott