Archive: Function request


Function request
I would like to request a function that is called when Abort is called in a section (or similar).

Why? I'll answer that now. If the user minimizes the install, and it fails, you would never know about it. But with this function, you could restore the window to let the user know. I want to use it to unload my SpiderBanner plugin and show the original window, and show "Install failed" on the DetailPrint label.

I don't have enough knowledge to implement this myself into NSIS, but if I figure it out before you guys, I will post a patch.

Comments welcome.


You could check if the window is minimized as the last instruction in your sections and then restore


!include LogicLib.nsh
!include winmessages.nsh

Section LastSection
...
System::Call 'user32::GetWindowLong(i $hwndparent,i -16)i.r0'
IntOp $0 $0 & 0x20000000
${IfThen} $0 > 0 ${|} ShowWindow $HWNDPARENT ${SW_RESTORE} ${|}
SectionEnd


True, but if the installer fails for some reason, execution stops at the current command (like using abort). So you code will not be executed, leaving the window minimized. Thats what I want my abort function for, so that your code is executed if it fails.


The leave function is still called. In there, you can use IfAbort.

Function leave
IfAbort 0 +2
MessageBox MB_OK abort
FunctionEnd

It appears my plugin hates being destroyed in a leave function, just as much as it hates being created in a pre or show function.

My plugin deals with window placement of the installer window, and it looks like it gets stuck in a loop somewhere. My plugin only works when called inside a section.


That's probably because you start it in a section, which is executed in a different thread than the leave function which is executed in the GUI thread.


I have made some small adjustments in my destroy function.

I changed PostMessage into SendMessage to close the banner window, and I refreshed the global hwndparent with the hwnd passed with the destroy function. This seems to have fixed the problem with the leave function.

I'm not going to change the show function in my plugin to work in the pre function, it should only be created in a section.

Thanks guys, I used the code given by kichik, and now it works the way I want it to.