Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Capturing mouse clicks to non_client area of a control

Posted on 2002-07-28
2
Medium Priority
?
175 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 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

783 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