Delphisand
asked on
information from the desktop to a Delphi app
When I switch from my application (MyApp) to another application (App), I can see, that my application still is receiving some inputs. For example I can detect when the cursor moves over MyApp even if MyApp is not the active/focused one. I can receive the input in OnMouseEnter.
Is it possible for MyApp to receive information of the movement of App, if App is dragged across the window of MyApp??
Is it possible for MyApp to receive information of the movement of App, if App is dragged across the window of MyApp??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is better sample without using timer, you need TApplicationEvents component to use OnMessage even
this is full unit
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, AppEvnts;
type
TForm1 = class(TForm)
ApplicationEvents1: TApplicationEvents;
procedure ApplicationEvents1Message( var Msg: tagMSG; var Handled: Boolean);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
FHookStarted : Boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
JHook: THandle;
implementation
{$R *.dfm}
function JournalProc(Code, wParam: Integer; var EventStrut: TEventMsg): Integer; stdcall;
var
Char1: PChar;
s: string;
begin
{this is the JournalRecordProc}
Result := CallNextHookEx(JHook, Code, wParam, Longint(@EventStrut));
{the CallNextHookEX is not really needed for journal hook since it it not
really in a hook chain, but it's standard for a Hook}
if Code < 0 then Exit;
{you should cancel operation if you get HC_SYSMODALON}
if Code = HC_SYSMODALON then Exit;
if Code = HC_ACTION then
begin
if (EventStrut.message = WM_MOUSEMOVE) then
form1.Caption := IntToStr(EventStrut.paramL ) + ' / ' + IntToStr(EventStrut.paramH );
end;
end;
procedure TForm1.ApplicationEvents1M essage(var Msg: tagMSG;
var Handled: Boolean);
begin
{the journal hook is automaticly camceled if the Task manager
(Ctrl-Alt-Del) or the Ctrl-Esc keys are pressed, you restart it
when the WM_CANCELJOURNAL is sent to the parent window, Application}
Handled := False;
if (Msg.message = WM_CANCELJOURNAL) and FHookStarted then
JHook := SetWindowsHookEx(WH_JOURNA LRECORD, @JournalProc, 0, 0);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
{make sure you unhook it if the app closes}
if FHookStarted then
UnhookWindowsHookEx(JHook) ;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
JHook := SetWindowsHookEx(WH_JOURNA LRECORD, @JournalProc, hInstance, 0);
{SetWindowsHookEx starts the Hook}
if JHook > 0 then
begin
FHookStarted := True;
end
else
ShowMessage('No Journal Hook availible');
end;
end.
And this is dfm code
object Form1: TForm1
Left = 192
Top = 114
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnClose = FormClose
PixelsPerInch = 96
TextHeight = 13
object Button_StartJour: TButton
Left = 112
Top = 80
Width = 147
Height = 25
Caption = 'Button_StartJour'
TabOrder = 0
OnClick = Button_StartJourClick
end
object ListBox1: TListBox
Left = 311
Top = 0
Width = 377
Height = 446
Align = alRight
ItemHeight = 13
TabOrder = 1
end
object Button_StopJour: TButton
Left = 112
Top = 120
Width = 145
Height = 25
Caption = 'Button_StopJour'
TabOrder = 2
OnClick = Button_StopJourClick
end
object ApplicationEvents1: TApplicationEvents
OnMessage = ApplicationEvents1Message
Left = 208
Top = 8
end
end
this is full unit
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, AppEvnts;
type
TForm1 = class(TForm)
ApplicationEvents1: TApplicationEvents;
procedure ApplicationEvents1Message(
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
FHookStarted : Boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
JHook: THandle;
implementation
{$R *.dfm}
function JournalProc(Code, wParam: Integer; var EventStrut: TEventMsg): Integer; stdcall;
var
Char1: PChar;
s: string;
begin
{this is the JournalRecordProc}
Result := CallNextHookEx(JHook, Code, wParam, Longint(@EventStrut));
{the CallNextHookEX is not really needed for journal hook since it it not
really in a hook chain, but it's standard for a Hook}
if Code < 0 then Exit;
{you should cancel operation if you get HC_SYSMODALON}
if Code = HC_SYSMODALON then Exit;
if Code = HC_ACTION then
begin
if (EventStrut.message = WM_MOUSEMOVE) then
form1.Caption := IntToStr(EventStrut.paramL
end;
end;
procedure TForm1.ApplicationEvents1M
var Handled: Boolean);
begin
{the journal hook is automaticly camceled if the Task manager
(Ctrl-Alt-Del) or the Ctrl-Esc keys are pressed, you restart it
when the WM_CANCELJOURNAL is sent to the parent window, Application}
Handled := False;
if (Msg.message = WM_CANCELJOURNAL) and FHookStarted then
JHook := SetWindowsHookEx(WH_JOURNA
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
{make sure you unhook it if the app closes}
if FHookStarted then
UnhookWindowsHookEx(JHook)
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
JHook := SetWindowsHookEx(WH_JOURNA
{SetWindowsHookEx starts the Hook}
if JHook > 0 then
begin
FHookStarted := True;
end
else
ShowMessage('No Journal Hook availible');
end;
end.
And this is dfm code
object Form1: TForm1
Left = 192
Top = 114
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnClose = FormClose
PixelsPerInch = 96
TextHeight = 13
object Button_StartJour: TButton
Left = 112
Top = 80
Width = 147
Height = 25
Caption = 'Button_StartJour'
TabOrder = 0
OnClick = Button_StartJourClick
end
object ListBox1: TListBox
Left = 311
Top = 0
Width = 377
Height = 446
Align = alRight
ItemHeight = 13
TabOrder = 1
end
object Button_StopJour: TButton
Left = 112
Top = 120
Width = 145
Height = 25
Caption = 'Button_StopJour'
TabOrder = 2
OnClick = Button_StopJourClick
end
object ApplicationEvents1: TApplicationEvents
OnMessage = ApplicationEvents1Message
Left = 208
Top = 8
end
end
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Now I understand, that what I really is asking about is the structure and procedures that delphi uses to communicate with windows xp and vice versa. i.e. that these answers can bring me further on in my search.
Thanks!
Thanks!
procedure TForm1.Timer1Timer(Sender:
var Point : TPoint;
begin
GetCursorPos(Point);
Caption := IntToStr(Point.X )+'/' +inttostr(Point.Y );
end;