.386
.model flat, stdcall
option casemap:none
include windows.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
.data
AppLoadMsgTitle db "装载应用程序", 0
AppLoadMsgText db "收到WM_CREATE消息", 0
PopupTitle db "弹出窗口", 0
PopupText db "您已经按下鼠标左键", 0
GreetTitle db "主窗口激活", 0
GreetText db "将显示主窗口", 0
CloseMsg db "收到WM_CLOSE消息", 0
CloseWinMsg db "关闭窗口", 0
ErrorTitle db "错误", 0
WindowName db "鱼C工作室(www.fishc.com)Win32案例演示程序"
ClassName db "类名", 0
MainWin WNDCLASS <CS_HREDRAW or CS_VREDRAW,\
WinProc,\
NULL,\
NULL,\
NULL,\
NULL,\
NULL,\
COLOR_WINDOW+1,\
NULL,\
ClassName>
msg MSG <> ; 消息结构
winRect RECT <> ; 矩形坐标结构
hMainWnd dd ? ; 主窗口的句柄
hInstance dd ? ; 模块的句柄
.code
WinMain PROC ; 主程序入口点
invoke GetModuleHandle, NULL ; 获取本模块句柄
mov hInstance, eax
mov MainWin.hInstance, eax
invoke LoadIcon, NULL, IDI_APPLICATION ; 载入图标并填充
mov MainWin.hIcon, eax
invoke LoadCursor, NULL, IDC_ARROW ; 载入鼠标光标并填充
mov MainWin.hCursor, eax
invoke RegisterClass, addr MainWin ; 注册窗口
.if eax == 0
call ErrorHandler ; 显示错误信息,该过程在后边定义
jmp Exit_Program
.endif
invoke CreateWindowEx,WS_EX_CLIENTEDGE,offset ClassName,offset WindowName,\
WS_OVERLAPPEDWINDOW,\
100,100,600,400,\
NULL,NULL,hInstance,NULL
mov hMainWnd, eax
.if eax == 0
call ErrorHandler
jmp Exit_Program
.endif
invoke ShowWindow, hMainWnd, SW_SHOW
invoke UpdateWindow, hMainWnd
invoke MessageBox,
hMainWnd,
addr GreetText,
addr GreetTitle,
MB_OK
@@:
invoke GetMessage, ; 从消息队列取消息
addr msg, ; 传入待填充的消息结构的地址
NULL, ; NULL代表要取本程序所属的窗口的消息
NULL,
NULL
.if eax == 0 ; 没有获得消息
jmp Exit_Program
.endif
invoke DispatchMessage,
addr msg
jmp @B
Exit_Program:
invoke ExitProcess, 0
WinMain ENDP
WinProc PROC, hWnd:DWORD, localMsg:DWORD, wParam:DWORD, lParam:DWORD
mov eax, localMsg
.if eax == WM_LBUTTONDOWN
invoke MessageBox, hWnd, addr PopupText, addr PopupTitle, MB_OK
jmp WinProcExit
.elseif eax == WM_CLOSE
invoke MessageBox, hWnd, addr CloseMsg, addr CloseWinMsg, MB_OK
invoke PostQuitMessage, 0
jmp WinProcExit
.elseif eax == WM_CREATE
invoke MessageBox, hWnd, addr AppLoadMsgText, addr AppLoadMsgTitle, MB_OK
jmp WinProcExit
.else
invoke DefWindowProc, hWnd, localMsg, wParam, lParam
jmp WinProcExit
.endif
WinProcExit:
ret
WinProc ENDP
ErrorHandler PROC
local pErrorMsg:DWORD
local messageID:DWORD
invoke GetLastError
mov messageID, eax
invoke FormatMessage,
FORMAT_MESSAGE_ALLOCATE_BUFFER + FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
messageID,
NULL,
addr pErrorMsg,
NULL,
NULL
invoke MessageBox, NULL, pErrorMsg, addr ErrorTitle, MB_ICONERROR + MB_OK
invoke LocalFree, pErrorMsg
ret
ErrorHandler ENDP
END WinMain
这是基于win32汇编的一个窗口代码,求最佳答案