最近看罗哥的WIN32
以下程序:
=================
send
=================
.386
.model flat,stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;include
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hWnd dd ?
szBuffer db 256 dup(?)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.const
szCaption db 'sendMessage',0
szStart db 'Press OK to start sendMessage,param:%08x!',0
szReturn db 'sendMessage Return!',0
szDestClass db 'MyClass',0
szText db 'Text Send to other windows',0
szNotFound db 'receive Message Window not find',0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
start:
invoke FindWindow,addr szDestClass,NULL
.if eax
mov hWnd,eax
invoke wsprintf,addr szBuffer,addr szStart,addr szText
invoke MessageBox,NULL,addr szBuffer,addr szCaption,MB_OK
;invoke SendMessage,hWnd,WM_SETTEXT,0,addr szText
;invoke PostMessage,hWnd,WM_SETTEXT,0,addr szText;失败 invoke MessageBox,NULL,addr szReturn,addr szCaption,MB_OK
.else
invoke MessageBox,NULL,addr szNotFound,addr szCaption,MB_OK
.endif
invoke ExitProcess,NULL
end start
=======================================================
recive
======================================================
.386
.model flat,stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;include file define
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include gdi32.inc
includelib gdi32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;data segment
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance dd ?
hWinMain dd ?
szBuffer db 256 dup(?)
.const
szCaptionMain db 'My First Windows!',0
szText db 'Win32 Assembley,Simple And Powerful!',0
szClassName db 'MyClass',0
szRecive db 'Recive WM_SETTEXT message',0dh,0ah
db 'param:%08x',0dh,0ah
db 'Text:%s',0
szRecCaption db 'Recive',0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;code segment
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;Deal Message Proc
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_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 DestroyWindow,hWnd
invoke PostQuitMessage,NULL
;***************************************************************************
.
elseif eax==WM_SETTEXT
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
invoke wsprintf,addr szBuffer,addr szRecive, lParam,lParam
invoke MessageBox,NULL,addr szBuffer,addr szRecCaption ,MB_OK;***************************************************************************
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
;***************************************************************************
xor eax,eax
ret
_ProcWinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;Create Window Proc
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_WinMain proc
LOCAL @stWndClass:WNDCLASSEX
LOCAL @stMsg:MSG
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
;*******************************************************************************
;Regist Class
;*******************************************************************************
invoke LoadCursor,hInstance,IDC_ARROW
mov @stWndClass.hCursor,eax
push hInstance
pop @stWndClass.hInstance
mov @stWndClass.cbSize,sizeof @stWndClass
mov @stWndClass.style,CS_HREDRAW or CS_VREDRAW or CS_DBLCLKS
mov @stWndClass.lpfnWndProc,_ProcWinMain
mov @stWndClass.hbrBackground,COLOR_WINDOW+1
mov @stWndClass.lpszClassName,offset szClassName
invoke RegisterClassEx,addr @stWndClass
;*******************************************************************************
;Create Window And Show Update
;*******************************************************************************
invoke CreateWindowEx,WS_EX_CLIENTEDGE,offset szClassName,\
offset szCaptionMain,WS_OVERLAPPEDWINDOW,\
100,100,600,400,\
NULL,NULL,hInstance,NULL
mov hWinMain,eax
invoke ShowWindow,hWinMain,SW_SHOWNORMAL
invoke UpdateWindow,hWinMain
;******************************************************************************
;MSG
;******************************************************************************
.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
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;Main Proc
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
call _WinMain
invoke ExitProcess,NULL
end start
=================================================================
上面蓝色的
SendMessage时recive弹出MessageBox说明处理了WM_SETTEXT,然后send返回
PostMessage,send直接返回,recive没有弹出MessageBox等了半天都没说明没有处理了WM_SETTEXT
那什么时候处理WM_SETTEXT啊
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!