Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
ow to Track the mouse position over a TPanel on a form Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
26-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
69
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I want to track the position of the mouse over a TPanel within the client area of 
my main form. Using WM_MOUSEMOVE, I can track the mouse position over the main form 
easily enough, but once the mouse moves over my panel, the tracking stops. What do 
I need to do to track the position of the mouse over the panel?

Answer:

This is happening because TPanel is a different window with a handle of its own. 
You need to intercept the WM_MOUSEMOVE message in the TPanels WindowProc procedure. 
Assuming the form is TForm1 and the panel is Panel1:

First declare the following in the forms class:

1   private
2   { Private declarations }
3   OldPanelWndProc: TWndMethod;
4   
5   procedure NewPanelWndProc(var message: TMessage);


Finally, implement the relevant code. Note how you should always call the old 
WindowProc procedure after you've handled the message. Also, WindowProc should be 
restored to it's original procedure when the form (containing the panel) is hidden. 
It would be a bad idea to restore the WindowProc procedure in the forms OnDestroy 
event because if it (the form) is hidden and shown again, it's going to cause 
problems with WindowProc being reassigned when it shouldn't be.

6   procedure TForm1.FormShow(Sender: TObject);
7   begin
8     OldPanelWndProc := Panel1.WindowProc;
9     Panel1.WindowProc := NewPanelWndProc;
10  end;
11  
12  procedure TForm1.FormHide(Sender: TObject);
13  begin
14    Panel1.WindowProc := OldPanelWndProc;
15  end;
16  
17  procedure TForm1.NewPanelWndProc(var message: TMessage);
18  begin
19    case message.Msg of
20      WM_MOUSEMOVE:
21        Caption := 'x = ' + inttostr(message.LParamLo) + ' y = ' +
22  			 inttostr(message.LParamHi);
23    end;
24    OldPanelWndProc(message);
25  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC