win32汇编-送消息给其它应用程序

2个函数
invoke postmessage,hwnd,msg,wparam,lparam
invoke sendmessage,hwnd,msg,wparam,lparam
对于不同的MSG,WPARAM和LPARAM所代表的信息是不同的
1、postmessage

MSDN

The PostMessage function places (posts) a message in the messagequeue associated with the thread that created the specified windowand returns without waiting for the thread to process themessage.
这个函数将消息送到指定窗口的线程后马上返回而不等待,sendmessage必须等该消息被处理后才能返回。

To post a message in the message queue associate with a thread, usethe PostThreadMessage function.


Syntax

BOOL PostMessage( HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
Parameters

hWnd
[in] Handle to the window whose window procedure is to receive themessage. The following values have special meanings.

HWND_BROADCAST
The message is posted to all top-level windows in the system,including disabled or invisible unowned windows, overlappedwindows, and pop-up windows. The message is not posted to childwindows
送给系统的的所有顶层主窗口,不会送到子窗口

.
NULL
The function behaves like a call to PostThreadMessage with thedwThreadId parameter set to the identifier of the currentthread.

Msg
[in] Specifies the message to be posted.
wParam
[in] Specifies additional message-specific information.
lParam
[in] Specifies additional message-specific information.
Return Value

If the function succeeds, the return value is nonzero.成功返回非0

If the function fails, the return value is zero. To get extendederror information, call GetLastError. 错误返回0




Remarks

Messages in a message queue are retrieved by calls to theGetMessage or PeekMessage function.

Applications that need to communicate using HWND_BROADCAST shoulduse the RegisterWindowMessage function to obtain a unique messagefor inter-application communication.

The system only does marshalling for system messages (those in therange 0 to WM_USER). To send other messages (those above WM_USER)to another process, you must do custom marshalling.

If you send a message in the range below WM_USER to theasynchronous message functions (PostMessage, SendNotifyMessage, andSendMessageCallback), its message parameters cannot includepointers. Otherwise, the operation will fail. The functions willreturn before the receiving thread has had a chance to process themessage and the sender will free the memory before it isused.

Do not post the WM_QUIT message using PostMessage; use thePostQuitMessage function.

Windows 2000/XP: There is a limit of 10,000 posted messages permessage queue. This limit should be sufficiently large. If yourapplication exceeds the limit, it should be redesigned to avoidconsuming so many system resources. To adjust this limit, modifythe following registry key:

2、SendMessage Function

--------------------------------------------------------------------------------

The SendMessage function sends the specified message to a window orwindows. It calls the window procedure for the specified window anddoes not return until the window procedure has processed themessage.
发送消息给窗口,并调用指定窗口的窗口过程,到窗口过程处理该消息才返回。  
To send a message and return immediately, use theSendMessageCallback or SendNotifyMessage function. To post amessage to a thread's message queue and return immediately, use thePostMessage or PostThreadMessage function.


Syntax

LRESULT SendMessage( HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
Parameters

hWnd
[in] Handle to the window whose window procedure will receive themessage. If this parameter is HWND_BROADCAST, the message is sentto all top-level windows in the system, including disabled orinvisible unowned windows, overlapped windows, and pop-up windows;but the message is not sent to child windows.
Msg
[in] Specifies the message to be sent.
wParam
[in] Specifies additional message-specific information.
lParam
[in] Specifies additional message-specific information.
Return Value

The return value specifies the result of the message processing; itdepends on the message sent.


Remarks

Applications that need to communicate using HWND_BROADCAST shoulduse the RegisterWindowMessage function to obtain a unique messagefor inter-application communication.

The system only does marshalling for system messages (those in therange 0 to WM_USER). To send other messages (those above WM_USER)to another process, you must do custom marshalling.

If the specified window was created by the calling thread, thewindow procedure is called immediately as a subroutine. If thespecified window was created by a different thread, the systemswitches to that thread and calls the appropriate window procedure.Messages sent between threads are processed only when the receivingthread executes message retrieval code. The sending thread isblocked until the receiving thread processes the message. However,the sending thread will process incoming nonqueued messages whilewaiting for its message to be processed. To prevent this, useSendMessageTimeout with SMTO_BLOCK set. For more information onnonqueued messages, see Nonqueued Messages.
==============
一个发送消息的子程序,将消息发送到打开的记事本窗口中。
szdestclass db 'notepad',0
_sndtontoepad proc _lpsz
local @hwinntoepad
pushad

invoke findwindow,addrszdestclass,null;找到指定应用程序即WINDOWS的记事本程序的句柄
===================
;关于findwindow

msdn
The FindWindow function retrieves a handle to the top-level windowwhose class name and window name match the specified strings. Thisfunction does not search child windows. This function does notperform a case-sensitive search.
获得顶层窗口的句柄,不查找子窗口,查找时不分大小写

To search child windows, beginning with a specified child window,use the FindWindowEx function.


Syntax

HWND FindWindow(
  LPCTSTR lpClassName,;窗口类名
LPCTSTR lpWindowName;窗口标题名称
);
Parameters

lpClassName窗口类名
[in] Pointer to a null-terminated string that specifies the classname or a class atom created by a previous call to theRegisterClass or RegisterClassEx function. The atom must be in thelow-order word of lpClassName; the high-order word must bezero.
If lpClassName points to a string, it specifies the window classname. The class name can be any name registered with RegisterClassor RegisterClassEx, or any of the predefined control-classnames.

If lpClassName is NULL, it finds any window whose title matches thelpWindowName parameter. 如果窗口类名为NULL,则按标题名称查找

lpWindowName窗口标题名称 
[in] Pointer to a null-terminated string that specifies the windowname (the window's title). If this parameter is NULL, all windownames match.
Return Value

If the function succeeds, the return value is a handle to thewindow that has the specified class name and window name.

If the function fails, the return value is NULL. To get extendederror information, call GetLastError.




Remarks

If the lpWindowName parameter is not NULL, FindWindow calls theGetWindowText function to retrieve the window name for comparison.For a description of a potential problem that can arise, see theRemarks for GetWindowText.
举例:☆☆☆☆☆☆☆☆☆
To check if the Microsoft IntelliType version 1.x software isrunning, call FindWindow as follows:

FindWindow("MSITPro::EventQueue",NULL);
To check if the IntelliType version 2.0 software is running, callFindWindow as follows:

FindWindow("Type32_Main_Window", NULL);
If the IntelliType software is running, it sends WM_APPCOMMANDmessages to the application. Otherwise the application must installa hook to receive WM_APPCOMMAND messages.
☆☆☆☆☆☆☆☆☆☆
Microsoft Windows 95 or later: FindWindowW is supported by theMicrosoft Layer for Unicode (MSLU). To use this, you must addcertain files to your application, as outlined in Microsoft Layerfor Unicode on Windows 95/98/Me Systems.

===========
.if eax
mov ecx,eax

  invokechildwindowfrompoint,ecx,20,20
.endif

;☆☆☆☆☆☆关于childwindowfrompoint
ChildWindowFromPoint Function

--------------------------------------------------------------------------------


The ChildWindowFromPoint function determines which, if any, of thechild windows belonging to a parent window contains the specifiedpoint. The search is restricted to immediate child windows,grandchildren, and deeper descendant windows are notsearched.
获取处在父窗口指定位置的子窗口的句柄。

Syntax

HWND ChildWindowFromPoint( HWND hWndParent,
POINT Point
);
Parameters

hWndParent
[in] Handle to the parent window.
Point
[in] Specifies a POINT structure that defines the clientcoordinates (relative to hWndParent of the point to bechecked.
Return Value

The return value is a handle to the child window that contains thepoint, even if the child window is hidden or disabled. If the pointlies outside the parent window, the return value is NULL. If thepoint is within the parent window but not within any child window,the return value is a handle to the parent window.
;☆☆☆☆☆☆☆
.if eax ;获得了子窗口即编辑窗口的指针
mov @hwinnotepad,eax
mov esi,_lpsz
@@:
loadsb;将数据送向累加器,数据在ds:esi中,而movs中,目的地址为es:dsi
or al,al
jz @F ;如果结束符号是0,则表示字符串结束退出循环
movzx eax,al
invoke postmessage,@hwinnotepad,WM_CHAR,eax,1
jmp @B
@@:
.endif
popad
ret
_setndtonotepad endp
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值