Skip to content
⌘ NSIS Forum Archive

SendMessage to close "browse" from directory_page

6 posts

watdafox#

SendMessage to close "browse" from directory_page

Hi,

I'm trying to enhance the installer we use for an opensource application, but I'm stuck with the whole SendMessage thing.

Here is what I currently have:
- Using MUI 2, offer the default "DIRECTORY_PAGE" allowing to choose an install directory
- With a .onVerifyInstDir function, check if the chosen directory is eligible
- If eligible, .onVerifyInstDir does nothing

But here's what I would like to do:
- If not eligible, I would like to close the "Browse" window opened from DIRECTORY_PAGE.

The code is like this:


MessageBox MB_OK|MB_USERICON "Cannot require admin privileges" IDOK true
true:
;TODO:close browser
Abort
---

Here's a screenshot to illustrate:



On click 1, simulate click 2.



I tried some things, but no luck so far.
SendMessage $hwndparent ${WM_COMMAND} 3 0
allows me to trigger "previous" button, but it doesn't close the browser.

---


FindWindow $1 "#32770" "" $HWNDPARENT
SendMessage $1 ${WM_CLOSE} 0 0
this is a snippet that I found here, but it doesn't do anything.

Could you please help me ? Thanks !
Anders#
NSIS already has built-in support for handling this dialog: if you call "Abort" in .onVerifyInstDir then the OK button is disabled.

If you still want to cancel the dialog you can try this:

InstallDir $ProgramFiles32\Test
Page Directory
Page InstFiles

!include LogicLib.nsh
!include WinMessages.nsh
Function CloseBrowseForFolderDialog
!ifmacrodef "_P<>" ; NSIS 3+
System::Call 'USER32::GetActiveWindow()p.r0'
${If} $0 P<> $HwndParent
!else
System::Call 'USER32::GetActiveWindow()i.r0'
${If} $0 <> $HwndParent
!endif
SendMessage $0 ${WM_CLOSE} 0 0
${EndIf}
FunctionEnd

Function .onVerifyInstDir
${If} $WinDir == $InstDir
Call CloseBrowseForFolderDialog
${EndIf}
FunctionEnd
watdafox#
Thanks for your answer !

I saw that the "abort" was cancelling the 'OK' button, but sadly it doesn't fit my needs, as it's not working for every subfolder (unless I bind yet another function with recursion search to see if topdirectory is what I want to prevent).

Sadly, your code doesn't seem to work. No errors in compiling, but it doesn't seem to close the browser. Could it be because it's binded to the "MB_OK" window ? I guess not but it might be worth asking.

edit: here's the entire code if needed
Anders#
I don't really understand what you are trying to do, displaying a messagebox AND closing the dialog does not make sense to me but you can try this and see if it is what your want:

InstallDir $ProgramFiles32\Test
Page Directory
Page InstFiles

!include LogicLib.nsh
!include WinMessages.nsh
Function CloseBrowseForFolderDialogWithMessage
System::Call 'USER32::GetActiveWindow()i.r0'
${If} $0 <> $HwndParent
System::Call 'USER32::MessageBox(ir0,ts,t"$(^SetupCaption)",i0x10)'
SendMessage $0 ${WM_CLOSE} 0 0
${EndIf}
FunctionEnd

Function .onVerifyInstDir
${If} $WinDir == $InstDir
Push "Blah blah"
Call CloseBrowseForFolderDialogWithMessage
Abort
${EndIf}
FunctionEnd
watdafox#
EDIT: AAAAAH ! Sorry ! The 1st one works 🙂 Thanks !

My error was:
- Display the MB then trigger the close function (instead of the opposite: close then display MB)

Thanks a bunch ! 🙂
aerDNA#
Function .onVerifyInstDir
StrLen $0 $PROGRAMFILES
StrCpy $0 "$INSTDIR" $0
StrCmp $0 "$PROGRAMFILES" +4
StrLen $0 $PROGRAMFILES64
StrCpy $0 "$INSTDIR" $0
StrCmp $0 "$PROGRAMFILES64" 0 +2
Abort
FunctionEnd 
Prevents selection of Program Files + subfolders.

Edit: this was in reply to the question you removed.