zoukankan      html  css  js  c++  java
  • 建立空窗口时,窗口函数受到的消息(三种拦截记录消息的方法)

    新窗体上放一个Button1和Panel1,仅仅Form1就会收到以下消息:

    procedure TWinControl.DefaultHandler(var Message);
    begin
      if FHandle <> 0 then
      begin
        with TMessage(Message) do
        begin
          if (Msg = WM_CONTEXTMENU) and (Parent <> nil) then
          begin
            Result := Parent.Perform(Msg, WParam, LParam);
            if Result <> 0 then Exit;
          end;
          case Msg of
            WM_CTLCOLORMSGBOX..WM_CTLCOLORSTATIC:
              Result := SendMessage(LParam, CN_BASE + Msg, WParam, LParam);
            CN_CTLCOLORMSGBOX..CN_CTLCOLORSTATIC:
              begin
                SetTextColor(WParam, ColorToRGB(FFont.Color));
                SetBkColor(WParam, ColorToRGB(FBrush.Color));
                Result := FBrush.Handle;
              end;
          else
            if Msg = RM_GetObjectInstance then
              Result := Integer(Self)
            else
            begin
              if Msg <> WM_PAINT then // 在这里下断点,竟然收到36 129 70 131 71 3 5 127 1 124 125 48 128 24 一大串消息
              Result := CallWindowProc(FDefWndProc, FHandle, Msg, WParam, LParam);
            end;
          end;
          if Msg = WM_SETTEXT then
            SendDockNotification(Msg, WParam, LParam);
        end;
      end
      else
        inherited DefaultHandler(Message);
    end;

    需要逐一研究。。。

    procedure TWinControl.DefaultHandler(var Message);
    begin
      if FHandle <> 0 then
      begin
        with TMessage(Message) do
        begin
          if (Msg = WM_CONTEXTMENU) and (Parent <> nil) then
          begin
            Result := Parent.Perform(Msg, WParam, LParam);
            if Result <> 0 then Exit;
          end;
          case Msg of
            WM_CTLCOLORMSGBOX..WM_CTLCOLORSTATIC:
              Result := SendMessage(LParam, CN_BASE + Msg, WParam, LParam);
            CN_CTLCOLORMSGBOX..CN_CTLCOLORSTATIC:
              begin
                SetTextColor(WParam, ColorToRGB(FFont.Color));
                SetBkColor(WParam, ColorToRGB(FBrush.Color));
                Result := FBrush.Handle;
              end;
          else
            if Msg = RM_GetObjectInstance then
              Result := Integer(Self)
            else
            begin
              if self.Name='Panel1' then
              begin
                tag:=100; // 这里下断点
              end;
              if Msg <> WM_PAINT then
              Result := CallWindowProc(FDefWndProc, FHandle, Msg, WParam, LParam);
            end;
          end;
          if Msg = WM_SETTEXT then
            SendDockNotification(Msg, WParam, LParam);
        end;
      end
      else
        inherited DefaultHandler(Message);
    end;

    这样观察,可以得到Panel1收到的所有默认消息,而且都是平时没有注意到的消息。同时还可在DispatchMessage那里记录消息,那样更加一网打尽。还可在WndProc里记录消息,反正所有消息都有首先经过这里。

    另外两种不常用:使用TAppEvent和HookMessage

  • 相关阅读:
    java 单元测试 No tests were found 和 org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests
    Cesium 各种坐标转换
    windows express + https ssl 证书申请
    layui数据表格跨行自动合并
    mui中的遍历each()
    点击按钮,回到页面顶部的5种写法
    html中a标签中实现点击事件
    @-webkit-keyframes 动画 css3
    在手机上调试H5页面
    SQL Server 按某一字段分组取最大(小)值所在行的数据
  • 原文地址:https://www.cnblogs.com/findumars/p/5221795.html
Copyright © 2011-2022 走看看