.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
include kernel32.inc
includelib user32.lib
includelib kernel32.lib
.const
szClassName db 'MyWindow',0
szWinName db '第一个汇编窗口',0
szHello db 'Hello',0
.data?
hInstance dd ?
hWinMain dd ?
.code
_WindowProc proc uses ebx esi edi,hwnd,uMsg,wParam,lParam
LOCAL @stPaint:PAINTSTRUCT
LOCAL @stRect:RECT
LOCAL @hdc
;mov eax,uMsg
.if uMsg == WM_CLOSE
invoke DestroyWindow,hWinMain
invoke PostQuitMessage,NULL
.elseif uMsg == WM_PAINT
invoke BeginPaint,hWinMain,addr @stPaint
mov @hdc,eax
invoke GetClientRect,hWinMain,addr @stRect
invoke DrawText,@hdc,offset szHello,-1,addr @stRect,DT_SINGLELINE or DT_CENTER or DT_VCENTER
invoke EndPaint,hWinMain,addr @stPaint
.else
invoke DefWindowProc,hwnd,uMsg,wParam,lParam
;ret ;这里注释掉后功能正常
.endif
;xor eax,eax ;这里注释掉后功能正常
ret
_WindowProc endp
_Main proc
LOCAL @stWndClass:WNDCLASSEX
LOCAL @stMsg:MSG
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
invoke LoadCursor,NULL,IDC_ARROW
push hInstance
pop @stWndClass.hInstance
mov @stWndClass.cbSize,sizeof @stWndClass
mov @stWndClass.style,CS_VREDRAW or CS_HREDRAW
mov @stWndClass.lpfnWndProc,offset _WindowProc
mov @stWndClass.hbrBackground,COLOR_WINDOW + 1
mov @stWndClass.lpszClassName,offset szClassName
invoke RegisterClassEx,addr @stWndClass
invoke CreateWindowEx,WS_EX_CLIENTEDGE,\
offset szClassName,
offset szWinName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,NULL,hInstance,NULL
mov hWinMain,eax
invoke ShowWindow,hWinMain,SW_SHOWNORMAL
invoke UpdateWindow,hWinMain
.while TRUE
invoke GetMessage,addr @stMsg,NULL,0,0
.break .if eax == 0
invoke TranslateMessage,addr @stMsg
invoke DispatchMessage,addr @stMsg
.endw
ret
_Main endp
start:
invoke _Main
invoke ExitProcess,NULL
end start
==========================================================================
以上程序摘自罗云彬的《Windows环境下32位汇编语言程序设计-琢石成器》
源代码通过Radasm编译运行通过