zoukankan      html  css  js  c++  java
  • c++builder 重载WindowProc、WndProc 截获消息(比Delphi多一个Message Map方法)

    c++builder 重载WindowProc、WndProc 截获消息 

    方法一WindowProc

    void __fastcall  myWindowProc(Messages::TMessage &msg); //增加
    Classes::TWndMethod OldWindowProc;  //增加

    void __fastcall  TForm1::myWindowProc(Messages::TMessage &msg)
     {
       if (msg.Msg == WM_MOUSEWHEEL)
       {
         //::MessageBox(NULL,"OK","Message",0);  //测试
         Caption = Now();
       }

       else
         OldWindowProc(Message);
     }

    void __fastcall TForm1::FormCreate(TObject *Sender)
    {

      OldWindowProc=Edit1->WindowProc;
      Edit1->WindowProc=myWindowProc;        
    }

    方法二 MESSAGE_MAP

    class TForm1 : public TForm
    {
    __published: // IDE-managed Components
            TEdit *Edit1;
    private: // User declarations
    void __fastcall OnEditMouseWell(TMessage &msg);
    BEGIN_MESSAGE_MAP 

    MESSAGE_HANDLER(WM_MOUSEWHEEL, TMessage, OnEditMouseWell)

    END_MESSAGE_MAP(TForm)  //TForm 换成TEdit 

    public:  // User declarations
            __fastcall TForm1(TComponent* Owner);
    };

     void __fastcall TForm1::OnEditMouseWell(TMessage &msg)
     {
       if(String(ActiveControl->ClassName())=="TEdit")  //所有的Edit
          Caption   = Now(); //测试


    //TForm::Dispatch(&Msg); 

    }

    方法三 重载 WndProc

    private: // User declarations
         void __fastcall WndProc(Messages::TMessage &msg);

    void __fastcall TForm1::WndProc(Messages::TMessage &msg)
    {
      if (msgMsg == WM_MOUSEWHEEL && msg.WParam )
        {
          Caption = Now();
        }
        TForm::WndProc(msg);
    }

    四、ApplicationEvents控件

     窗体上放置ApplicationEvents1控件,在ApplicationEvents1Message事件里判断。

    void __fastcall TForm3::ApplicationEvents1Message(tagMSG &Msg, bool &Handled)
    {
        if (Msg.hwnd == this->DBGrid1->Handle && Msg.message == WM_MOUSEWHEEL)
            this->Caption = Now();
    }

    http://www.cnblogs.com/cb168/p/4705059.html

  • 相关阅读:
    安卓基础干货(六):安卓Activity的学习
    安卓基础干货(四):安卓网络编程的学习
    安卓基础干货(三):安卓数据库的学习
    安卓基础干货(二):安卓测试以及解析
    Broadcast 源码笔记
    使用smb 将vm Ubuntu磁盘 挂载到windwos
    libbinder -- BinderService
    Android属性系统
    AndroidO -- 背光手动调节流程
    Typora+PicGo-Core+gitee实现上传服务
  • 原文地址:https://www.cnblogs.com/findumars/p/5597286.html
Copyright © 2011-2022 走看看