[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Dragging a window without using the title bar.

Posted on 1998-11-17
13
Medium Priority
?
312 Views
Last Modified: 2010-04-04
Dragging a window without using the title bar is easy enough, BUT it's not quite that simple.
I have a form that contains only a TGuage and a TPopupMenu.  The popup menu is linked to the TGauge and modifies certain parameters of the gauge (font, type, etc) and this works fine when you right click on the gauge, but if I use the code below to allow dragging of the form by clicking anywhere, the popup menu stops working.

procedure TForm1.WMNCHitTest( var Msg : TWMNCHitTest );
              begin
                inherited;
                if htClient = Msg.Result
                then
                  Msg.Result := htCaption;
              end;

Can anyone tell me how to have both the popup menu and being able to drag the window by clicking on the gauge?  I've tried everything I can think of.... thanks in advance.
0
Comment
Question by:delphiexpert
  • 5
  • 2
  • 2
  • +4
13 Comments
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 1347177
You may have to add a DouseDown event to the Gauge control and then manually show the PopUp menu (PopupMenu1.PopUp(X, Y).  That way you can still drag the form with the left mouse button, and get the PopUp menu working.

Hope this helps.

Stu.
0
 
LVL 1

Author Comment

by:delphiexpert
ID: 1347178
Unfortunately it doesn't.  The code I gave above makes windows think that the user is always clicking on the title bar, not the gauge and so the popup code never gets called.  I tried setting a flag whenever the mousedown event is called that contains the mouse button, and checking that flag in the WMNCHitTest procedure to see if the right mouse button was used... but this didn't work either.  Any further suggestions?  Thanks.

0
 
LVL 4

Expert Comment

by:dwwang
ID: 1347179
Isn't the popupmenu activeted by rightmouse click?
If so, why not just filter the rightclick in the above procedure?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Expert Comment

by:BoRiS
ID: 1347180
delphiexpert

what you can maybe do is pass this procedure and then call it

procedure WMRButtonDown(var M: TWMRButtonDown); message WM_RBUTTONDOWN; //under the public heading

then call

procedure TForm1.WMRButtonDown(var M: TWMRButtonDown);
var
Pt: Tpoint;
begin
 inherited;
  GetCursorPos(Pt);
  if M.Result = htClient then
  PopupMenu1.Popup(pt.x, pt.y);
end;

Havn't tested, so I don't know if it will work but you can try...

Later
BoRiS
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1347181
What you have to do is to determine whether a control is under the mouse while NCHITTEST:

procedure TForm1.WMNCHitTest( var Msg : TWMNCHitTest );
begin
  if ControlAtPos(ScreenToClient(SmallPointToPoint(Msg.Pos)), False) <> nil then inherited
    else Msg.Result := htCaption;
end;

In this case mouse handling works as normal if the mouse is over a child control, while you can drag the form in any other case.

Ciao, Mike
0
 
LVL 1

Author Comment

by:delphiexpert
ID: 1347182
Lischke,
the problem with the answer you gave is - the control takes up the whole form; its Align property is set to client.  Basically, what I want is this:
if the left mouse button is clicked, drag the form
if the right mouse button is clicked, bring up the menu.
It doesn't matter where on the form the mouse is, the above actions need to happen whereever it is.

0
 
LVL 1

Author Comment

by:delphiexpert
ID: 1347183
BoRiS,

thanks for your idea, but that didn't work either.  The procedure didnt ever get called, even when the right mouse button was down.
0
 
LVL 4

Expert Comment

by:dwwang
ID: 1347184
May I know how do you send the message TWMNCHitTest to the form?
0
 

Expert Comment

by:tothpaul
ID: 1347185
It is probably a TGauge bug, with a TPanel, your code work fine.

just put the TGauge on a TPanel (align=alclient) and link then PopupMenu to the Panel !
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1347186
try this:

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
if ssleft in shift then
   begin
   releasecapture; //restore mouse input to prevent from moving too far
   form1.perform(WM_syscommand, $F012, 0);
   end;
end;

bryan
0
 
LVL 1

Author Comment

by:delphiexpert
ID: 1347187
Unfortunately that doesn't work either, when I put the Tgauge on a Tpanel, the  WMNCHitTest procedure wasn't called while the mouse was over the Tpanel (ie, the whole time really).  The menu did work though.  I can easily get the dragging, or the popup menu but not both.  perhaps I'll just put the options somewhere on the main form...
unless anyone can come up with something else.
0
 

Accepted Solution

by:
tothpaul earned 320 total points
ID: 1347188
I suppose, it's possible to change TGauge to handle (or not) mouse events...on a right click, show the popup menu, on the left click, just do nothing (Form1 will take the message)

An other way is to implemente the dragging.

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 leftclick:=(Button=mbLeft);
 cleft:=x;
 ctop:=y;
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 leftclick:=false;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
 if leftclick then begin
  setbounds(left+x-cleft,top+y-ctop,width,height);
 end;
end;

0
 
LVL 1

Author Comment

by:delphiexpert
ID: 1347189
That worked!  Thanks!

(sorry for the delay in accepting the answer, I thought I already had.. obviously it didn't go through)

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month18 days, 3 hours left to enroll

829 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