.386
.Model Flat,Stdcall

Extrn   ExitProcess:Proc
Extrn   GetModuleHandleA:Proc
Extrn   GetMessageA:Proc
Extrn   DispatchMessageA:Proc
Extrn   IsDialogMessage:Proc
Extrn   TranslateMessage:Proc
Extrn   DefWindowProcA:Proc
Extrn   LoadCursorA:Proc
Extrn   RegisterClassExA:Proc
Extrn   CreateDialogParamA:Proc
Extrn   ShowWindow:Proc
Extrn   UpdateWindow:Proc
Extrn   PostQuitMessage:Proc
Extrn   SendMessageA:Proc
Extrn   MessageBoxA:Proc
Extrn   ShellExecuteA:Proc
Extrn   SendDlgItemMessageA:Proc
Extrn   InitControls:Proc
Extrn   CreatePopupMenu:Proc
Extrn   AppendMenuA:Proc
Extrn   TrackPopupMenu:Proc
Extrn   DestroyMenu:Proc
Extrn   GetCursorPos:Proc
Extrn   GlobalAlloc:Proc
Extrn   GlobalLock:Proc
Extrn   GlobalUnlock:Proc
Extrn   lstrcpy:Proc
Extrn   OpenClipboard:Proc
Extrn   EmptyClipboard:Proc
Extrn   SetClipboardData:Proc
Extrn   CloseClipboard:Proc
Extrn   lstrlen:Proc
Extrn   CreateFont:Proc
Extrn   CreateFontIndirectA:Proc
Extrn   GetDlgItem:Proc
Extrn   GetWindowDC:Proc
Extrn   EnumFontsA:Proc
Extrn   LoadBitmapA:Proc
Extrn   LoadStringA:Proc
Extrn   LoadIconA:Proc

include win32api.inc
include addctrls.inc

.Data
hInstance               HINSTANCE      ?
DlgName                 db             "MyDlg",0
ClassName               db             "RgnClass",0
msg                     MSG            ?
hDlg                    HWND           0
wc                      WNDCLASSEX     ?
hCursor                 DWORD          0
Tekst                   db             100 dup (0)
Lewy                    db             "Left button pressed",0
Prawy                   db             "Right button pressed",0
ShellOpen               db             "open",0
hMenu                   DWORD           0
MenuItem1               db              "Open",0
MenuItem2               db              "Copy this text",0
CurPos                  POINT           <>
Andor                   db              "mailto:and_or@poczta.onet.pl",0
TimesNew                db              "Times New Roman",0

.Code

EnumFontsProc   Proc    lplf:DWORD,lptm:DWORD,dwType:DWORD,lpData:DWORD
                push    ebx edi esi
                mov     eax,lplf
                mov     dword ptr [eax],12
                mov     dword ptr [eax+4],8
                mov     byte ptr [eax+22],FALSE
                call    CreateFontIndirectA,lplf
                push    eax
                call    SendDlgItemMessageA,hDlg,0,HL_SETINACTIVEFONT,eax,TRUE
                pop     eax
                push    eax
                call    SendDlgItemMessageA,hDlg,1,HL_SETINACTIVEFONT,eax,TRUE
                pop     eax
		push	eax
                call    SendDlgItemMessageA,hDlg,2,HL_SETINACTIVEFONT,eax,TRUE
		pop	eax
		call    SendDlgItemMessageA,hDlg,5,CI_SETFONT,eax,TRUE
                mov     eax,lplf
                mov     byte ptr [eax+20],TRUE
                mov     byte ptr [eax+21],TRUE
                mov     byte ptr [eax+22],FALSE
                call    CreateFontIndirectA,lplf
                push    eax
                call    SendDlgItemMessageA,hDlg,0,HL_SETACTIVEFONT,eax,TRUE
                pop     eax
                push    eax
                call    SendDlgItemMessageA,hDlg,1,HL_SETACTIVEFONT,eax,TRUE
                pop     eax
                call    SendDlgItemMessageA,hDlg,2,HL_SETACTIVEFONT,eax,TRUE
                xor     eax,eax
                pop     esi edi ebx
                ret
EnumFontsProc   EndP

