Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving a caption-less window by using a "drag area"

Tags:

delphi

I would like to have my own caption bar and therefore I am using basically a panel (Name: pnCaption) and remove the original caption bar in CreateParams. But the ability to move the window by MouseDown-MouseMove in the new panel is a problem.

Normally you would use the NCHITTEST message. BUT this isn't signaled if the mouse is over the panel (my own caption). See code ...

procedure TForm1.CreateParams(var params: TCreateParams);  
begin  
  inherited Createparams(Params);  
  with Params do  
    Style := (Style or WS_POPUP) and (not WS_DLGFRAME);  
end;  

procedure TForm1.WM_NCHitTest(var Msg: TWMNcHitTest);  
begin  
  inherited;  
  if PtInRect(pnCaption.BoundsRect, ScreenToClient(Point(Msg.XPos, Msg.YPos)))  
      then Msg.Result := HTCAPTION;  
end;  

I would appreciate any hints how to accomplish that task.

Christian

like image 573
Christian Avatar asked Oct 20 '10 09:10

Christian


People also ask

How to move a dialog which does not have a caption?

Two ways to move a dialog by dragging its client area. This article is aimed at beginners, and presents two ways to move a dialog which does not have a caption by dragging its client area. 1. WM_SYSCOMMAND message Sending the WM_SYSCOMMAND message starts the move operation. Add the following code to handle the mouse down event:

How do I show the contents of a window when dragging?

Open Control Panel / System. Select Advanced System Settings. In the Performance section, select the Settings Button. The 'Show window contents while dragging' is the option. Enable this setting to show the entire window and disable this setting to see the outline.

What is the default drag and Drop Distance in Windows 10?

With the default value set to 4 pixels, it is easy to inadvertently drag and drop files to a random item on your desktop or File Explorer. If you’re not happy with the default value, you can increase the drag and drop distance (in pixels) to avoid accidental move or copy of files.

How to change the drag and drop sensitivity in Windows?

To change the Drag and Drop sensitivity in Windows, follow these steps: Start the Registry Editor (regedit.exe) Go to the following branch: HKEY_CURRENT_USER\Control Panel\Desktop. In the right pane, set the data for DragHeight and DragWidth values to 50. Exit the Registry Editor. Logoff and login back for the change to take effect.


1 Answers

You can always drag a window by any control that has a mousedown event by using the "Magic" $F012 number with a WM_SYSCOMMAND message. It's something I picked up from Ray Kanopka (author of the excellent raize components), but I no longer remember how this was imparted to me.

It is also a neat and simple way of allowing users to move borderless forms by giving them a label of panel that looks like a caption. For example, I use it to allow users to move a borderless about dialog:

procedure TAbout_Dlg.LblTitleMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
const
  sc_DragMove = $F012;
begin
  ReleaseCapture;
  Perform( wm_SysCommand, sc_DragMove, 0 );
end;
like image 200
Marjan Venema Avatar answered Sep 18 '22 18:09

Marjan Venema