2008. december 16., kedd

Responding to Windows Messages


Problem/Question/Abstract:

It shows how to act on response to windows messages. Further information can be foun in the Online Help seeking  "message handling"

Answer:

It is as easy as writing a method that complies with

Getting a TMessage Parameter or a specific Message Parameter (such as TWMMouse that makes it easier to get the message's parameters)
Putting the reserved word message followed by the windows message to which you want to react (such as WM_MOUSEMOVE)

Then write your method and VOILA!

Here is the code:

unit messageUnit;

interface

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

type
  TForm1 = class(TForm)
  private
    procedure CatchMouseMove(var winMessage: TWMMouse); message wm_mousemove;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

procedure TForm1.CatchMouseMove(var winMessage: TWMMouse);
{*
WM_MOUSEMOVE
fwKeys = wParam;        // key flags
xPos = LOWORD(lParam);  // horizontal position of cursor
yPos = HIWORD(lParam);  // vertical position of cursor
*}

begin
  self.Color := TColor(winmessage.XPos)
end;

{$R *.DFM}

end.

Nincsenek megjegyzések:

Megjegyzés küldése