• 建立空窗口时,窗口函数受到的消息(三种拦截记录消息的方法)


    新窗体上放一个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中的使用示例
    设计模式装饰者模式在Java中的使用示例
    git 恢复误删的远程分支
    从基础到实战 手把手带你掌握新版Webpack4.0
    掘金小册 – Taro 多端开发实现原理与项目实战
    react+tsx中使用betterscroll
    Taro3最新版本开发企业级出行全栈项目
    babelpolyfill的几种使用方式
    Vue3 + React18 + TS4 入门到实战
    typescript学习
  • 原文地址:https://www.cnblogs.com/findumars/p/5221795.html
Copyright © 2020-2023  润新知