This code is hard to read, requires some macros, and shouldn't be used by anyone:
	OPTION PROLOGUE:NONE

OPTION EPILOGUE:NONE

; loosely based on: [url]http://www.codeguru.com/staticctrl/st2ahl.html[/url]

PROP_ORIGINAL_FONT EQU <_T("_Hyperlink_Original_Font_")>
PROP_ORIGINAL_PROC EQU <_T("_Hyperlink_Original_Proc_")>
PROP_UNDERLINE_FONT EQU <_T("_Hyperlink_Underline_Font_")>


_HyperlinkParentProc PROC hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
thisPROC_hWnd TEXTEQU <[esp+4*1]>
thisPROC_uMsg TEXTEQU <[esp+4*2]>
thisPROC_wParam TEXTEQU <[esp+4*3]>
thisPROC_lParam TEXTEQU <[esp+4*4]>

invoke GetProp, thisPROC_hWnd[4], PROP_ORIGINAL_PROC
mov ecx, thisPROC_uMsg
pop edx
push eax
cmp ecx, WM_CTLCOLORSTATIC
push edx ; return address
je __WM_CTLCOLORSTATIC
cmp ecx, WM_DESTROY
je __WM_DESTROY
jmp CallWindowProc

; another dword on the stack
thisPROC_old TEXTEQU <[4][esp+4*0]>
thisPROC_hWnd TEXTEQU <[4][esp+4*1]>
thisPROC_uMsg TEXTEQU <[4][esp+4*2]>
thisPROC_wParam TEXTEQU <[4][esp+4*3]>
thisPROC_lParam TEXTEQU <[4][esp+4*4]>

__WM_DESTROY:
invoke SetWindowLong, thisPROC_hWnd[8], GWL_WNDPROC, eax
invoke RemoveProp, thisPROC_hWnd[4], PROP_ORIGINAL_PROC
_x: jmp CallWindowProc


__WM_CTLCOLORSTATIC:
; why would another control have this property?
invoke GetProp, thisPROC_lParam[4], PROP_ORIGINAL_PROC
test eax, eax
je _x
invoke CallWindowProc, thisPROC_old[16], thisPROC_hWnd[12], thisPROC_uMsg[8], thisPROC_wParam[4], thisPROC_lParam
mov [esp+4], eax
invoke SetTextColor, thisPROC_wParam[4], CONST_RGB(0,0,192)
mov eax, [esp+4]
retn 20

_HyperlinkParentProc ENDP



_HyperlinkProc PROC hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
thisPROC_hWnd TEXTEQU <[esp+4*1]>
thisPROC_uMsg TEXTEQU <[esp+4*2]>
thisPROC_wParam TEXTEQU <[esp+4*3]>
thisPROC_lParam TEXTEQU <[esp+4*4]>

invoke GetProp, thisPROC_hWnd[4], PROP_ORIGINAL_PROC
mov ecx, thisPROC_uMsg
pop edx
push eax
cmp ecx, WM_MOUSEMOVE
push edx ; return address
je __WM_MOUSEMOVE
cmp ecx, WM_SETCURSOR
je __WM_SETCURSOR
cmp ecx, WM_DESTROY
je __WM_DESTROY
jmp CallWindowProc

; another dword on the stack
thisPROC_old TEXTEQU <[4][esp+4*0]>
thisPROC_hWnd TEXTEQU <[4][esp+4*1]>
thisPROC_uMsg TEXTEQU <[4][esp+4*2]>
thisPROC_wParam TEXTEQU <[4][esp+4*3]>
thisPROC_lParam TEXTEQU <[4][esp+4*4]>

__WM_DESTROY:
invoke SetWindowLong, thisPROC_hWnd[8], GWL_WNDPROC, eax
invoke RemoveProp, thisPROC_hWnd[4], PROP_ORIGINAL_PROC

invoke GetProp, thisPROC_hWnd[4], PROP_ORIGINAL_FONT
invoke SendMessage, thisPROC_hWnd[12], WM_SETFONT, eax, 0
invoke RemoveProp, thisPROC_hWnd[4], PROP_ORIGINAL_FONT

invoke GetProp, thisPROC_hWnd[4], PROP_UNDERLINE_FONT
invoke DeleteObject, eax
invoke RemoveProp, thisPROC_hWnd[4], PROP_UNDERLINE_FONT
jmp CallWindowProc


__WM_MOUSEMOVE:
invoke GetCapture
cmp eax, thisPROC_hWnd
jne _start_capture

sub esp, SIZEOF RECT
invoke GetWindowRect, thisPROC_hWnd[4 + SIZEOF RECT], esp
movsx eax, WORD PTR thisPROC_lParam[2 + SIZEOF RECT]
movsx edx, WORD PTR thisPROC_lParam[0 + SIZEOF RECT]
push eax ; y
push edx ; x
invoke ClientToScreen, thisPROC_hWnd[4 + SIZEOF RECT + SIZEOF POINT], esp
; (x, y) already on stack
push esp
add DWORD PTR [esp], SIZEOF POINT
call PtInRect

test eax, eax
lea esp, [esp + SIZEOF RECT]
jne _x
invoke GetProp, thisPROC_hWnd[4], PROP_ORIGINAL_FONT
invoke SendMessage, thisPROC_hWnd[12], WM_SETFONT, eax, FALSE
invoke InvalidateRect, thisPROC_hWnd[8], NULL, FALSE
invoke ReleaseCapture
_x: jmp CallWindowProc

_start_capture:
invoke GetProp, thisPROC_hWnd[4], PROP_UNDERLINE_FONT
invoke SendMessage, thisPROC_hWnd[12], WM_SETFONT, eax, FALSE
invoke InvalidateRect, thisPROC_hWnd[8], NULL, FALSE
invoke SetCapture, thisPROC_hWnd
jmp CallWindowProc


__WM_SETCURSOR:
; Since IDC_HAND is not available on all operating systems,
; we will load the arrow cursor if IDC_HAND is not present.
mov edx, IDC_HAND
@@: invoke LoadCursor, NULL, edx
test eax, eax
mov edx, IDC_ARROW
je @B
invoke SetCursor, eax
mov eax, TRUE
ret 5*4

_HyperlinkProc ENDP



OPTION PROLOGUE:PROLOGUEDEF
OPTION EPILOGUE:EPILOGUEDEF


ConvertStaticToHyperlink PROC hwndParent:DWORD, uiCtlId:DWORD

invoke GetDlgItem, hwndParent, uiCtlId
mov uiCtlId, eax ; need handle, not Id

; Subclass the parent so we can color the controls as we desire
cmp hwndParent, NULL
je @F
invoke GetWindowLong, hwndParent, GWL_WNDPROC
cmp eax, OFFSET _HyperlinkParentProc
je @F
invoke SetProp, hwndParent, PROP_ORIGINAL_PROC, eax
invoke SetWindowLong, hwndParent, GWL_WNDPROC, OFFSET _HyperlinkParentProc
@@:
; Make sure the control will send notifications

invoke GetWindowLong, uiCtlId, GWL_STYLE
or eax, SS_NOTIFY
invoke SetWindowLong, uiCtlId, GWL_STYLE, eax

; Subclass the existing control

invoke GetWindowLong, uiCtlId, GWL_WNDPROC
invoke SetProp, uiCtlId, PROP_ORIGINAL_PROC, eax
invoke SetWindowLong, uiCtlId, GWL_WNDPROC, OFFSET _HyperlinkProc

; Create an updated font by adding an underline

invoke SendMessage, uiCtlId, WM_GETFONT, 0, 0
push eax
invoke SetProp, uiCtlId, PROP_ORIGINAL_FONT, eax
pop edx
sub esp, SIZEOF LOGFONT
invoke GetObject, edx, SIZEOF LOGFONT, esp
mov [esp].LOGFONT.lfUnderline, TRUE

invoke CreateFontIndirect, esp
invoke SetProp, uiCtlId, PROP_UNDERLINE_FONT, eax
add esp, SIZEOF LOGFONT

mov eax, TRUE
ret
ConvertStaticToHyperlink ENDP
...but if you change your mind, try this:
__WM_INITDIALOG:

invoke ConvertStaticToHyperlink, DlgPROC_hWnd[4], IDC_STC_web
Yeah, it worked for me once. :)

Posted on 2003-05-28 23:40:25 by bitRAKE
This code is hard to read, requires some macros, and shouldn't be used by anyone:

Seriously I found it quite easy to read and understand.

Anyway why not replace "jmp _x" with "jmp CallWindowProc"?
Posted on 2003-05-29 01:56:55 by roticv
Code is hard and impossible to read. Should not be used by programmer.
Posted on 2003-05-29 06:49:01 by comrade
The other part needed to implement this is:


BN_CLICKED_IDC_STC_web:
invoke SendDlgItemMessage, DlgPROC_hWnd[16],
IDC_STC_web, WM_GETTEXT, LENGTHOF tempBuffer, OFFSET _tempBuffer
invoke ShellExecute, DlgPROC_hWnd[20],
_T("open"), OFFSET tempBuffer, NULL, NULL, SW_SHOWNORMAL
ret
Posted on 2003-06-04 22:31:55 by bitRAKE
I created a sample from biRAKE's code to see if it works ;)


... and it does
Attachments:
Posted on 2006-07-18 03:23:02 by JimmyClif