WndProc         Proc    hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
                push    ebx edi esi
                mov     eax,uMsg
                cmp     eax,WM_DESTROY
                jz      OnDestroy
                cmp     eax,WM_NOTIFY
                jz      OnNotify
                jmp     GoOn
OnNotify:       mov     eax,lParam
                cmp     dword ptr [eax+4],0
                jz      Item_0
                cmp     dword ptr [eax+4],1
                jz      Item_0
                cmp     dword ptr [eax+4],2
                jz      Item_2
                cmp     dword ptr [eax+4],3
                jz      Item_3
                jmp     EndIt
Item_0:         cmp     dword ptr [eax+8],HLN_LMOUSECLICK
                jz      OnMenu
                cmp     dword ptr [eax+8],HLN_MENUITEM
                jnz     EndIt
                cmp     dword ptr [eax+12],1
                jz      CopyLink
                cmp     dword ptr [eax+12],0
                jz      OnMenu
                jmp     EndIt
Item_2:         cmp     dword ptr [eax+8],HLN_LMOUSECLICK
                jz      SendMail
                cmp     dword ptr [eax+8],HLN_RMOUSECLICK
                jz      SendMail
                jmp     EndIt
Item_3:         cmp     dword ptr [eax+8],HLN_MENUITEM
                jnz     EndIt
                mov     ebx,dword ptr [eax+12]
                add     ebx,2000
                call    LoadStringA,hInstance,ebx,offset Tekst,100
                call    ShellExecuteA,hWnd,offset ShellOpen,offset Tekst,0,0,SW_SHOWNORMAL
                jmp     EndIt
SendMail:       call            ShellExecuteA,hWnd,offset ShellOpen,offset Andor,0,0,SW_SHOWNORMAL
                jmp     EndIt
OnLeftBtn:      mov     eax,wParam
                cmp     ax,2
                jz      SendMail
                call    SendMessageA,lParam,WM_GETTEXT,100,offset Tekst
                call    ShellExecuteA,hWnd,offset ShellOpen,offset Tekst,0,0,SW_SHOWNORMAL
                jmp     EndIt
OnMenu:         call    SendMessageA,dword ptr [eax],WM_GETTEXT,100,offset Tekst
                call    ShellExecuteA,hWnd,offset ShellOpen,offset Tekst,0,0,SW_SHOWNORMAL
                jmp     EndIt
CopyLink:       call    SendMessageA,dword ptr [eax],WM_GETTEXT,100,offset Tekst
                inc     eax
                call    GlobalAlloc,GMEM_MOVEABLE OR GMEM_ZEROINIT or GMEM_SHARE,eax
                push    eax
                call    GlobalLock,eax
                call    lstrcpy,eax,offset Tekst
                pop     eax
                push    eax
                call    GlobalUnlock,eax
                call    OpenClipboard,hWnd
                call    EmptyClipboard
                pop     eax
                call    SetClipboardData,CF_TEXT,eax
                call    CloseClipboard
                jmp     EndIt
OnDestroy:      call    PostQuitMessage,NULL
                jmp     EndIt
GoOn:           call    DefWindowProcA,hWnd,uMsg,wParam,lParam
                pop     esi edi ebx
                ret
EndIt:          xor     eax,eax
                pop     esi edi ebx
                ret
WndProc         endp

