Archive: changing text on controls using SendMessage


changing text on controls using SendMessage
I've been trying for about a week to figure out how to use the FindWindow, GetDlgItem and SendMessage functions in my scripts without success.

I take that back, I have been able to change the branding text.
I haven't been able to change text on an item inside the dialog.

I have the following code inside a function that is called from the page definition.

i.e.


Page components LoadCurrentLabel


Function LoadCurrentLabel
ReadRegStr $0 HKCU "SOFTWARE\my\program" "CurrentLabel"
FindWindow $1 "#32770"
GetDlgItem $1 $HWNDPARENT 1022
SendMessage $1 ${WM_SETTEXT} 0 "STR:Current Label: $0"
FunctionEnd


however, this doesn't work.

I've tried Id#'s
1006, 1021, 1022

the only one I can get it to work with is the branding text 1028.

any suggestions?

thanks,

-Tim

You are using the wrong method of getting the inner dialog HWND. You should use:

FindWindow $0 "#32770" "" $HWNDPARENT

And only then use GetDlgItem to get the HWND to the dialog item:

GetDlgItem $0 $0 <control id>

The MUI does a lot of UI manipulation so Contrib\Modern UI\System.nsh contains a lot of such examples.


I just figured out what I was doing wrong.

I was trying to set labels in the pre-function. I switched to...


Page components "" LoadCurrentLabel

Function LoadCurrentLabel
ReadRegStr $0 HKCU "SOFTWARE\my\program" "CurrentLabel"
FindWindow $1 "#32770" "" $HWNDPARENT
GetDlgItem $1 $HWNDPARENT 1022
SendMessage $1 ${WM_SETTEXT} 0 "STR:Current Label: $0"
FunctionEnd


and now it's working.

thanks!

-Tim