zoukankan      html  css  js  c++  java
  • 消息处理方法1:onMessage

    《Delphi精要》P134页中提到消息处理有8个方法,现在对上面的方法,做一个实验。
    第1是onmessage方法:application中的onmessage方法可以处理属于application的除WM_QUIT以外的所有消息。但该方法用于处理个别方法时,效率会很低,因为需要对WINDOWS中的众多的消息中筛选其中之一。
    下面还比较了sendMessage与PostMessage两个方法的区别:SendMessage发送的消息进入了窗体而没有进入消息队列的(这一点还要深究)。Application无法识别没有进入消息队列的消息的。所以OnMessage不能截获该消息。

    从图中可以看到SendMessage是没有响应的。

        procedure AppMsg(var msg:Tmsg;var handled:Boolean);
        
    procedure FormCreate(Sender: TObject);
        
    procedure Button1Click(Sender: TObject);
        
    procedure Button2Click(Sender: TObject);


    procedure TForm1.AppMsg(var msg: Tmsg; var handled: Boolean);
    begin
      
    if msg.message=WM_KEYDOWN then
         
    begin
          Form1.Caption:
    ='PostMessage:Key Down';
          handled:
    =true;
         
    end;
    end;

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Application.OnMessage:
    =AppMsg;//由AppMsg"接管"(这个词不准确,有待再深究)
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    begin
       PostMessage(Form1.Handle,WM_KEYDOWN,
    0,0);
    end;

    procedure TForm1.Button2Click(Sender: TObject);
    begin
       SendMessage(Form1.Handle,WM_KEYDOWN,
    0,0);
    end;
  • 相关阅读:
    bzoj 4012: [HNOI2015]开店
    POJ 1054 The Troublesome Frog
    POJ 3171 Cleaning Shifts
    POJ 3411 Paid Roads
    POJ 3045 Cow Acrobats
    POJ 1742 Coins
    POJ 3181 Dollar Dayz
    POJ 3040 Allowance
    POJ 3666 Making the Grade
    洛谷 P3657 [USACO17FEB]Why Did the Cow Cross the Road II P
  • 原文地址:https://www.cnblogs.com/samsonleung/p/1235849.html
Copyright © 2011-2022 走看看