Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.12.19;
Скачать: CL | DM;

Вниз

Координаты мыши в "чужом" приложении.   Найти похожие ветки 

 
Nix   (2004-11-03 01:56) [0]

Необходимо из другого, активного, приложения по double click получать координаты мыши.
Пожалуйста, помогите разобраться.


 
++MASTER++ ©   (2004-11-03 13:15) [1]

Уважаемый Nix, ловите события мышки вне вашего приложения, например:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ApplicationEvents1: TApplicationEvents;
    Button_StartJour: TButton;
    Button_StopJour: TButton;
    ListBox1: TListBox;
    procedure ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    procedure Button_StartJourClick(Sender: TObject);
    procedure Button_StopJourClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    FHookStarted : Boolean;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

var
  JHook: THandle;

// WH_JOURNALPLAYBACK Hook Function

//Syntax

// JournalPlaybackProc
// nCode: Integer;  
// wParam: WPARAM;  
// lParam: LPARAM  
// ): LRESULT;  

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
    {
   The lParam parameter contains a pointer to a TEventMsg
   structure containing information on
   the message removed from the system message queue.
   }
    s := "";

    if EventStrut.message = WM_LBUTTONUP then
      s := "Left Mouse UP at X pos " +
        IntToStr(EventStrut.paramL) + " and Y pos " + IntToStr(EventStrut.paramH);

    if EventStrut.message = WM_LBUTTONDOWN then
      s := "Left Mouse Down at X pos " +
        IntToStr(EventStrut.paramL) + " and Y pos " + IntToStr(EventStrut.paramH);

    if EventStrut.message = WM_RBUTTONDOWN then
      s := "Right Mouse Down at X pos " +
        IntToStr(EventStrut.paramL) + " and Y pos " + IntToStr(EventStrut.paramH);

    if (EventStrut.message = WM_RBUTTONUP) then
      s := "Right Mouse Up at X pos " +
        IntToStr(EventStrut.paramL) + " and Y pos " + IntToStr(EventStrut.paramH);

    if (EventStrut.message = WM_MOUSEWHEEL) then
      s := "Mouse Wheel at X pos " +
        IntToStr(EventStrut.paramL) + " and Y pos " + IntToStr(EventStrut.paramH);

    if (EventStrut.message = WM_MOUSEMOVE) then
      s := "Mouse Position at X:" +
        IntToStr(EventStrut.paramL) + " and Y: " + IntToStr(EventStrut.paramH);

    if s <> "" then
       Form1.ListBox1.ItemIndex :=  Form1.ListBox1.Items.Add(s);
  end;
end;

procedure TForm1.Button_StartJourClick(Sender: TObject);
begin
  if FHookStarted then
  begin
    ShowMessage("Mouse is already being Journaled, can not restart");
    Exit;
  end;
  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;

procedure TForm1.Button_StopJourClick(Sender: TObject);
begin
  FHookStarted := False;
  UnhookWindowsHookEx(JHook);
  JHook := 0;
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;

end.



Страницы: 1 вся ветка

Текущий архив: 2004.12.19;
Скачать: CL | DM;

Наверх




Память: 0.46 MB
Время: 0.036 c
14-1101885880
raymond
2004-12-01 10:24
2004.12.19
Адвминистрирование компьютерного класса (ищу программу)...


1-1102019486
AlexHawk
2004-12-02 23:31
2004.12.19
Помогите с циклом...


1-1101900153
Larisa
2004-12-01 14:22
2004.12.19
Подскажите, пожалуйста, как динамически добавить


14-1101696360
Думкин
2004-11-29 05:46
2004.12.19
С днем рождения! 28 ноября


1-1101992869
Aleksandr.
2004-12-02 16:07
2004.12.19
У меня Делфи сломалась, или как?





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский