sorry.ReplayMessage是回应SendMessage的。
PeekMessage 加 PM_REMOVE不知行不行。

解决方案 »

  1.   

    在消息队列中取消某一消息的执行。应算是消息的过滤。在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;