Archive: Set caption of a link control?


Set caption of a link control?
Hello all,

I'm trying to set the caption of a link/hyperlink control (the one provided by InstallOptions). The following does not work:


SendMessage <handle to the control> ${WM_SETTEXT} 0 "STR:http://whatever.net/"


I have verified that the control handle is correct by using..
ShowWindow <handle> 0

It disappears just fine.

Note that for the specific application, I cannot modify the .ini file before the dialog is displayed - the caption of the link would be modified when the user presses a button (which does some fancy things and the appropriate caption is chosen from its results) on the same dialog as this link control.

I'm probably missing something obvious - I'm just hoping that the obvious is -not- "You cannot do that".

Thanks in advance for any insights :)

Did you !include "WinMessages.nsh"? This is necessary to use "${WM_SETTEXT}".


yep... I'm using it on label controls and a button control, and it's working just fine on those. Here's a sample script. Note: this is with NSIS v2.06


!include "WinMessages.nsh"

Name ""
OutFile "Setup.exe"

Page Custom CustomPre CustomPost
Page InstFiles

Function .onInit
InitPluginsDir
File /oname=$PLUGINSDIR\test.ini test.ini
FunctionEnd

Function CustomPre
Push $R0
Push $R1
Push $R2

InstallOptions::initDialog /NOUNLOAD $PLUGINSDIR\test.ini
Pop $R0

GetDlgItem $R1 $R0 1200 ;1200 + Field number - 1

InstallOptions::show
Pop $R0

Pop $R2
Pop $R1
Pop $R0

FunctionEnd

Function CustomPost
ReadINIStr $0 "$PLUGINSDIR\test.ini" "Settings" "State"
IntCmp $0 0 _abort
IntCmp $0 1 _click
_click:
GetDlgItem $0 $R0 1200
SendMessage $0 ${WM_SETTEXT} "" "STR:FooBar"
GetDlgItem $0 $R0 1201
SendMessage $0 ${WM_SETTEXT} "" "STR:http://nsis.sourceforge.net/"
_abort:
Abort
FunctionEnd

Section "Test"
SectionEnd

I forgot... content of test.ini:


; Ini file generated by the HM NIS Edit IO designer.
[Settings]
NumFields=2

[Field 1]
Type=Button
Text=push me
Flags=NOTIFY
Left=100
Right=150
Top=30
Bottom=45

[Field 2]
Type=Link
Text=Link
Left=72
Right=181
Top=73
Bottom=81

Oh... now I remember why that doesn't work. "Link" controls draw the text only when the dialog starts up. InstallOptions has custom drawing functions specific for this control. WM_SETTEXT needs to be handled by the plug-in for this control in order to support drawing it after it is changed using that message (AFAIK).

I'm just hoping that the obvious is -not- "You cannot do that".
the obvious is that =(... and no workarounds...

d'oh...

Well I'm working on a work-around, and it works nearly perfectly, except for one thing - I need to change the focus from one control to another (any), or else if a user hits tab (as users invariably do), my link control pops back up and ruins my work-around.

Now I know it involves WM_KILLFOCUS and WM_SETFOCUS (I think both, not 100% sure), but be darned if I have the skill to know what the lParam and wParam bits should be. If you know, or just have a friendly pointer, please do type away :)


well, that should just be:


SendMessage <handle> ${WM_KILLFOCUS|WM_SETFOCUS} 0 0


Unfortunately, that link control refuses to lose focus. Grrr. :)

Alright, giving up. Too many problems with that approach.

Essentially I had a blank link control overlapping a label control. The label control was colored blue so as to appear like a link.

When the link control is pressed it, for reasons unknown to me, suddenly becomes opaque - so I have to re-show the label control.

