请问下面这段代码是什么意思?
procedure TXXSpeedButton.MouseDown(Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);....
        if PeekMessage(Msg, 0, 0, 0, PM_NOREMOVE) then
        begin
          if (Msg.Message = WM_LBUTTONDOWN) or (Msg.Message = WM_LBUTTONDBLCLK) then
          begin
            P := ScreenToClient(Msg.Pt);
            if (P.X >= 0) and (P.X < ClientWidth) and (P.Y >= 0) and (P.Y <= ClientHeight) then
              KillMessage(Windows.HWND_DESKTOP, Msg.Message);
          end;
        end;
.....

解决方案 »

  1.   

    抱歉,忘了KillMessage的定义,KillMessage是这样定义的:
    procedure KillMessage(Wnd: THandle; Msg: Cardinal);
    var
      M: TMsg;
    begin
      M.Message := 0;
      if PeekMessage(M, Wnd, Msg, Msg, PM_REMOVE) and (M.Message = WM_QUIT) then
        PostQuitMessage(M.WParam);
    end;
      

  2.   

    这段代码又是什么意思?和上面有什么区别?
    procedure TXXSpeedButton.MouseDown(Button: TMouseButton; 
      Shift: TShiftState; X, Y: Integer); .... 
        while PeekMessage(Msg, HWND_DESKTOP, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE) do
          {nothing};
        if GetCapture <> 0 then
          SendMessage(GetCapture, WM_CANCELMODE, 0, 0);
    .....
      

  3.   

    看Windows API文档呀!PeekMessage 是从消息队列中取消息,PM_REMOVE参数是指将消息从队列中移除。而自编的KillMessage是将所有消息从队列中取掉(不处理),而如果碰见了退出程序的消息则重新投递它(导致程序退出)。
      

  4.   

     if PeekMessage(Msg, 0, 0, 0, PM_NOREMOVE) then //PM_NOREMOVE 只从队列中取出消息
            begin
              if (Msg.Message = WM_LBUTTONDOWN) or (Msg.Message = WM_LBUTTONDBLCLK) then // 判断是左键按下 或者 左键双击
              begin
                P := ScreenToClient(Msg.Pt); // 
                if (P.X  >= 0) and (P.X  < ClientWidth) and (P.Y  >= 0) and (P.Y  <= ClientHeight) then 在//ClientRect 范围内
                  KillMessage(Windows.HWND_DESKTOP, Msg.Message); 
              end;
            end; procedure KillMessage(Wnd: THandle; Msg: Cardinal);
    var
      M: TMsg;
    begin
      M.Message := 0;
      if PeekMessage(M, Wnd, Msg, Msg, PM_REMOVE) // 取出 WM_LBUTTONDOWN 或 WM_LBUTTONDBLCLK 消息
       and (M.Message = WM_QUIT) then // M.Message = WM_QUIT 一定为 false
        PostQuitMessage(M.WParam); // 根本不执行
    end;
    综上所述,KillMessage 啥也没干。
    procedure TXXSpeedButton.MouseDown(Button: TMouseButton; 
      Shift: TShiftState; X, Y: Integer); .... 
        while PeekMessage(Msg, HWND_DESKTOP, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE) do // 清除消息队列中   WM_MOUSEFIRST 到 WM_MOUSELAST 之间的消息, 也就是鼠标消息
          {nothing};
        if GetCapture  < > 0 then
          SendMessage(GetCapture, WM_CANCELMODE, 0, 0);
    .....