Solved

Capturing mouse clicks to non_client area of a control

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…

820 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