Then there's the bit about not allowing the link control to be tabbed to, storing a URL in the label control's State value (not in the link, or it'll actually act like a link), making the link instead issue a NOTIFY, and using that to open the actual URL.

So far so good - where things go wrong:
As soon as I use ExecShell, that darn link control refuses to lose focus. Meaning that as soon as somebody alt-tabs back to the installer, or tabs from that control, my label has once again disappeared behind the link control that suddenly went opaque.
Perhaps the above is fixable, perhaps not.

The second issue is that if you mouseDown on the link control, then mouseUp outside of it, the link control still gets 'focus', turns opaque, but because you don't mouseUp on it, no NOTIFY is issued, and no chance is had to bring the label back to life. drat.

So, my only option, it appears, is to use a Button control instead. I guess I can still make its text blue :x


for the curious, here's the code up to the point where I'm giving up.

.nsi


!include "WinMessages.nsh"

Name ""
OutFile "Setup.exe"

Page Custom CustomPre CustomPost
Page InstFiles

Function .onInit
InitPluginsDir
File /oname=$PLUGINSDIR\test.ini test.ini
FunctionEnd

Function CustomPre
Push $R0
Push $R1
Push $R2

InstallOptions::initDialog /NOUNLOAD $PLUGINSDIR\test.ini
Pop $R0

; Change the color of the text so it appears like a link
GetDlgItem $0 $R0 1202 ; get the label control
ShowWindow $0 0 ; hide it
SetCtlColors $0 0x0000ff "transparent" ; change colors to blue on transparent
ShowWindow $0 1 ; and show it

InstallOptions::show
Pop $R0

Pop $R2
Pop $R1
Pop $R0

FunctionEnd

Function CustomPost
ReadINIStr $0 "$PLUGINSDIR\test.ini" "Settings" "State"
IntCmp $0 0 _NEXT
IntCmp $0 1 _CNN
IntCmp $0 2 _NSIS
IntCmp $0 4 _link
_cnn:
GetDlgItem $0 $R0 1202
ShowWindow $0 0
SendMessage $0 ${WM_SETTEXT} "" "STR:http://www.cnn.com/"
WriteIniStr "$PLUGINSDIR\test.ini" "Field 3" "State" "http://www.cnn.com/"
ShowWindow $0 1
Abort
_nsis:
GetDlgItem $0 $R0 1202
ShowWindow $0 0
SendMessage $0 ${WM_SETTEXT} "" "STR:http://nsis.sourceforge.net/"
WriteIniStr "$PLUGINSDIR\test.ini" "Field 3" "State" "http://nsis.sourceforge.net/"
ShowWindow $0 1
Abort
_link:
ReadIniStr $0 "$PLUGINSDIR\test.ini" "Field 3" "State"
ExecShell "open" $0
GetDlgItem $0 $R0 1203
SendMessage $0 ${WM_KILLFOCUS} 0 0
GetDlgItem $0 $R0 1200
SendMessage $0 ${WM_SETFOCUS} 0 0
GetDlgItem $0 $R0 1202
ShowWindow $0 0
ShowWindow $0 1
Abort
_next:
FunctionEnd

Section "Test"
SectionEnd


test.ini

[Settings]
NumFields=4

[Field 1]
Type=Button
Flags=NOTIFY
Text=CNN
Top=30
Left=64
Bottom=44
Right=114

[Field 2]
Type=Button
Flags=NOTIFY
Text=NSIS
Top=30
Left=132
Bottom=44
Right=182

[Field 3]
Type=Label
Flags=NOTABSTOP
Text=http://www.cnn.com/
State=http://www.cnn.com/
Top=56
Left=68
Bottom=64
Right=181

[Field 4]
Type=Link
Flags=NOTABSTOP|NOTIFY
Text=Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_Â_
State=
Top=56
Left=68
Bottom=64
Right=177

actually.. come to think of it. Is it possible to change button controls' borders? If so - I suppose I could just get rid of the button control's 3D border. For all intents and purposes, that should have it look like a plain ol' link control (as long as I make the text blue, too).


excepting, of course, that you can't set the text color of a Button control? *sigh* :)

I'll have to re-think this, or go with that iffy work-around after all.. hmm.


generic link text "Click here for more information" with a varying URL (still by means of NOTIFY, so I can use the "open in new browser window" function) is going to have to be it, looks like. Was hoping to show the actual URL on it so those who prefer typing it in, could. Perhaps elsewhere in the dialog. Hrm.

*kicks that link control* ;)


You could use the ToolTips plug-in to show the address of the link when the user hovers the mouse on it. Also, the tooltip disappears after the user clicked on the link, which might be seen as a feature :) or as a problem :(...


oooh.. good idea :) tooltip that disappears after the user clicked on the link... hmm.. permanently? will have to play with it.