Solved

Capturing mouse clicks to non_client area of a control

Posted on 2002-07-28
2
171 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 100 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month7 days, 17 hours left to enroll

617 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