Start:          call    InitControls
                call    GetModuleHandleA,NULL
                mov     hInstance,eax
                call    LoadCursorA,hInstance,1001
                mov     hCursor,eax
                mov     wc.wce_cbSize,SIZE WNDCLASSEX
                mov     wc.wce_style,CS_HREDRAW or CS_VREDRAW
                mov     wc.wce_lpfnWndProc,offset WndProc
                mov     wc.wce_cbClsExtra,NULL
                mov     wc.wce_cbWndExtra,DLGWINDOWEXTRA
                push    hInstance
                pop     wc.wce_hInstance
                mov     wc.wce_hbrBackground,COLOR_WINDOW
                mov     wc.wce_lpszMenuName,NULL
                mov     wc.wce_lpszClassName,offset ClassName
                mov     wc.wce_hIcon,0
                mov     wc.wce_hIconSm,0
                call    LoadCursorA,NULL,IDC_ARROW
                mov     wc.wce_hCursor,eax
                call    RegisterClassExA,offset wc
                call    CreateDialogParamA,hInstance,offset DlgName,NULL,NULL,NULL
                mov     hDlg,eax
                call    SendDlgItemMessageA,hDlg,0,HL_SETACTIVECOLOR,0FFh,TRUE
                call    SendDlgItemMessageA,hDlg,0,HL_SETINACTIVECOLOR,0FFFFFFh,TRUE
                call    SendDlgItemMessageA,hDlg,1,HL_SETCURSOR,hCursor,0
                call    GetDlgItem,hDlg,0
                call    GetWindowDC,eax
                call    EnumFontsA,eax,offset TimesNew,offset EnumFontsProc,0
                call    LoadBitmapA,hInstance,1003
                call    SendDlgItemMessageA,hDlg,3,HL_SETACTIVEBITMAP,eax,TRUE
                call    LoadBitmapA,hInstance,1002
                call    SendDlgItemMessageA,hDlg,3,HL_SETINACTIVEBITMAP,eax,TRUE
                call    LoadIconA,hInstance,1013
                call    SendDlgItemMessageA,hDlg,4,HL_SETACTIVEICON,eax,TRUE
                call    LoadIconA,hInstance,1012
                call    SendDlgItemMessageA,hDlg,4,HL_SETINACTIVEICON,eax,TRUE
		call    LoadIconA,hInstance,1012
                call    SendDlgItemMessageA,hDlg,5,CI_SETUNCHKDICON,eax,TRUE
                call    LoadIconA,hInstance,1013
                call    SendDlgItemMessageA,hDlg,5,CI_SETCHKDICON,eax,FALSE
                call    CreatePopupMenu
                mov     hMenu,eax
                call    AppendMenuA,hMenu,MF_STRING,0,offset MenuItem1
                call    AppendMenuA,hMenu,MF_SEPARATOR,0,0
                call    AppendMenuA,hMenu,MF_STRING,1,offset MenuItem2
                call    SendDlgItemMessageA,hDlg,0,HL_SETMENU,hMenu,0
                call    SendDlgItemMessageA,hDlg,1,HL_SETMENU,hMenu,0
                call    CreatePopupMenu
                mov     hMenu,eax
                call    LoadStringA,hInstance,2000,offset Tekst,100
                call    AppendMenuA,hMenu,MF_STRING,0,offset Tekst
                call    LoadStringA,hInstance,2001,offset Tekst,100
                call    AppendMenuA,hMenu,MF_STRING,1,offset Tekst
                call    LoadStringA,hInstance,2002,offset Tekst,100
                call    AppendMenuA,hMenu,MF_STRING,2,offset Tekst
                call    LoadStringA,hInstance,2003,offset Tekst,100
                call    AppendMenuA,hMenu,MF_STRING,3,offset Tekst
                call    LoadStringA,hInstance,2004,offset Tekst,100
                call    AppendMenuA,hMenu,MF_STRING,4,offset Tekst
                call    LoadStringA,hInstance,2005,offset Tekst,100
                call    AppendMenuA,hMenu,MF_STRING,5,offset Tekst
                call    LoadStringA,hInstance,2006,offset Tekst,100
                call    AppendMenuA,hMenu,MF_STRING,6,offset Tekst
                call    SendDlgItemMessageA,hDlg,3,HL_SETMENU,hMenu,0
		call    SendDlgItemMessageA,hDlg,5,CI_SETCURSOR,hCursor,TRUE
                call    ShowWindow,hDlg,SW_SHOWNORMAL
                call    UpdateWindow,hDlg
BackHere:       call    GetMessageA,offset msg,NULL,NULL,NULL
                cmp     eax,TRUE
                jnz     StopPrg
                call    IsDialogMessage,hDlg,offset msg
                cmp     eax,TRUE
                jz      BackHere
                call    TranslateMessage,offset msg
                call    DispatchMessageA,offset msg
                jmp     BackHere
StopPrg:
                mov     eax,msg.m_wParam
                call    ExitProcess,eax
End Start