Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Capturing mouse clicks to non_client area of a control

Posted on 2002-07-28
2
Medium Priority
?
172 Views
Last Modified: 2010-04-04

I'm trying to write a panel component that has a caption area similar to a standard TForm. See http://www.experts-exchange.com/jsp/qManageQuestion.jsp?qid=20326931 for details.

On the caption area I've drawn a close and minimize icon, but I can't figure out how to capture the mouse clicks in this part of the control because it's not in the client area.
I would also like to be able to change the cursor to crHandPoint when the mouse is over this part of the control.

Thanks

Jo
0
Comment
Question by:nnbbb09
[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
2 Comments
 
LVL 7

Accepted Solution

by:
Cynna earned 400 total points
ID: 7183896
Hello again Jo ;)

You'll need to add a bit more windows message handling to your component for this.
I added three more event handlers. As usual, copy/paste of below code will do fine:

  TmyPanel = class(TCustomPanel)
  protected
     // Old stuff:
     procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
     procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;

     // Added for cursor change and click:
     procedure WMNCHitTest(var Message: TMessage); message WM_NCHITTEST;
     procedure CMMouseLeave(var msg: TMessage); message CM_MOUSELEAVE;
     procedure NCMouseClicked(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;

     // ... rest of your stuff ....

  end;




implementation

// ... your implementation code ...

procedure TmyPanel.WMNCHitTest(var Message: TMessage);
var s, c: TPoint;
begin
  inherited;
  s.x:=Message.LParamLo;
  s.y:=Message.LParamHi;
  c:= ScreenToClient(s);
  if (c.y<1) then Cursor:=crHandPoint
  else if Cursor=crHandPoint then Cursor:=crDefault;
  Message.Result:=1;
end;

procedure TmyPanel.CMMouseLeave(var msg: TMessage);
begin
  inherited;
  Screen.Cursor:=crDefault;
end;

procedure TmyPanel.NCMouseClicked(var Message: TWMLButtonDown);
var ClickPoint: TPoint;
begin
  inherited;
  with ClickPoint, Message do begin
       X:=XPos;
       Y:=YPos+CaptionAreaHeight;
  end;
  // ClickPoint now contains click coordinates!

  // ....  your click-dependant stuff goes here....

end;

0
 
LVL 3

Author Comment

by:nnbbb09
ID: 7184908
Thats some nice work.. Thanks.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

719 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