学习 Message(18): WM_SYSCOMMAND 消息[二] : LParam 参数


WM_SYSCOMMAND 消息的 LParam 参数是鼠标位置, 低位是 X, 高位是 Y.

下面三段程序是一样的只是使用不同类型的消息参数, 用 TWMSysCommand 更方便, 用 TMessage 更正统.
程序一:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
  protected
    procedure WMSysCommand(var Message: TWMSysCommand); message WM_SYSCOMMAND;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WMSysCommand(var Message: TWMSysCommand);
begin
  Text := Format('%d,%d', [Message.XPos, Message.YPos]);
  inherited;
end;

end.

 
 
 
 
 

 

 
  

程序二:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
  protected
    procedure WMSysCommand(var Message: TMessage); message WM_SYSCOMMAND;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WMSysCommand(var Message: TMessage);
begin
  Text := Format('%d,%d', [LoWord(Message.LParam), HiWord(Message.LParam)]);
  inherited;
end;

end.

 
 
 
 
 

 

 
  

程序三:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
  protected
    procedure WMSysCommand(var Message: TMessage); message WM_SYSCOMMAND;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WMSysCommand(var Message: TMessage);
begin
  Text := Format('%d,%d', [Message.LParamLo, Message.LParamHi]);
  inherited;
end;

end.

 
 
 
 
 

 

 
  

你可能感兴趣的:(学习 Message(18): WM_SYSCOMMAND 消息[二] : LParam 参数)