Where is my way?

 

汇编学习Windows窗体(1)

.386
.model flat,stdcall
option
casemap:none

include windows.
inc
include gdi32.
inc
includelib gdi32.lib
include user32.
inc
includelib user32.lib
include kernel32.
inc
includelib kernel32.lib

.data?
hInstance dd ?
hWinMain dd ?

.const
szClassName db
'MyClass',0
szMainCaption db
'My first Window!',0
szText db
'YangGuo is my Gays'

.code

;>>>>>>>>>>>>>>>>>>>>>>»Øµ÷¹ý³Ì>>>>>>>>>>>>>>>>>>>>
_ProcWinMain PROC uses ebx edi esi 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 PostQuitMessage,NULL
.else
invoke DefWindowProc,hwnd,uMsg,wParam,lParam
ret
.endif

xor eax,eax
ret

_ProcWinMain ENDP

_mainWindow PROC
local
@stWndClass:WNDCLASSEX ;
local @stMsg:MSG ;ÏûÏ¢

;»ñÈ¡³ÌÐòʵÀý ·µ»ØÖµ±£´æµ½eax
invoke GetModuleHandle,NULL
mov hInstance,eax

;³õʼ»¯½á¹¹Ì嶼Ϊ0
invoke RtlZeroMemory,addr @stWndClass,sizeOf @stWndClass

invoke LoadCursor,
0,IDC_ARROW ;ÉèÖùâ±ê
mov @stWndClass.hIcon,eax

push hInstance
pop @stWndClass.hInstance ;ÉèÖóÌÐòhInstance

mov @stWndClass.style,CS_HREDRAW OR CS_VREDRAW ;´°Ìå·ç¸ñ
mov @stWndClass.lpfnWndProc, offset _ProcWinMain ;º¯Êýµ÷ÓõØÖ·
mov @stWndClass.lpszClassName,offset szClassName
mov @stWndClass.cbSize,sizeof WNDCLASSEX

;×¢²á´°Ìå
invoke RegisterClassEx,addr @stWndClass

;´´½¨´°Ìå
invoke CreateWindowEx,WS_EX_CLIENTEDGE,\
offset szClassName,\
offset szMainCaption,\
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,hWinMain,
0,0
.break .if eax ==
0
invoke TranslateMessage,addr @stMsg
invoke DispatchMessage,addr @stMsg
.endw
ret

_mainWindow ENDP

start:
call _mainWindow
invoke ExitProcess,NULL
end start





一、模块的概念

一个模块代表的是一个运行中的exe文件或dll文件,用来代表这个文件中所有的代码和资源,磁盘上的文件不是模块.将入内存运行时就叫做模块.一个应用程序调用其他DLL中的API时,这些DLL文件被载入内存,就产生了不同的模块,为了区分地址空间中不同的模块,每个模块都有一个唯一的模块句柄来标识.
取模块句柄使用的API函数是 GetModuleHandle
invoke GetModuleHandle,lpModuleName
lpModuleName参数是一个指向含有名称字符串的指针.NUL默认调用者本模块的句柄
返回的句柄在eax寄存器中保存

二、句柄是什么
一个unsign long integer无符号长整型数值,是唯一,通过句柄可对程序进行各种操作

posted on 2011-08-26 16:30  ManLoveGirls  阅读(295)  评论(0)    收藏  举报

导航