.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include gdi32.inc
includelib gdi32.lib
;数据段
;-------------------------------------------------------------------------------
.data?
hInstance dd ?
hWinMain dd ?
;-------------------------------------------------------------------------------
.const
szClassName db 'My Class',0
szCaptionMain db 'My first window',0
SzText db 'Win32 Assembly, simple and powerful !',0
;-------------------------------------------------------------------------------
;代码段
;-------------------------------------------------------------------------------
.code
;-------------------------------------------------------------------------------
_ProcWinMain proc uses ebx esi edi,hWnd,uMsg,wParam,lparam
local @stPs:PAINTSTRUCT
local @stRect:RECT
local @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 SzText,-1,\
addr @stRect,\
DT_SINGLELINE or DT_CENTER or DT_VCENTER
;将字符串写入“设备环境”中,
invoke EndPaint,hWnd,addr @stPs
.elseif eax == WM_CLOSE
invoke DestroyWindow,hWinMain
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
;将GetModuleHandle函数的返回值赋值给全局变量hInstance
invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
;将stWndClass类型数据内存用0填充
;注册窗口
invoke LoadCursor,0,IDC_ARROW
mov @stWndClass.hCursor,eax
;获取光标句柄并赋值给结构体元素hCursor
push hInstance
pop @stWndClass.hInstance
;获取模块句柄赋值给结构体元素Instance
mov @stWndClass.cbSize,sizeof WNDCLASSEX
;获取结构体的字节数赋值给结构体元素cbSize
mov @stWndClass.style,CS_HREDRAW or CS_VREDRAW
;获取窗口风格:高度和宽度改变时是否重画
mov @stWndClass.lpfnWndProc,offset _ProcWinMain
;获取窗口过程地址
mov @stWndClass.hbrBackground,COLOR_WINDOW+1
;获取背景颜色COLOR_WINDOW是系统预定义的颜色+1表示使用
mov @stWndClass.lpszClassName,offset szClassName
;获取类名,以便引用这个风格的窗口模式
;Button表示按钮,Edit表示按钮
invoke RegisterClassEx,addr @stWndClass
;调用注册窗口函数
; WNDCLASSEX STRUCT
; cbsize 结构的字节数
; style 类风格
; lpfnWndproc 窗口过程地址
; hInstance 实例句柄
; cbclsextra
; cbwndextra
; hicon 图标句柄
; hiconsm 小图标
; hcursor 光标句柄
; hbrBackground 背景颜色
; lpszmenuname 窗口菜单
; lpszclassname 类名字符串的地址
;建立窗口
;invoke CreateWindowEx,dwExstyle,lpClassName,lpWindowName,\
dwstylex,y,nwidth,nHeight,hWndParent,hMenu,hInstance,lpParam
;建立窗口的模板
;1 dwExstyle 为W32的扩展的风格,以WS_EX_SZ为标准的一系列风格
;2 lpClassName 建立窗口使用的类名字符串指针,如果使用My class
;是注册窗口使用的类名字符串,如果使用则拥有My class的所有属性,
;并且消息将会发送到该类名中指定的窗口过程中去。
;3 lpWindowName 指向标题栏中的自定义的字符串
;4 dwstyle一些常有的属性,以WS_SZ为标准的一系列风格WS_CHILD表
;示子窗口WS_VISIBLE表示在子窗口如按钮类时,显示可见,如果未指定
;,则不会显示出来
;5 x,y 指窗口左上角的位置
;6 nWidth,nHeight 指窗口的宽度和高度
;x,y,nWidth,nHeight都是以像素为单位
;7 hWndparent 父窗口的句柄,定义后在父窗口销毁时子窗口一同销毁
;8 hMenu 当为主窗口时:表示的时菜单的属性
; 当表示子窗口时:表示的是子窗口的ID号
;9 hInstance 表示本程序的句柄
;10 lpparam 指向窗口的创建数据
invoke CreateWindowEx,WS_EX_CLIENTEDGE,\
offset szClassName,offset szCaptionMain,\
WS_OVERLAPPEDWINDOW,\
200,200,1000,600,\
NULL,NULL,hInstance,NULL
;ShowWindow函数
;参数一:hWinMain窗口句柄,即在CreateWindow函数中返回值
;参数二:包括控制窗口的状态(显示或隐藏),大小控制(最大值,最
;小值或原始大小)
;,是否激活(当前的窗口或其他窗口) 激活:你操作时消息传入的窗口
mov hWinMain,eax
invoke ShowWindow,hWinMain,SW_SHOWNORMAL
;UpdateWindow函数
invoke UpdateWindow,hWinMain
;参数:窗口句柄
;函数作用绘制客户区,即向窗口发送一条WM_PAINT消息
;消息循环
;GetMessage函数
;invoke Getmessage,lpMsg,hWnd,wMngFilterMin,wMngFilterMax
;参数一:MSG 结构体, hwnd(消息要发向的窗口句柄) message(消息标
;识符以WM_开头的) wparam(消息参数一)
; lParam(消息参数二) time(消息进入消息队列的时间)
; pt(消息放入消息队列的鼠标坐标)
;参数二:hWnd 指定要获取哪个窗口的消息
;参数三,参数四:获取所有本程序所属窗口的消息,Min和Max表示0
;表示获取所有编号的消息
.while TRUE
invoke GetMessage,addr @stMsg,NULL,0,0
;TranslateMessage函数
;将MSG结构传给Windows进行键盘消息的转换,如WM_KEYDOWN或
;WM_SYSKEYDOWN(区别:SYS指按下了AIT键)
;各个键位的扫描码转换成ASCII码在消息队列插入WM_CHAR或WM_SYSCHAR
invoke TranslateMessage,addr @stMsg
;DispatchMessage函数
;将消息派遣给过程窗口处理
invoke DispatchMessage,addr @stMsg
.endw
ret
_WinMain endp
;主函数
start:
call _WinMain
invoke ExitProcess,NULL
end start
转载请注明原文地址: https://ju.6miu.com/read-674108.html