Date: 02-16-2022
Return to Index
created by gbSnippets
'This shows how to put a URL in a label, have it change color as a
'cursor moves over it, and then opens the URL when clicked.
'Primary Code:
'1. Use %SS_Notify in the label so you can get the mouse click
Control Add Label, hDlg, %ID_Label, "http://www.garybeene.com", 10, 40, 200, 20, %SS_Notify
'2. Respond to %STN_CLICKED with ShellExecute to tun the default client for URs
Case %WM_Command
If CB.Ctl = %ID_Label AND CB.Ctlmsg = %STN_Clicked Then
URL$ = "http://www.garybeene.com/"
iReturn = ShellExecute(hDlg, "Open", URL, $Nul, $Nul, %SW_ShowNormal)
End If
'3. %WM_SetCursor to detect mouse movement and set hover colors of URL text in label
Case %WM_SetCursor
Select Case GetDlgCtrlID (CB.wParam)
Case %ID_Label
Control Set Color hDlg, %ID_Label, %Red, -1 'when over the label, use RED
Dialog Redraw hDlg
Case Else
Control Set Color hDlg, %ID_Label, %Black, -1 'everywhere else, use Black
Dialog Redraw hDlg
End Select
'Compilable Example: (Jose Includes)
'This example demonstrates an active URL in a label
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
%ID_Label = 300
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,100, %WS_OverlappedWindow To hDlg
Control Add Label, hDlg, %ID_Label, "http://www.garybeene.com", 10, 40, 200, 20, _
%SS_Center Or %SS_Notify
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local URL As Asciiz * %Max_Path, iReturn As Long
Select Case CB.Msg
Case %WM_Command
If CB.Ctl = %ID_Label AND CB.Ctlmsg = %STN_Clicked Then
URL$ = "http://www.garybeene.com/"
iReturn = ShellExecute(hDlg, "Open", URL, $Nul, $Nul, %SW_ShowNormal)
End If
Case %WM_SetCursor
Select Case GetDlgCtrlID (CB.wParam)
Case %ID_Label
Control Set Color hDlg, %ID_Label, %Red, -1 'when over the label, use RED
Dialog Redraw hDlg
Case Else
Control Set Color hDlg, %ID_Label, %Black, -1 'everywhere else, use Black
Dialog Redraw hDlg
End Select
End Select
End Function
'gbs_00110
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm