.386
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\shell32.inc
include \masm32\include\gdi32.inc
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
         
    WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
    HyperLink PROTO :DWORD, :DWORD
    HyperLinkWndProc PROTO :DWORD, :DWORD, :DWORD, :DWORD

.const
    IDC_URL     equ 100
    IDC_MAIL    equ 101
    
.data
    dlgname db "URL",0
    szOpen  db "open",0 ;tells shellexacute to open the link

.data? 
    buffer      db 255 dup (?) ;Buffer to hold our string
    hInstance   dd ?           ;Instance of the program
    hFinger     dd ?           ;Holder for the cursor

.code

start:

    invoke GetModuleHandle, NULL
        mov hInstance, eax        
    invoke DialogBoxParam,hInstance,ADDR dlgname,0,ADDR WndProc,0
        invoke ExitProcess,eax

WndProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
    .if uMsg == WM_INITDIALOG
        invoke HyperLink, hWin, IDC_URL     ;Turn the url into a hyperlink
        invoke HyperLink, hWin, IDC_MAIL    ;Turn the e-mail into a hyperlink
            invoke LoadCursor,hInstance,101 ;Load our custom cursor into memory
                mov hFinger,eax             ;Save Its handle
                    xor eax,eax             ;Return falsw
                        ret
    .elseif uMsg == WM_CTLCOLORSTATIC
        invoke SendMessage,lParam,uMsg,wParam,lParam    ;We want to hook this message to our hyperlink function
            ret
    .elseif uMsg == WM_CLOSE
        invoke EndDialog,hWin,0
            xor eax,eax
                ret
    .endif
        xor eax,eax
            ret
WndProc endp

HyperLink proc hDlg:DWORD, nID:DWORD
    invoke GetDlgItem, hDlg, nID        ;Get the handle of our item
        push eax                        ;save it
    invoke SetWindowLong, eax, GWL_WNDPROC, addr HyperLinkWndProc   ;subclass our static window
        pop edx                             ;Restore saved eax into eax
    invoke SetWindowLong, edx, GWL_USERDATA, eax    ;Set new value
        ret
HyperLink endp

HyperLinkWndProc PROC uses ebx, hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
LOCAL tmpFont  :LOGFONT 
    .IF uMsg==WM_CTLCOLORSTATIC                     ;Color our static windows
        invoke SendMessage, hWnd, WM_GETFONT, 0, 0  ;Get the defualt system font
            mov edx,eax                             ;store result
                invoke GetObject, edx, sizeof LOGFONT, addr tmpFont ;get our font into a logfont structure
                    mov tmpFont.lfUnderline, TRUE ;under line the link
                        invoke CreateFontIndirect, addr tmpFont ;Create the new font
                            mov ebx,eax                         ;We need the return to free the memory later
                            invoke SelectObject, wParam, ebx    ;Select our control
                        invoke SetTextColor, wParam, Blue ;change this to change the color of the link
                        invoke GetSysColor, COLOR_MENU    ;background is = to the system menu
                        invoke SetBkColor, wParam, eax    ;Set the color
                        invoke DeleteObject,ebx           ;Free memory used for font creatin
                        invoke GetStockObject, HOLLOW_BRUSH ;Return painting with a hollow brush
                            ret 
    .ELSEIF uMsg==WM_NCHITTEST
        mov eax, 1 ;We want to handle the non client hit test so we return true or 1
            ret
    .ELSEIF uMsg==WM_LBUTTONDOWN
        invoke GetWindowText,hWnd,offset buffer,sizeof buffer ;change this for using a preset url
            invoke ShellExecute, NULL, offset szOpen, offset buffer, NULL, NULL, SW_SHOWNORMAL ;change this to represent your preset url
                xor eax,eax
                    ret
    .ELSEIF uMsg==WM_SETCURSOR
        invoke SetCursor,hFinger
            xor eax,eax
                ret
    .ENDIF
        invoke GetWindowLong, hWnd, GWL_USERDATA 
            invoke CallWindowProc, eax, hWnd, uMsg, wParam, lParam 
                ret
HyperLinkWndProc endp
end start


