Avatar of Delphisand
Delphisand
Flag for Denmark 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??
Delphi

Avatar of undefined
Last Comment
Delphisand

8/22/2022 - Mon
Mahdi78

Add Timer with 100 interval and use this even


procedure TForm1.Timer1Timer(Sender: TObject);
var  Point : TPoint;
begin
GetCursorPos(Point);
Caption  := IntToStr(Point.X )+'/' +inttostr(Point.Y );
end;
ASKER CERTIFIED SOLUTION
Emmanuel PASQUIER

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Mahdi78

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.ApplicationEvents1Message(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_JOURNALRECORD, @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_JOURNALRECORD, @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
SOLUTION
Mahdi78

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Delphisand

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!
Your help has saved me hundreds of hours of internet surfing.
fblack61