随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253


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.

posted on 2008-10-31 16:26  万一  阅读(...)  评论(...编辑  收藏