Code: Select all
#ENM_LINK = $04000000
#CFM_LINK = $00000020
#EN_LINK = 1803
Procedure Callback(Window, Message, wParam, lParam)
; WM_NOTIFY can only be caught in the callback, not in the main loop
;
If Message = #WM_NOTIFY
*hdr.NMHDR = lParam
; ensure it is the right message and gadget
;
If *hdr\hwndFrom = GadgetID(0) And *hdr\code = #EN_LINK
*link.ENLINK = lParam
; react only to the button release part.
;
If *link\msg = #WM_LBUTTONUP
; Show also the range of text that was clicked
;
MessageRequester("", "click! (" + Str(*link\chrg\cpMin) + ", " + Str(*link\chrg\cpMax) + ")")
EndIf
EndIf
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
If OpenWindow(0, 0, 0, 400, 400, "Links", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
SetWindowCallback(@Callback())
EditorGadget(0, 10, 10, 380, 380)
; Enable the link message
SendMessage_(GadgetID(0), #EM_SETEVENTMASK, 0, #ENM_LINK)
; This enables autodetect of url text
; must be before the SetGadgettext.
SendMessage_(GadgetID(0), #EM_AUTOURLDETECT, #True, 0)
SetGadgetText(0, "There is a link in here." + Chr(13) + "http://www.purebasic.com/")
; To manually set a text as an url, select it and use the charformat message:
format.CHARFORMAT2\cbSize = SizeOf(CHARFORMAT2)
format\dwMask = #CFM_LINK
format\dwEffects = #CFM_LINK
SendMessage_(GadgetID(0), #EM_SETSEL, 11, 15)
SendMessage_(GadgetID(0), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)
; deselect the text
SendMessage_(GadgetID(0), #EM_SETSEL, 0, 0)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf