Solved

Capturing mouse clicks to non_client area of a control

Posted on 2002-07-28
2
166 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
Comment Utility
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
Comment Utility
Thats some nice work.. Thanks.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now