汇编,SendMessage和WM_SETTEXT

接受代码
.386
.model flat,stdcall
option casemap:none

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


.data

_className db "MyClass",0
_szBuffer db 256 dup(?)

_swTitle db "测试标题",0
_szReceive db "hello Window",0dh,0ah
db "param:%08x",0dh,0ah
db "text:%s",0


.data?
_hInstance dd ?
_hWinMan dd ?
.const
.code




;消息过程
_ProcMain proc uses ebx edi esi hWnd,uMsg,wParam,lParam

mov eax,uMsg
;--------------------------------------------------------------------------------
.if eax==WM_PAINT
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.elseif eax==WM_CLOSE

invoke DestroyWindow,_hWinMan
invoke PostQuitMessage,NULL
;.elseif eax==WM_CREATE

.elseif eax==WM_SETTEXT
invoke wsprintf,offset _szBuffer,offset _szReceive,lParam,lParam
invoke MessageBox,NULL,offset _szBuffer,offset _swTitle,MB_YESNO
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
;or eax,eax
ret
;--------------------------------------------------------------------------------
_ProcMain endp
;后缀EX扩展的意思。代码书写格式为易读性 st结构 h模块 _全局 @局部
_Win32Main proc
LOCAL @stWNDClass:WNDCLASSEX
LOCAL @stMSG:MSG

invoke GetModuleHandle,NULL
mov _hInstance,eax
;初始化
invoke RtlZeroMemory,addr @stWNDClass,sizeof @stWNDClass

invoke LoadCursor,0,IDC_ARROW ;获取鼠标模块
;结构
mov @stWNDClass.hCursor,eax
; push _hInstance;1
;pop @stWNDClass.hInstance;1

mov @stWNDClass.hInstance,offset _hInstance;2 上面的1 和这里的2 有什么不同 这两句为什么实现的不是一个效果 有什么不同?
mov @stWNDClass.cbSize,sizeof WNDCLASSEX
mov @stWNDClass.hbrBackground,COLOR_WINDOW
mov @stWNDClass.lpszClassName,offset _className
mov @stWNDClass.lpfnWndProc,offset _ProcMain
mov @stWNDClass.style,CS_HREDRAW or CS_VREDRAW

invoke RegisterClassEx,addr @stWNDClass

;创建窗口
invoke CreateWindowEx,WS_EX_CLIENTEDGE,offset _className,offset _swTitle,WS_OVERLAPPEDWINDOW,\
100,100,444,555,\
NULL,NULL,_hInstance,NULL
mov _hWinMan,eax
;显示窗口
invoke ShowWindow,_hWinMan,SW_SHOWNORMAL
;刷新绘制 发送WM_PAINT消息
invoke UpdateWindow,_hWinMan
;消息循环
;GetMessage 如果取得的MSG是WM_QUIT EAX就等于0,否则非零
;PeekMessage 有消息返回非零,否则直接返回EAX等于0
.while TRUE

invoke GetMessage,addr @stMSG,NULL,0,0
.break .if eax==0
invoke TranslateMessage,addr @stMSG
invoke DispatchMessage,addr @stMSG

.endw

ret


_Win32Main endp


start:
Call _Win32Main
invoke ExitProcess,NULL
end start
发送代码
.386
.model flat,stdcall
option casemap:none

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


.data
_szNoFindTxet db "没有找到窗口",0
_szYesFindTxet db "点击OK 开始发送消息 %08x",0
_szSendText db "test send Message",0
_sztitle db "send Message",0
_className db "Myclass",0
_szTiShi db "开始寻找",0
_szBuffer db 256 dup(?)
.data?
_hInstance dd ?
_hWindow dd ?
.const
.code



;后缀EX扩展的意思。代码书写格式为易读性 st结构 h模块 _全局 @局部
_Win32Main proc
invoke MessageBox,NULL,offset _szTiShi,offset _sztitle,MB_OK
invoke FindWindow,offset _className,NULL
mov _hWindow,eax
.if eax
invoke wsprintf,offset _szBuffer,offset _szYesFindTxet,offset _szSendText
invoke MessageBox,NULL,offset _szBuffer,offset _sztitle,MB_OK
invoke SendMessage,_hWindow,WM_SETTEXT,0,offset _szSendText
.else
invoke MessageBox,NULL,offset _szNoFindTxet,offset _sztitle,MB_OK
.endif

invoke ExitProcess,NULL
_Win32Main endp


start:
Call _Win32Main
invoke ExitProcess,NULL
end start


PostMessage和SendMessage

差别在于,postmessage 该函数不能用户任何参数中用到的指针ps:WM_COPYDATA

原文地址:https://www.cnblogs.com/yueyue184/p/2271919.html