全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:890
推到 Plurk!
推到 Facebook!

請問點擊一個在Formg上的Button, 訊息會先經過TForm::WndProc嗎

尚未結案
donald_chen
一般會員


發表:9
回覆:2
積分:2
註冊:2004-04-22

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-01-10 11:50:14 IP:163.28.xxx.xxx 未訂閱
請問點擊一個在Formg上的Button, 訊息會先經過TForm::WndProc嗎? 還是直接進入TButton::WndProc呢?
m8815010
版主


發表:99
回覆:372
積分:289
註冊:2003-11-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-01-10 18:12:28 IP:61.63.xxx.xxx 未訂閱
引言: 請問點擊一個在Formg上的Button, 訊息會先經過TForm::WndProc嗎? 還是直接進入TButton::WndProc呢?
donald_chen你好< >: 試試看就知了< >:
In .h    ~~    class TForm1 : public TForm
{
__published:        // IDE-managed Components
        TButton *Button1;
        TApplicationEvents *ApplicationEvents1;
        TMemo *Memo1;
        void __fastcall ApplicationEvents1Message(tagMSG &Msg, //Application的messag event
          bool &Handled);
private:        // User declarations
        TWndMethod OldButtonWndProc;                           //Button1的WndProc
        void __fastcall ButtonWndProc(TMessage& Message);
        TWndMethod OldFormWndProc;                             //Form的WndProc
        void __fastcall FormWndProc(TMessage& Message);
public:                // User declarations
        __fastcall TForm1(TComponent* Owner);
};    ~~        In.cpp    ~~    TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
 OldButtonWndProc=Button1->WindowProc;
 Button1->WindowProc=ButtonWndProc;     OldFormWndProc=this->WindowProc;
 this->WindowProc=FormWndProc;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ApplicationEvents1Message(tagMSG &Msg,
      bool &Handled)
{
 if (Msg.message==WM_LBUTTONDOWN)
     Memo1->Lines->Add("Get message---[1]");              //當application收到訊息
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ButtonWndProc(TMessage& Message)
{
 OldButtonWndProc(Message);     if (Message.Msg==WM_LBUTTONUP)                           //當Buuton1收到訊息
     Memo1->Lines->Add("Get message---[2]");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormWndProc(TMessage& Message)
{
 OldFormWndProc(Message);     if (Message.Msg==WM_PARENTNOTIFY) {                      
     if (LOWORD(Message.WParam)==WM_LBUTTONDOWN) {
         int Coor_Y=HIWORD(Message.LParam);
         int Coor_X=LOWORD(Message.LParam);
         POINT point;
         point.x=Coor_X;
         point.y=Coor_Y;             TRect rect=Button1->ClientRect;
         rect.top =Button1->Top;
         rect.bottom =Button1->Top;
         rect.left =Button1->Left;
         rect.right =Button1->Left;             if (PtInRect(rect,point))
             Memo1->Lines->Add("Get message---[3]");      //當Form收到訊息
     }
 }
}    ~~    
發表人 - m8815010 於 2005/01/10 19:14:47
系統時間:2024-05-05 0:29:24
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!