Skip to content

Latest commit

 

History

History
79 lines (53 loc) · 2.09 KB

File metadata and controls

79 lines (53 loc) · 2.09 KB

Home

How to drag a Form not using its Titlebar or Caption

Before you begin:

Drag the form with a mouse holding at any point in the client area of the form, not just the title of the form. The form can be dragged using its client area even if the Movable property set to False.

See also:


Code:

LOCAL oForm
oForm = CREATEOBJECT("Tform")
oForm.Visible=.T.
READ EVENTS

DEFINE CLASS Tform As Form
	Caption="Left-click inside the form and drag"
	Autocenter=.T.

PROCEDURE Init
	THIS.declare

PROCEDURE Destroy
	CLEAR EVENTS

PROCEDURE MouseDown
LPARAMETERS nButton, nShift, nXCoord, nYCoord
#DEFINE WM_NULL 0
#DEFINE WM_SYSCOMMAND 0x0112
#DEFINE WM_LBUTTONUP 0x0202
#DEFINE MOUSE_MOVE 0xf012

	IF nButton = 1
		LOCAL hWindow
		hWindow = THIS.HWnd && GetFocus()

		= ReleaseCapture()

		= SendMessage(hWindow, WM_SYSCOMMAND,;
			MOUSE_MOVE, WM_NULL)

		= SendMessage(hWindow, WM_LBUTTONUP, 0, 0)
	ENDIF

PROCEDURE declare
	DECLARE INTEGER ReleaseCapture IN user32
	DECLARE INTEGER GetFocus IN user32

	DECLARE INTEGER SendMessage IN user32;
		INTEGER hWindow, INTEGER Msg,;
		INTEGER wParam, INTEGER lParam

ENDDEFINE  

Listed functions:

GetFocus
ReleaseCapture
SendMessage

Comment:

This behaviour can also be implemented by intercepting and processing WM_NCHITTEST windows messages sent to the form. If the cursor is inside the client area, return HTCAPTION (2) instead of HTCLIENT (1).

Note that for top-level forms (ShowWindow=2), the first parameter in WM_NCHITTEST handling BINDEVENT call should not be ThisForm.HWnd, but the window handle of the inner window.