lloydtech
22nd March 2011 07:07 UTC
HWND of Destination folder
Hi,
I want to make sure that the user is installing to an empty folder. For that I would like to check whether the "Destination folder" is empty or not when the user changes the path. For this, how can I get the HWND of the "Destination folder" text box? or is there a better way to solve this?
Thanks,
Lloyd
MSG
22nd March 2011 07:13 UTC
Use winspy to get the control ID, then call GetDlgItem to get the HWND for that ID.
http://www.catch22.net/software/winspy
lloydtech
22nd March 2011 07:55 UTC
Section "MainSection" SEC01
SetOutPath "$INSTDIR"
GetDlgItem $DestFolderText $HWNDPARENT 1019
MessageBox MB_OK "$DestFolderText"
${NSD_OnChange} $DestFolderText ConfigInstallPathChange
At first, I wrote this code in "main section".Then I understood that the code in main section is executed only when we click "Install" button. The I moved the code to "OnInit" section. Then also "GetDlgItem" sets zero in "DestFolderText" variable. What is the right place to write "GetDlgItem" ?
The control id returned by WinSpy is 3FB, so I converted it into decimal, ie 1019.
Thanks a lot,
Lloyd
MSG
22nd March 2011 13:42 UTC
You can only get the HWND for an existing control, so you cannot GetDlgItem in .onInit or in a section. You need to use the SHOW function of the directory page.
!define MUI_PAGE_CUSTOMFUNCTION_SHOW YourFunction
!insertmacro MUI_PAGE_DIRECTORY
function YourFunction
GetDlgItem $DestFolderText $HWNDPARENT 1019
functionend
or something like that.
lloydtech
24th March 2011 10:56 UTC
This is how my code look like
!define MUI_PAGE_CUSTOMFUNCTION_SHOW DirDlgShow
!insertmacro MUI_PAGE_DIRECTORY
Function DirDlgShow
GetDlgItem $0 $HWNDPARENT 1019
${NSD_OnChange} $0 ConfigInstallPathChange
FunctionEnd
Here "GetDlgItem" returns "0" in $0. Further reading the documentation, I feel that FindWindow has to be used first to get the HANDLE of "MUI_PAGE_DIRECTORY", then we need to use "GetDlgItem" to get handle of the "text box". The I modified the code as given below
Function DirDlgShow
FindWindow $0 "#32770"
GetDlgItem $1 $0 1019
FunctionEnd
Here FindWindow returns some valid code, but the "GetDlgItem" returns "0" in $1 again. What is the right way to get the handle of the text box in directory selection box?
Thanks a lot,
Lloyd
Afrow UK
24th March 2011 11:12 UTC
The description for FindWindow shows the correct usage to get the handle of the inner window.
Stu
lloydtech
24th March 2011 11:19 UTC
Yes, I have tried
FindWindow $0 "#32770" "" $HWNDPARENT
without any success!
Thanks,
Lloyd
pengyou
24th March 2011 12:12 UTC
If your installer uses a DIRECTORY page to let the user select a directory and you want to ensure that the user has selected an empty directory surely you could just use a "leave" function for the DIRECTORY page?
If the selected directory is not empty then display a suitable message and use an Abort command in the "leave" function to keep the user at the DIRECTORY page.
lloydtech
24th March 2011 12:43 UTC
Thanks, this is a simple and elegant solution...
Lloyd