如何取消系统消息队列中的某一条消息的执行?

auto 2000-01-28 05:40:00
...全文
329 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
929 2000-01-28
  • 打赏
  • 举报
回复
在消息队列中取消某一消息的执行。应算是消息的过滤。在WINDOWS中消息过滤可用GETMESSAGE和PEEKMESSGE来实现。但二者略有不同,GETMESSGE直到取到消息才返回,而PEEKMESSAGE则不管取到与否都立即返回。下面事例摘自WIN32帮助。

HWND hwnd;
BOOL fDone;
MSG msg;

// Begin the operation and continue until it is complete
// or until the user clicks the mouse or presses a key.

fDone = FALSE;
while (!fDone)
{
fDone = DoLengthyOperation(); // application-defined function

// Remove any messages that may be in the queue. If the
// queue contains any mouse or keyboard
// messages, end the operation.

while (PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE))
{

switch(msg.message)
{
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_KEYDOWN:
//
// Perform any required cleanup.
//
fDone = TRUE;
}
}
}
在DELPHI中要实现消息过滤可用APPLICATION的ONMESSAGE事件来完成,ONMESSAGE处理进入消息队列中消息,若有消息不想执行,可过滤之。DELPHI帮助中事例如下:

The following code handles a custom message that the application sends to itself when a file is ready for reading.

const
WM_FILEREADY = WM_USER + 2000;
procedure TForm1.FormCreate(Sender: TObject);

begin
Application.OnMessage := AppMessage;
end;

procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
if Msg.message = WM_FILEREADY then
begin
Memo1.Lines.LoadFromFile(StrPas(PChar(Msg.lParam)));
Handled := True;

end;

{ for all other messages, Handled remains False }
{ so that other message handlers can respond }
end;
olo 2000-01-28
  • 打赏
  • 举报
回复
sorry.ReplayMessage是回应SendMessage的。
PeekMessage 加 PM_REMOVE不知行不行。
olo 2000-01-28
  • 打赏
  • 举报
回复
ReplyMessage?

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