(delphi)Perform,SendMessage,PostMessage三者區別

(delphi)Perform,SendMessage,PostMessage三者區別

Perform():
     VCL的Perform()方法適用於所有的TControl派生對象。 Perform()可以向任何一個窗件或控件發送消息,只需要知道窗體或控件的實例。 Perform()需要傳遞3個參數:消息標識符,wParam和lParam。
要給一個窗件或控件發送一個消息,可以參照下面的代碼:
RetVal = ControlName->Perform(MessagID, (NativeInt)wParam,(NativeInt)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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值