Move Form without Titlebar

topic: 

The code below shows how a form without 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

.

$SAMPLECODE$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

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

Comments

I found VERY easy and useful the example code in your site

Thank you very much !
{J}

Great !
This help me very much.
Thank you !

Yes it works, Thanks!!!

YOU ARE THE BEST!!!!!!!!!!!!!!!!!!

I had this code snippet once... then I lost it... now I found it again thanks to you, Sergey! Many many thanks!