MASM32 Downloads
OPTION DOTNAMEoption casemap:noneinclude temphls.incinclude win64.incinclude kernel32.incinclude user32.incincludelib kernel32.libincludelib user32.libOPTION PROLOGUE:rbpFramePrologue.codeWinMain proc sub rsp,5*8 invoke MessageBox,NULL,&MsgBoxText,&MsgCaption,MB_OK invoke ExitProcess,NULLWinMain endpMsgCaption db "Iczelion's tutorial #2",0MsgBoxText db "Win64 Assembly is Great!",0end
clsset masm64_path=\masm64\set filename=%1if exist %1.rc (%masm64_path%bin\RC /r %filename%.rc || exit%masm64_path%bin\cvtres /machine:X64 %filename%.res || exit%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit%masm64_path%bin\link /SUBSYSTEM:WINDOWS /LIBPATH:"%masm64_path%Lib" ^/entry:WinMain %filename%.obj %filename%.res /LARGEADDRESSAWARE:NO ^/ALIGN:16 /SECTION:.text,W ^/BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe || exitdel %filename%.objdel %filename%.res) else (%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit%masm64_path%bin\link /SUBSYSTEM:WINDOWS /LIBPATH:"%masm64_path%Lib" ^/entry:WinMain %filename%.obj /LARGEADDRESSAWARE:NO ^/ALIGN:16 /SECTION:.text,W ^/BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe || exitdel %filename%.obj)
OPTION DOTNAMEoption casemap:noneinclude temphls.incinclude win64.incinclude user32.incincludelib user32.libOPTION PROLOGUE:rbpFramePrologue.codeWinMain proc enter 4*8,0 xor ecx,ecx mov r9,rcx lea r8,MsgCaption lea edx,MsgBoxText call MessageBox leave retWinMain endpMsgCaption db "Iczelion's tutorial #2a",0MsgBoxText db "Win64 Assembly is Great!",0end
OPTION DOTNAMEoption casemap:noneinclude temphls.incinclude win64.incinclude kernel32.incinclude user32.incincludelib kernel32.libincludelib user32.libOPTION PROLOGUE:rbpFramePrologue.codeWinMain proc push rbp mov rbp,rsp sub rsp,30h invoke GetModuleHandle,NULL mov x1,rax invoke LoadIcon,NULL,IDI_APPLICATION mov x2,rax invoke LoadCursor,NULL,IDC_ARROW mov x3,rax mov rax,x1 mov [rsp+20h],eax lea ecx,buffer lea edx,fmt mov r8,x3 mov r9,x2 call wsprintf invoke MessageBox,NULL,&buffer,&MsgCaption,MB_OK invoke ExitProcess,NULLWinMain endpMsgCaption db "Iczelion's tutorial #2b",0fmt db "hCursor = %08Xh",0Ah,"hIcon = %08Xh",0Ah,"hInstance =%08Xh",0n = $ - fmt + 12buffer db n dup(?)x1 dq ?x2 dq ?x3 dq ?end
include win64a.inc.codeWinMain proc local msg:MSG push rbp mov ebp,esp sub esp,sizeof MSG xor ebx,ebx mov eax,10029h push rax ;hIconSm mov edi,offset ClassName push rdi ;lpszClassName push rbx ;lpszMenuName push COLOR_WINDOWTEXT;hbrBackground push 10005h ;hCursor push rax ;hIcon mov esi,400000h push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra mov eax,offset WndProc push rax ;lpfnWndProc push sizeof WNDCLASSEX;cbSize & style mov rcx,rsp ;addr WNDCLASSEX call RegisterClassEx push rbx push rsi ;rsi=400000h shl esi,9 ;rsi=CW_USEDEFAULT push rbx push rbx push rsi push rsi push rsi push rsi mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx sub esp,20h call CreateWindowEx@@: lea ecx,msg xor edx,edx xor r8d,r8d xor r9d,r9d call GetMessage lea ecx,msg call DispatchMessage jmp @bWinMain endpWndProc:cmp edx,WM_DESTROY je wmDESTROY jmp DefWindowProcwmDESTROY: xor ecx,ecx call ExitProcess;---------------------------------------ClassName db 'Win64 Iczelion lesson #3',0end
OPTION DOTNAMEoption casemap:noneinclude temphls.incinclude win64.incinclude kernel32.incincludelib kernel32.libinclude user32.incincludelib user32.libOPTION PROLOGUE:rbpFramePrologueOPTION EPILOGUE:rbpFrameEpilogue.codeWinMain proc msg equ [rbp-sizeof MSG] enter sizeof MSG+sizeof WNDCLASSEX+20h,0 xor ebx,ebx push 10029h ;hIconSm lea rdi,ClassName push rdi ;lpszClassName push rbx ;lpszMenuName push COLOR_WINDOW;hbrBackground push 10005h ;hCursor push 10029h ;hIcon mov esi,400000h push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra lea rax,WndProc push rax ;lpfnWndProc push sizeof WNDCLASSEX;cbSize & style mov rcx,rsp ;addr WNDCLASSEX push rbx push rbx push rbx push rbx call RegisterClassEx add rsp,sizeof WNDCLASSEX+20h push rbx push rsi ;rsi=400000h shl esi,9 ;rsi=CW_USEDEFAULT push rbx push rbx push rsi push rsi push rsi push rsi mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx push rbx push rbx push rbx push rbx call CreateWindowEx lea edi,msg@@: mov ecx,edi xor edx,edx mov r8,rbx mov r9,rbx call GetMessage mov ecx,edi call DispatchMessage jmp @bWinMain endpWndProc:hwnd equ [rbp+10h]ps equ [rbp-sizeof PAINTSTRUCT]expRect equ ps-sizeof RECT enter sizeof PAINTSTRUCT+sizeof RECT+28h,0 mov hwnd,rcx cmp edx,WM_DESTROY je wmDESTROY cmp edx,WM_PAINT je wmPAINT cmp edx,WM_SIZE je wmPAINT leave jmp DefWindowProcwmDESTROY: xor ecx,ecx call ExitProcesswmSIZE: mov r8d,1 xor edx,edx call InvalidateRect;send WM_PAINT if size changes jmp wmBYEwmPAINT: lea edx,ps call BeginPaint mov rcx,hwnd lea rdx,expRect call GetClientRect mov qword ptr [rbp-60h],DT_SINGLELINE or DT_CENTER or DT_VCENTER lea r9,expRect or r8,-1 lea edx,expTxt mov rcx,ps.PAINTSTRUCT.hdc call DrawText lea edx,ps mov rcx,hwnd call EndPaintwmBYE: leave retn;---------------------------------------ClassName db 'Win64 Iczelion''s lesson #4: Painting with Text',0expTxt db 'Win64 assembly with MASM is great and easy',0end
OPTION DOTNAMEoption casemap:noneinclude temphls.incinclude win64.incinclude kernel32.incincludelib kernel32.libinclude user32.incincludelib user32.libinclude gdi32.incincludelib gdi32.libOPTION PROLOGUE:rbpFramePrologueOPTION EPILOGUE:rbpFrameEpilogue.codeWinMain proc msg equ [rbp-sizeof MSG] enter sizeof MSG+sizeof WNDCLASSEX+20h,0 xor ebx,ebx push 10029h ;hIconSm lea rdi,ClassName push rdi ;lpszClassName push rbx ;lpszMenuName push COLOR_WINDOW;hbrBackground push 10005h ;hCursor push 10029h ;hIcon mov esi,400000h push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra lea rax,WndProc push rax ;lpfnWndProc push sizeof WNDCLASSEX;cbSize & style mov rcx,rsp ;addr WNDCLASSEX push rbx push rbx push rbx push rbx call RegisterClassEx add rsp,sizeof WNDCLASSEX+20h push rbx push rsi ;rsi=400000h shl esi,9 ;rsi=CW_USEDEFAULT push rbx push rbx push rsi push rsi push rsi push rsi mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx push rbx push rbx push rbx push rbx call CreateWindowEx lea edi,msg@@: mov ecx,edi xor edx,edx mov r8,rbx mov r9,rbx call GetMessage mov ecx,edi call DispatchMessage jmp @bWinMain endpWndProc:hwnd equ [rbp+10h]ps equ [rbp-sizeof PAINTSTRUCT] enter sizeof PAINTSTRUCT+98h,0 mov hwnd,rcx cmp edx,WM_DESTROY je wmDESTROY cmp edx,WM_PAINT je wmPAINT leave jmp DefWindowProcwmDESTROY: xor ecx,ecx call ExitProcesswmPAINT: lea edx,ps call BeginPaint mov edx,OBJ_FONT mov rcx,ps.PAINTSTRUCT.hdc call GetCurrentObject push rax ;default font object lea rax,expFont push rax push DEFAULT_PITCH or FF_SCRIPT push rbx;DEFAULT_QUALITY push rbx;CLIP_DEFAULT_PRECIS push rbx;OUT_DEFAULT_PRECIS push OEM_CHARSET push rbx push rbx push rbx push 400 mov r9,rbx mov r8,rbx mov edx,12 mov ecx,26 push rbx push rbx push rbx push rbx call CreateFont mov rdx,rax mov rcx,ps.PAINTSTRUCT.hdc call SelectObject mov edx,32C8C8h mov rcx,ps.PAINTSTRUCT.hdc call SetTextColor mov edx,0FF0000h mov rcx,ps.PAINTSTRUCT.hdc call SetBkColor lea ecx,expTxt call lstrlen ;help us to count the string length push rax lea r9,expTxt xor edx,edx mov r8,rdx mov rcx,ps.PAINTSTRUCT.hdc push rbx push rbx push rbx push rbx call TextOut add rsp,30h pop rdx mov rcx,ps.PAINTSTRUCT.hdc call SelectObject lea edx,ps mov rcx,hwnd call EndPaintwmBYE: leave retn;---------------------------------------ClassName db 'Win64 Iczelion''s lesson #5:More about Text',0expTxt db 'Win64 assembly with MASM is great and easy',0expFont db 'script',0end
OPTION DOTNAMEoption casemap:noneinclude temphls.incinclude win64.incinclude kernel32.incincludelib kernel32.libinclude user32.incincludelib user32.libinclude gdi32.incincludelib gdi32.libOPTION PROLOGUE:rbpFramePrologueOPTION EPILOGUE:rbpFrameEpilogue.codeWinMain proc msg equ [rbp-sizeof MSG] enter sizeof MSG+sizeof WNDCLASSEX+20h,0;90h,0 xor ebx,ebx push 10029h ;hIconSm lea rdi,ClassName push rdi ;lpszClassName push rbx ;lpszMenuName push COLOR_WINDOW;hbrBackground push 10005h ;hCursor push 10029h ;hIcon mov esi,400000h push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra lea rax,WndProc push rax ;lpfnWndProc push sizeof WNDCLASSEX;cbSize & style mov rcx,rsp ;addr WNDCLASSEX push rbx push rbx push rbx push rbx call RegisterClassEx add rsp,sizeof WNDCLASSEX+20h push rbx push rsi ;rsi=400000h shl esi,9 ;rsi=CW_USEDEFAULT push rbx push rbx push 352 push 512 push rsi push rsi mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx push rbx push rbx push rbx push rbx call CreateWindowEx lea edi,msg@@: mov ecx,edi xor edx,edx mov r8,rbx mov r9,rbx call GetMessage mov ecx,edi call TranslateMessage mov ecx,edi call DispatchMessage jmp @bWinMain endpWndProc:hwnd equ [rbp+10h]ps equ [rbp-sizeof PAINTSTRUCT] enter sizeof PAINTSTRUCT+20h,0 mov hwnd,rcx cmp edx,WM_DESTROY je wmDESTROY cmp edx,WM_CHAR je wmCHAR cmp edx,WM_PAINT je wmPAINT leave jmp DefWindowProcwmDESTROY: xor ecx,ecx call ExitProcess wmCHAR: mov expChar,r8 mov r8d,TRUE xor edx,edx call InvalidateRect jmp wmBYEwmPAINT: lea edx,ps call BeginPaint sub rsp,10h mov qword ptr [rsp+20h],lengthof Message lea r9,Message mov r8d,90 mov edx,192 mov rcx,ps.PAINTSTRUCT.hdc call TextOut mov qword ptr [rsp+20h],1 lea r9,expChar mov r8d,150 mov edx,242 mov rcx,ps.PAINTSTRUCT.hdc call TextOut add rsp,10h lea edx,ps mov rcx,hwnd call EndPaintwmBYE: leave retn;---------------------------------------ClassName db 'Win64 Iczelion''s lesson #6: Keyboard Input',0Message db 'Press any key'expChar dq '?'end
OPTION DOTNAMEoption casemap:noneinclude temphls.incinclude win64.incinclude kernel32.incincludelib kernel32.libinclude user32.incincludelib user32.libinclude gdi32.incincludelib gdi32.libOPTION PROLOGUE:rbpFramePrologueOPTION EPILOGUE:rbpFrameEpilogue.codeWinMain proc msg equ [rbp-sizeof MSG] enter sizeof MSG+sizeof WNDCLASSEX+20h,0 xor ebx,ebx push 10029h ;hIconSm lea rdi,ClassName push rdi ;lpszClassName push rbx ;lpszMenuName push COLOR_WINDOW;hbrBackground push 10005h ;hCursor push 10029h ;hIcon mov esi,400000h push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra lea rax,WndProc push rax ;lpfnWndProc push sizeof WNDCLASSEX;cbSize & style mov rcx,rsp ;addr WNDCLASSEX push rbx push rbx push rbx push rbx call RegisterClassEx add rsp,sizeof WNDCLASSEX+20h push rbx push rsi ;rsi=400000h shl esi,9 ;rsi=CW_USEDEFAULT push rbx push rbx push rsi push rsi push rsi push rsi mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx push rbx push rbx push rbx push rbx call CreateWindowEx lea edi,msg@@: mov ecx,edi xor edx,edx mov r8,rbx mov r9,rbx call GetMessage mov ecx,edi call DispatchMessage jmp @bWinMain endpWndProc:hwnd equ [rbp+10h]ps equ [rbp-sizeof PAINTSTRUCT] enter sizeof PAINTSTRUCT+30h,0 mov hwnd,rcx cmp edx,WM_DESTROY je wmDESTROY cmp edx,WM_PAINT je wmPAINT cmp edx,WM_LBUTTONDOWN je wmLBUTTONDOWN leave jmp DefWindowProcwmDESTROY: xor ecx,ecx call ExitProcesswmLBUTTONDOWN: ;low order lParam = x ;high order lParam = y mov word ptr expHPoint.x,r9w;eax shr r9,16 mov expHPoint.y,r9d or expClick,TRUE mov r8d,TRUE xor edx,edx call InvalidateRect jmp wmBYEwmPAINT: lea edx,ps call BeginPaint cmp expClick,TRUE jne wmPAINT_END mov qword ptr [rsp+20h],lengthof expTxt lea r9,expTxt mov r8d,expHPoint.y mov edx,expHPoint.x mov rcx,ps.PAINTSTRUCT.hdc call TextOutwmPAINT_END: lea edx,ps mov rcx,hwnd call EndPaintwmBYE: leave retn;---------------------------------------ClassName db 'Win64 Iczelion''s lesson #7:Mouse Input',0expTxt db 'You clicked here!',0expClick db 0expHPoint POINT <0>end
include win64a.incinclude gdi32.incincludelib gdi32.libMAXRECTS = 40;the maximum number of processed mouse clicks.codeWinMain proc msg equ [rbp-sizeof MSG] enter sizeof MSG+sizeof WNDCLASSEX+20h,0 xor ebx,ebx push 10029h ;hIconSm lea rdi,ClassName push rdi ;lpszClassName push rbx ;lpszMenuName push COLOR_WINDOW;hbrBackground push 10005h ;hCursor push 10029h ;hIcon mov esi,400000h push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra lea rax,WndProc push rax ;lpfnWndProc push sizeof WNDCLASSEX;cbSize & style mov rcx,rsp ;addr WNDCLASSEX call RegisterClassEx push rbx push rsi ;rsi=400000h shl esi,9 ;rsi=CW_USEDEFAULT push rbx push rbx push rsi push rsi push rsi push rsi mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx sub esp,20h call CreateWindowEx@@: lea ecx,msg xor edx,edx xor r8d,r8d xor r9d,r9d call GetMessage lea ecx,msg call DispatchMessage jmp @bWinMain endpWndProc:hwnd equ [rbp+10h]lParam equ [rbp+28h]ps equ [rbp-sizeof PAINTSTRUCT] enter sizeof PAINTSTRUCT+30h,0 mov lParam,r9 xor eax,eax mov hwnd,rcx cmp edx,WM_DESTROY je wmDESTROY cmp edx,WM_PAINT je wmPAINT cmp edx,WM_LBUTTONDOWN je wmLBUTTONDOWN cmp edx,WM_RBUTTONDOWN je wmRBUTTONDOWN leave jmp DefWindowProcwmDESTROY: xor ecx,ecx call ExitProcesswmLBUTTONDOWN: ;low order lParam = x ;high order lParam = y mov eax,80000000hwmRBUTTONDOWN: add eax,lParam cmp nextRect,MAXRECTS-1 jge @f inc nextRect mov ecx,nextRect mov [ecx*4+recs],eax xor edx,edx mov rcx,hwnd mov r8d,TRUE call InvalidateRect jmp wmBYE@@: xor ecx,ecx call MessageBeep jmp wmBYEwmPAINT: mov ebx,nextRect inc ebx;cmp nextRect,-1 jz wmBYE lea edx,ps call BeginPaint mov edx,TRANSPARENT mov rcx,rax call SetBkMode@@: mov eax,[ebx*4+recs-4] mov ecx,1 shl eax,1 adc ecx,0 shr eax,1 shl ecx,4 xor edx,edx mov dx,ax;nYStart shr eax,16 mov r8d,eax;nXStart mov rax,[PS+ecx] mov [rsp+20h],rax;cchString mov r9,[PS+ecx+8];lpString mov rcx,ps.PAINTSTRUCT.hdc call TextOut dec ebx jnz @bwmPAINT_END: lea edx,ps mov rcx,hwnd call EndPaintwmBYE: leave retn;---------------------------------------ClassName db 'Win64 Iczelion''s lesson #7a: Mouse Input',0text1 db 'right-clicking'text2 db 'left-clicking'PS dq 0,0,lengthof text1, text1, lengthof text2, text2recs dd MAXRECTS dup(?)nextRect dd -1end
OPTION DOTNAMEoption casemap:noneinclude temphls.incinclude win64.incinclude kernel32.incincludelib kernel32.libinclude user32.incincludelib user32.libOPTION PROLOGUE:rbpFramePrologueOPTION EPILOGUE:rbpFrameEpilogueZZZ_TEST equ 0 ZZZ_OPEN equ 1 ZZZ_SAVE equ 2 ZZZ_EXIT equ 3.codeWinMain proc msg equ [rbp-sizeof MSG] enter sizeof MSG+sizeof WNDCLASSEX+20h,0;90h,0 xor ebx,ebx push 10029h ;hIconSm lea rdi,ClassName push rdi ;lpszClassName lea eax,menu_name push rax ;lpszMenuName push COLOR_WINDOW;hbrBackground push 10005h ;hCursor push 10029h ;hIcon mov esi,400000h push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra lea rax,WndProc push rax ;lpfnWndProc push sizeof WNDCLASSEX;cbSize & style mov rcx,rsp ;addr WNDCLASSEX push rbx push rbx push rbx push rbx call RegisterClassEx add rsp,sizeof WNDCLASSEX+20h push rbx push rsi ;rsi=400000h shl esi,9 ;rsi=CW_USEDEFAULT push rbx push rbx push rsi push rsi push rsi push rsi mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx push rbx push rbx push rbx push rbx call CreateWindowEx lea edi,msg@@: mov ecx,edi xor edx,edx mov r8,rbx mov r9,rbx call GetMessage mov ecx,edi call DispatchMessage jmp @bWinMain endpWndProc: enter 20h,0 cmp edx,WM_DESTROY je wmDESTROY cmp edx,WM_COMMAND je wmCOMMAND leave jmp DefWindowProcwmDESTROY: xor ecx,ecx call ExitProcesswmCOMMAND:cmp r8,ZZZ_EXIT je wmDESTROY show_msg:mov r9,rbx;r9=MB_OK mov rdx,menu_handlers[r8*8] lea r8,menu_name call MessageBoxwmBYE: leave retn;---------------------------------------ClassName db 'Win64 Iczelion''s lesson #8: Menu',0menu_name db 'ZZZ_Menu',0test_msg db 'You select menu item TEST',0 open_msg db 'You select menu item OPEN',0 save_msg db 'You select menu item SAVE',0 menu_handlers dq test_msg, open_msg, save_msgend
#define ZZZ_TEST 0#define ZZZ_OPEN 1#define ZZZ_SAVE 2#define ZZZ_EXIT 3ZZZ_Menu MENU { POPUP "&File" { MENUITEM "&Test",ZZZ_TEST MENUITEM "&Open",ZZZ_OPEN MENUITEM "&Save",ZZZ_SAVE MENUITEM SEPARATOR MENUITEM "&Exit",ZZZ_EXIT } MENUITEM "&Exit",ZZZ_EXIT}
include win64a.incinclude gdi32.incincludelib gdi32.libIMAGE_BASE equ 400000hIDB_MYBITMAP equ 100.codeWinMain proc local msg:MSG push rbp mov rbp,rsp sub rsp,sizeof MSG xor ebx,ebx push 10029h ;hIconSm mov edi,offset ClassName push rdi ;lpszClassName push rbx ;lpszMenuName push COLOR_WINDOW;hbrBackground push 10005h ;hCursor push 10029h ;hIcon mov esi,IMAGE_BASE push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra mov eax,offset WndProc push rax ;lpfnWndProc push sizeof WNDCLASSEX;cbSize & style mov rcx,rsp ;addr WNDCLASSEX push rbx push rbx push rbx push rbx call RegisterClassEx push rbx push rsi ;rsi=400000h shr esi,7;Special CreateWindow position value CW_USEDEFAULT=8000h push rbx push rbx push 320 push 300 push rsi push rsi mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx push rbx push rbx push rbx push rbx call CreateWindowEx lea edi,msg@@: mov ecx,edi xor edx,edx mov r8,rbx mov r9,rbx call GetMessage mov ecx,edi call DispatchMessage jmp @bWinMain endp;---------------------------------------------------------------WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM LOCAL ps:PAINTSTRUCT LOCAL hMemDC:HDC LOCAL rect:RECT push rbp mov rbp,rsp sub rsp,sizeof PAINTSTRUCT+sizeof RECT+8+40h mov hWnd,rcx cmp edx,WM_DESTROY je wmDESTROY cmp edx,WM_CREATE je wmCREATE cmp edx,WM_PAINT je wmPAINT leave jmp DefWindowProcwmDESTROY:mov rcx,hBitmap call DeleteObject xor ecx,ecx call ExitProcesswmCREATE:mov edx,IDB_MYBITMAP mov ecx,IMAGE_BASE call LoadBitmap mov hBitmap,rax jmp wmBYEwmPAINT:lea edx,ps call BeginPaint mov rcx,rax call CreateCompatibleDC mov hMemDC,rax mov rdx,hBitmap mov rcx,rax call SelectObject lea edx,rect mov rcx,hWnd call GetClientRect mov qword ptr [rsp+40h],SRCCOPY mov [rsp+38h],rbx mov [rsp+30h],rbx mov rax,hMemDC mov [rsp+28h],rax mov eax,rect.bottom mov [rsp+20h],rax mov r9d,rect.right mov r8,rbx xor edx,edx mov rcx,ps.hdc call BitBlt mov rcx,hMemDC call DeleteDC lea edx,ps mov rcx,hWnd call EndPaint wmBYE: leave retn WndProc endp;---------------------------------------ClassName db 'Win64 Iczelion lesson #25a',0hBitmap dq ?end
#define IDB_MYBITMAP 100 IDB_MYBITMAP BITMAP "Images\\tweety78.bmp"
include win64a.incinclude gdi32.incincludelib gdi32.lib.codeWinMain proc local msg:MSG push rbp mov rbp,rsp sub rsp,sizeof MSG xor ebx,ebx mov esi,400000h lea rdi,ClassName mov qword ptr [rsp+28h],LR_LOADFROMFILE mov [rsp+20h],rbx mov r9,rbx mov r8,rbx mov edx,edi mov ecx,esi call LoadImage mov rcx,rax call CreatePatternBrush push 10029h ;hIconSm push rdi ;lpszClassName push rbx ;lpszMenuName push rax ;hbrBackground push 10005h ;hCursor push 10029h ;hIcon push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra lea eax,WndProc push rax ;lpfnWndProc push sizeof WNDCLASSEX;cbSize & style mov rcx,rsp ;addr WNDCLASSEX push rbx push rbx push rbx push rbx call RegisterClassEx push rbx push rsi ;rsi=400000h shl esi,9 ;rsi=CW_USEDEFAULT push rbx push rbx push 305 push 286 push rsi push rsi mov r9d,WS_OVERLAPPED or WS_VISIBLE or WS_CAPTION or \ WS_SYSMENU or WS_MINIMIZEBOX mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx push rbx push rbx push rbx push rbx call CreateWindowEx lea edi,msg@@: mov ecx,edi xor edx,edx mov r8,rbx mov r9,rbx call GetMessage mov ecx,edi call DispatchMessage jmp @bWinMain endpWndProc:cmp edx,WM_DESTROY je wmDESTROY jmp DefWindowProcwmDESTROY: xor ecx,ecx call ExitProcess;---------------------------------------ClassName db 'Images\tweety78.bmp',0end
Where do you find: win64.inc ???
On the site http://dsmhelp.narod.ru/environment.htm you can find a set of lib- and inc-files to create 64-bit applications in assembler, as well as a lot of useful macros.
OPTION DOTNAMEoption casemap:noneinclude temphls.incinclude win64.incinclude kernel32.incincludelib kernel32.libinclude user32.incincludelib user32.libOPTION PROLOGUE:rbpFramePrologueOPTION EPILOGUE:rbpFrameEpilogueZZZ_TEST equ 0 ZZZ_OPEN equ 1 ZZZ_SAVE equ 2 ZZZ_EXIT equ 3IMAGE_BASE equ 400000hZZZ_Menu equ 30.codeWinMain proc msg equ [rbp-sizeof MSG] enter sizeof MSG+sizeof WNDCLASSEX+20h,0;90h,0 xor ebx,ebx push 10029h ;hIconSm lea edi,ClassName push rdi ;lpszClassName push rbx ;lpszMenuName push COLOR_WINDOW;hbrBackground push 10005h ;hCursor push 10029h ;hIcon mov esi,IMAGE_BASE push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra lea eax,WndProc push rax ;lpfnWndProc push sizeof WNDCLASSEX;cbSize & style mov rcx,rsp ;addr WNDCLASSEX push rbx push rbx push rbx push rbx call RegisterClassEx add rsp,sizeof WNDCLASSEX+20h mov edx,ZZZ_Menu mov ecx,IMAGE_BASE call LoadMenu push rbx push rsi ;rsi=400000h shl esi,9 ;rsi=CW_USEDEFAULT push rax push rbx push rsi push rsi push rsi push rsi mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx push rbx push rbx push rbx push rbx call CreateWindowEx lea edi,msg@@: mov ecx,edi xor edx,edx mov r8,rbx mov r9,rbx call GetMessage mov ecx,edi call DispatchMessage jmp @bWinMain endpWndProc: enter 20h,0 cmp edx,WM_DESTROY je wmDESTROY cmp edx,WM_COMMAND je wmCOMMAND leave jmp DefWindowProcwmDESTROY: xor ecx,ecx call ExitProcesswmCOMMAND:cmp r8,ZZZ_EXIT je wmDESTROY show_msg:mov r9,rbx;r9=MB_OK mov rdx,menu_handlers[r8*8] lea r8,menu_name call MessageBoxwmBYE: leave retn;---------------------------------------ClassName db 'Win64 Iczelion''s lesson #8a: Menu and LoadMenu',0menu_name db 'ZZZ_Menu',0test_msg db 'You select menu item TEST',0 open_msg db 'You select menu item OPEN',0 save_msg db 'You select menu item SAVE',0 menu_handlers dq test_msg, open_msg, save_msgend
#define ZZZ_TEST 0#define ZZZ_OPEN 1#define ZZZ_SAVE 2#define ZZZ_EXIT 3#define ZZZ_Menu 30ZZZ_Menu MENU { POPUP "&File" { MENUITEM "&Test",ZZZ_TEST MENUITEM "&Open",ZZZ_OPEN MENUITEM "&Save",ZZZ_SAVE MENUITEM SEPARATOR MENUITEM "&Exit",ZZZ_EXIT } MENUITEM "&Exit",ZZZ_EXIT}