'.386
'.model flat,stdcall
'option casemap:none
#compact
$ filename "Text.exe"
'include "$inc/RTL32.inc"
include "$inc/minwin.inc"
% COLOR_WINDOW=5
% OUT_DEFAULT_PRECIS=0
% OEM_CHARSET=255
'WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
declare sub WinMain(sys hInst,hPrevInst, asciiz* CmdLine, sys CmdShow)
'include \masm32\include\windows.inc
'include \masm32\include\user32.inc
'include \masm32\include\kernel32.inc
'include \masm32\include\gdi32.inc
'includelib \masm32\lib\user32.lib
'includelib \masm32\lib\kernel32.lib
'includelib \masm32\lib\gdi32.lib
macro RGB (red,green,blue)
xor eax,eax
mov ah,blue
shl eax,8
mov ah,green
mov al,red
end macro
'.data
'ClassName db "SimpleWinClass",0
'AppName db "Our First Window",0
'TestString db "Win32 assembly is great and easy!",0
'FontName db "script",0
zstring ClassName = "SimpleWinClass"
zstring AppName = "Our First Window"
zstring TestString = "Win32 assembly is great and easy!"
zstring FontName = "script"
'.data?
'hInstance HINSTANCE ?
'CommandLine LPSTR ?
sys hInstance
asciiz ptr CommandLine
'.code
'start:
' invoke GetModuleHandle, NULL
' mov hInstance,eax
' invoke GetCommandLine
' mov CommandLine,eax
' invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
' invoke ExitProcess,eax
hInstance=GetModuleHandle NULL
&CommandLine=GetCommandLine
WinMain hInstance, NULL, CommandLine, SW_SHOWDEFAULT
'WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
sub WinMain(sys hInst,hPrevInst, asciiz* CmdLine, sys CmdShow)
' LOCAL wc:WNDCLASSEX
' LOCAL msg:MSG
' LOCAL hwnd:HWND
WNDCLASSEX wc
MSG msg
sys hwnd
' mov wc.cbSize,SIZEOF WNDCLASSEX
' mov wc.style, CS_HREDRAW or CS_VREDRAW
' mov wc.lpfnWndProc, OFFSET WndProc
' mov wc.cbClsExtra,NULL
' mov wc.cbWndExtra,NULL
' push hInst
' pop wc.hInstance
' mov wc.hbrBackground,COLOR_WINDOW+1
' mov wc.lpszMenuName,NULL
' mov wc.lpszClassName,OFFSET ClassName
' invoke LoadIcon,NULL,IDI_APPLICATION
' mov wc.hIcon,eax
' mov wc.hIconSm,eax
' invoke LoadCursor,NULL,IDC_ARROW
' mov wc.hCursor,eax
wc.cbSize=SIZEOF WNDCLASSEX
wc.style=CS_HREDRAW or CS_VREDRAW
wc.lpfnWndProc= @WndProc
wc.cbClsExtra= NULL
wc.cbWndExtra= NULL
wc.hInstance=hInstance
wc.hbrBackground= COLOR_WINDOW+1
wc.lpszMenuName= NULL
wc.lpszClassName= @ClassName
wc.hIcon= LoadIcon NULL, IDI_APPLICATION
wc.hIconSm= LoadIcon NULL, IDI_APPLICATION
wc.hCursor= LoadCursor NULL, IDC_ARROW
' invoke RegisterClassEx, addr wc
if not RegisterClassEx @wc then mbox "Registration failed" : end
' INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
' WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
' CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
' hInst,NULL
' mov hwnd,eax
' INVOKE ShowWindow, hwnd,SW_SHOWNORMAL
' INVOKE UpdateWindow, hwnd
hwnd= CreateWindowEx NULL,@ClassName,@AppName,
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,
hInst,NULL
if hwnd=NULL then mbox "CreateWindow failed" : end
ShowWindow hwnd, SW_SHOWNORMAL
UpdateWindow hwnd
' .WHILE TRUE
' INVOKE GetMessage, ADDR msg,NULL,0,0
' .BREAK .IF (!eax)
' INVOKE TranslateMessage, ADDR msg
' INVOKE DispatchMessage, ADDR msg
' .ENDW
' mov eax,msg.wParam
' ret
while GetMessage @msg, NULL, 0, 0
TranslateMessage @msg
DispatchMessage @msg
wend
'WinMain endp
end sub
'WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
function WndProc (sys hWnd, uint uMsg, sys wParam, lParam) as sys callback
' LOCAL hdc:HDC
' LOCAL ps:PAINTSTRUCT
' LOCAL hfont:HFONT
sys hdc
PAINTSTRUCT ps
sys hfont
' .IF uMsg==WM_DESTROY
' invoke PostQuitMessage,NULL
' .ELSEIF uMsg==WM_PAINT
' invoke BeginPaint,hWnd, ADDR ps
' mov hdc,eax
' invoke CreateFont,24,16,0,0,400,0,0,0,OEM_CHARSET,\
' OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
' DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT,\
' ADDR FontName
' invoke SelectObject, hdc, eax
' mov hfont,eax
' RGB 200,200,50
' invoke SetTextColor,hdc,eax
' RGB 0,0,255
' invoke SetBkColor,hdc,eax
' invoke TextOut,hdc,0,0,ADDR TestString,SIZEOF TestString
' invoke SelectObject,hdc, hfont
' invoke EndPaint,hWnd, ADDR ps
' .ELSE
' invoke DefWindowProc,hWnd,uMsg,wParam,lParam
' ret
' .ENDIF
' xor eax,eax
' ret
IF uMsg=WM_DESTROY then
PostQuitMessage NULL
ELSEIF uMsg=WM_PAINT then
hdc=BeginPaint hWnd, @ps
CreateFont 24,16,0,0,400,0,0,0,OEM_CHARSET,
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT,
@FontName
SelectObject hdc, eax
mov hfont,eax
RGB 200,200,50
SetTextColor hdc,eax
RGB 0,0,255
SetBkColor hdc,eax
TextOut hdc,0,0,@TestString,len TestString
SelectObject hdc, hfont
EndPaint hWnd, @ps
ELSE
return DefWindowProc hWnd,uMsg,wParam,lParam
ENDIF
'WndProc endp
end function
'end start