.386
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
include user32.inc
include gdi32.inc
includelib gdi32.lib
includelib kernel32.lib
includelib user32.lib
.data?
hInstance dd ?
hWinMain dd ?
.data
szCaption db 'Different Style Windows',0
szClass db 'WindowStyle',0
.const
IDC_CUR equ 1001
IDC_MAIN equ 1002
.code
;****************************************************************************************************
;視窗過程
;****************************************************************************************************
_ProcWinMain proc hWnd,uMsg,wParam,lParam
LOCAL @stPs:PAINTSTRUCT
LOCAL @stRect:RECT
LOCAL @hdc:HDC
mov eax,uMsg
.if eax==WM_PAINT
invoke BeginPaint,hWnd,addr @stPs
mov @hdc,eax
invoke GetClientRect,hWnd,addr @stRect
invoke DrawText,@hdc,addr szCaption,-1,addr @stRect,DT_VCENTER or DT_CENTER
invoke EndPaint,hWnd,addr @stPs
.elseif eax ==WM_CLOSE
invoke DestroyWindow,hWnd
invoke PostQuitMessage,NULL
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
xor eax,eax
ret
_ProcWinMain endp
_WinMain proc
LOCAL @stWndClass:WNDCLASSEX
LOCAL @stMsg:MSG
;*******************************************************************************************************
;注冊視窗類
;*******************************************************************************************************
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
; 給程式添加新的滑鼠形狀
invoke LoadCursor,hInstance,IDC_CUR
mov @stWndClass.hCursor,eax
push hInstance
pop @stWndClass.hInstance
mov @stWndClass.cbSize,sizeof WNDCLASSEX
mov @stWndClass.style,CS_HREDRAW or CS_HREDRAW
mov @stWndClass.lpfnWndProc,offset _ProcWinMain
mov @stWndClass.hbrBackground,COLOR_WINDOW+1
mov @stWndClass.lpszClassName,offset szClass
; 給程式添加圖示
invoke LoadIcon,hInstance,IDC_MAIN
mov @stWndClass.hIcon,eax
invoke RegisterClassEx,addr @stWndClass
;*********************************************************************************************************
;建立并顯示視窗
;*********************************************************************************************************
invoke CreateWindowEx,WS_EX_CLIENTEDGE,addr szClass,addr szCaption,WS_OVERLAPPEDWINDOW,100,100,600,400,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
_WinMain endp
start:
call _WinMain
invoke ExitProcess,NULL
end start
使用RADAsm 編寫的WIN32 視窗程式,主要用到函數與編輯過程與VC 差不多。WIN32 視窗程式主要分三個部分:
1.視窗過程,用于處理視窗接受到的各種消息。在WIN32彙編中視窗過程的函數格式比較固定 ,主要有三個參數:hWnd:視窗句柄 uMsg:消息類型,wparam,lparam:與消息有關的·
_ProcWinMain proc hWnd,uMsg,wParam,lParam
_ProcWinWain endp
2.注冊視窗類,填充 WNDCLASSEX 結構,使用CreateWindowEx建立視窗。
3. 死循環建立消息循環。GetMessage, translateMessage,DisPatchMessage