Move Form without Titlebar

Tagged:

The code below shows how a form w/o titlebar can be moved with a mouse. It uses ReleaseCapture and SendMessage Windows API functions and based on How to Move a Form that Has No Titlebar or Caption.

This is sample code. Add error handling and adjust to your requirements as necessary.

PUBLIC oform1
 
oForm1 = NEWOBJECT("form1")
oForm1.Show()
RETURN
 
DEFINE CLASS form1 AS form
 
	Autocenter = .T.
	Height = 250
	Width = 375
	TitleBar = 0
	Name = "Form1"
 
	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 192, Left = 132, Height = 27, Width = 84, ;
		Caption = "Exit", Name = "Command1"
 
	ADD OBJECT command2 AS commandbutton WITH ;
		Top = 84, Left = 48, Height = 27, Width = 84, ;
		Caption = "Command2", SpecialEffect = 2, Name = "Command2"
 
	ADD OBJECT command3 AS commandbutton WITH ;
		Top = 84, Left = 252, Height = 27, Width = 84, ;
		Caption = "Command3", SpecialEffect = 2, Name = "Command3"
 
	PROCEDURE Load
		DECLARE Long ReleaseCapture IN WIN32API
		DECLARE Long SendMessage IN WIN32API ;
				Long HWND, Long wMsg, Long wParam, Long Lparam
	ENDPROC
 
	PROCEDURE MouseDown
		LPARAMETERS nButton, nShift, nXCoord, nYCoord
		#DEFINE WM_SYSCOMMAND 0x112
		#DEFINE WM_LBUTTONUP 0x202
		#DEFINE MOUSE_MOVE 0xf012
 
		IF nButton = 1 		&& LMB
			= ReleaseCapture()
			&& Complete left click by sending 'left button up' message
			= SendMessage(Thisform.HWnd, WM_LBUTTONUP, 0x0, 0x0)
			&& Initiate Window Move
			= SendMessage(Thisform.HWnd, WM_SYSCOMMAND, MOUSE_MOVE, 0x0)
		ENDIF
	ENDPROC
 
	PROCEDURE command1.Click
		Thisform.Release()
	ENDPROC
 
ENDDEFINE

I found VERY easy and useful the example code in your site
http://www.berezniker.com/content/pages/visual-foxpro/move-form-without-...
Thank you very much !
{J}