?
Solved

Detecting mouse event everywhere

Posted on 2006-06-15
4
Medium Priority
?
348 Views
Last Modified: 2010-04-05
How can I detect mouse event everywhere on the form, that contains listboxes, labels, panels... For example, i start OnMouseMove event on ListBox with left button pressed and I drag mouse outside of the ListBox and then I want released left button to be detected. Simply said, how to do it, that whole application monitors mouse events?
0
Comment
Question by:JackKuti
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16915734
Normally you'd have to use a windows hook (SetWindowsHookEx() API.) and put your code in a .DLL, but there is a trick using JOURNAL
http://www.delphitricks.com/source-code/windows/trap_mouse_events_outside_of_my_application.html
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16915752
oops, didn't read your question correctly. This is probably more than you needed
0
 
LVL 7

Expert Comment

by:kfoster11
ID: 16915968
Look at the Forms property TForm.WantEvents.  This should send all of the events from the child control to your form.  
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 500 total points
ID: 16916095
hmm, i'm not familiar with the WantEvents
here's another way of doing it though

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
{ these events are hooked up to the form's mousemove, mouseup, and mousedown}
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

{ these events are hooked up to _every_ wincontrol you are interested in keeping track of
  simply set each wincontrol's "OnMouseMove,OnMOuseUp, and OnMouseDown" events to point to these 3}
    procedure ControlAdjustment_MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure ControlAdjustment_MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure ControlAdjustment_MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
{  these events are the actual MouseMove, MouseUp, and MouseDown including the controls you are over.
   these events are the ones you should use (e.g. if you wish to move controls around etc) }
    procedure WholeForm_MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure WholeForm_MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure WholeForm_MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  public
    { Public declarations }
  end;


var
  Form1: TForm1;

implementation

{$R *.dfm}

// these events are hooked up to the form's mousemove, mouseup, and mousedown
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    begin
        WholeForm_MouseMove(Sender, Shift, X, Y);
    end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
        WholeForm_MouseDown(Sender, Button, Shift, X, Y);
    end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
        WholeForm_MouseUp(Sender, Button, Shift, X, Y);
    end;

{ these events are hooked up to _every_ wincontrol you are interested in keeping track of
  simply set each wincontrol's "OnMouseMove,OnMOuseUp, and OnMouseDown" events to point to these 3}
procedure TForm1.ControlAdjustment_MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    begin
        WholeForm_MouseMove(Sender, Shift, (Sender as TWinControl).Left + X, (Sender as TWinControl).Top + Y);
    end;

procedure TForm1.ControlAdjustment_MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
        WholeForm_MouseDown(Sender, Button, Shift, (Sender as TWinControl).Left + X, (Sender as TWinControl).Top + Y);
    end;

procedure TForm1.ControlAdjustment_MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
        WholeForm_MouseUp(Sender, Button, Shift, (Sender as TWinControl).Left + X, (Sender as TWinControl).Top + Y);
    end;

{  these events are the actual MouseMove, MouseUp, and MouseDown including the TWincontrols you are over.
   these events are the ones you should use (e.g. if you wish to move controls around etc) }
procedure TForm1.WholeForm_MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    begin
        caption := format('x = %d, y = %d', [x,y]);
        listbox1.items.add(format('x = %d, y = %d', [x,y]));
    end;

procedure TForm1.WholeForm_MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
        caption := format('x = %d, y = %d, mouse down', [x,y]);
        listbox1.items.add(format('x = %d, y = %d, mouse down', [x,y]));
    end;

procedure TForm1.WholeForm_MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
        caption := format('x = %d, y = %d, mouse up', [x,y]);
        listbox1.items.add(format('x = %d, y = %d, mouse up', [x,y]));
    end;

end.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month11 days, 19 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question