I’m trying to imitate a hyperlink on a dialog using C++.
I’m using a static control with SS_NOTIFY set so that a user can click the control and go to a webpage:
LTEXT "Caption2",IDC_SETTINGS,9,36,219,13,SS_NOTIFY
With SS_NOTIFY set I can intercept the click, as it’s registered against the static:
case IDC_STC_URL:
ShellExecute(NULL, "open", "http://google.co.uk", NULL, NULL, SW_SHOWNORMAL);
return TRUE;
I’m also changing the cursor to a hand by intercepting the WM_SETCURSOR message:
case WM_SETCURSOR:
POINT pt;
RECT rect;
GetCursorPos( &pt );
GetWindowRect( GetDlgItem(hwnd,IDC_SETTINGS), &rect );
if (PtInRect(&rect, pt))
{
SetCursor(LoadCursor(NULL, IDC_HAND));
}
else
{
SetCursor(LoadCursor(NULL, IDC_ARROW));
}
return TRUE;
However, when SS_NOTIFY is set the cursor change doesn’t work. When SS_NOTIFY is disabeled it does. But then the click isn’t registered against the static so ShellExecute() doesn’t get to open the URL.
Does anyone have a suggestion as to what I’m doing wrong?
thanks,
ofer.
The return value from a dialog box proc is different from the return value from a window proc. (Documentation for dialog box proc: http://msdn.microsoft.com/en-us/library/windows/desktop/ms645469(v=vs.85).aspx – worth reading carefully.) The return value from a dialog box is just
TRUEorFALSE, indicating whether the message was handled, but the return value from a window proc is the return value of the processing of the window message.If the window message has a meaningful return value (most don’t, but
WM_SETCURSORis one that does), in a dialog proc you need to useSetWindowLong(hwnd,DWL_MSGRESULT,value)to set the result just before returningTRUEfrom the dialog proc.I think the default
DWL_MSGRESULTis zero, so in this code, you will be returningFALSEfrom theWM_SETCURSORmessage. That indicates that the static should do its own thing – i.e., set the arrow cursor.