Archive: HWND of Destination folder


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


Use winspy to get the control ID, then call GetDlgItem to get the HWND for that ID.

http://www.catch22.net/software/winspy



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

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.


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

The description for FindWindow shows the correct usage to get the handle of the inner window.

Stu


Yes, I have tried

  FindWindow $0 "#32770" "" $HWNDPARENT


without any success!

Thanks,
Lloyd

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.


Thanks, this is a simple and elegant solution...

Lloyd