Perform,SendMessage,PostMessage

Perform():
     VCL的Perform()方法适用于所有的TControl派生对象。Perform()可以向任何一个窗件或控件发送消息,只需要知道窗体或控件的实例。Perform()需要传递3个参数:消息标识符,wParam和lParam。

要给一个窗件或控件发送一个消息,可以参照下面的代码:
RetVal = ControlName->Perform(MessagID, wParam,lParam);

SendMessage()和PostMessage()
     有的时候, 可能需要向一个窗口发送一个消息,而又不知道这个窗口的实例。例如:可能要给一个非C++ Builder的窗口发送一个消息,而只有这个窗口的句柄。幸运的是,Windows有两个API函数可以实现这一点:SendMessage()和PostMessage().这两个函数几乎是一样的,它们的区别是: 
SendMessage()直接把一个消息发给窗口过程,等消息被处理后才返回。Postmessage()只是把消息发送到消息队列,完成后即返回。

SendMessage()和PostMessage()是Windows API函数,这样声明的:
SendMessage(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam):Integer;
PostMessage(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam):LongBool;

hWnd        是接收消息的窗口的句柄
Msg         是消息标识符
wParam      是32位的特定附加信息。
lParam      是32位特定附加信息

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The PostMessage function is a Windows API function that sends a message to the specified window or thread's message queue, without waiting for the recipient to process the message. This function is often used to send a message to a window to request that it perform a specific action or update its state. A hook is a mechanism that allows an application to intercept and handle events or messages before they are processed by the target window or thread. A hook function can be installed to intercept PostMessage calls before they are sent to the target window or thread. To install a hook for PostMessage, you can use the SetWindowsHookEx function with the WH_CALLWNDPROC hook type. This hook type allows you to intercept messages before they are processed by the target window's message queue. In the hook function, you can inspect the message and perform any necessary actions before passing it on to the target window. Here is an example of a hook function for PostMessage: ``` LRESULT CALLBACK PostMessageHook(int nCode, WPARAM wParam, LPARAM lParam) { if (nCode == HC_ACTION) { CWPSTRUCT* pMsg = (CWPSTRUCT*)lParam; if (pMsg->message == WM_MY_CUSTOM_MESSAGE) { // Handle custom message here return 0; } } return CallNextHookEx(NULL, nCode, wParam, lParam); } ``` In this example, the hook function intercepts messages with the custom message code WM_MY_CUSTOM_MESSAGE and handles them before passing them on to the target window. Note that the hook function must be installed using the SetWindowsHookEx function and must be removed using the UnhookWindowsHookEx function when it is no longer needed.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值