Page 1 of 1

How to drag a window by pulling a gadget?

Posted: Sat May 11, 2024 8:20 am
by AZJIO
How to drag a window by pulling a gadget?

Code: Select all

; $GUI_WS_EX_PARENTDRAG = 1048576 = $100000 (AutoIt3) = WS_EX_NOINHERITLAYOUT ?
If OpenWindow(0, 0, 0, 270, 160, "Drag a window by pulling the gadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	TextGadget(0, 10, 10, 250, 140, "Drag a window by pulling the gadget")
	SetWindowLongPtr_(GadgetID(0),#GWL_EXSTYLE,GetWindowLongPtr_(GadgetID(0),#GWL_EXSTYLE) | $100000)
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
it works in AutoIt3, here is the code

Code: Select all

#include <GUIConstantsEx.au3>
GUICreate('My Program', 250, 260)
GUICtrlCreateLabel('Drag a window by pulling the gadget', 5, 5, 150, 150, -1, $GUI_WS_EX_PARENTDRAG)
GUISetState()
While 1
 	If GUIGetMsg() = -3 Then Exit
WEnd

Re: How to drag a window by pulling a gadget?

Posted: Sat May 11, 2024 8:58 am
by BarryG
For Windows only:

Code: Select all

If OpenWindow(0, 0, 0, 270, 160, "Drag a window by pulling the gadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	TextGadget(0, 10, 10, 250, 140, "Drag a window by pulling the gadget",#SS_NOTIFY)
	SetWindowLongPtr_(GadgetID(0),#GWL_EXSTYLE,GetWindowLongPtr_(GadgetID(0),#GWL_EXSTYLE) | $100000)
  Repeat
    ev=WaitWindowEvent()
    If ev=#PB_Event_Gadget
      SendMessage_(WindowID(0),#WM_NCLBUTTONDOWN,#HTCAPTION,0)
    EndIf
  Until ev=#PB_Event_CloseWindow
EndIf

Re: How to drag a window by pulling a gadget?

Posted: Sat May 11, 2024 9:35 am
by AZJIO
Works without SetWindowLongPtr_
I had an example with #WM_NCLBUTTONDOWN, but the final solution turned out to be #SS_NOTIFY
What confuses me is that AutoIt3 does not use WM_NCLBUTTONDOWN

Re: How to drag a window by pulling a gadget?

Posted: Sat May 11, 2024 9:36 am
by BarryG
Yes, you need #SS_NOTIFY to make TextGadgets receive events.

Re: How to drag a window by pulling a gadget?

Posted: Sat May 11, 2024 9:50 am
by AZJIO
ImageGadget also works, but "LeftClick" is combined with "DragStart"

Code: Select all

If OpenWindow(0, 0, 0, 54, 104, "-|-", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
	ImageGadget(0, 0, 0, 54, 104, 0)

	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_Gadget
				Select EventGadget()
					Case 0
						Select EventType()
							Case #PB_EventType_LeftClick
								Debug "LeftClick"
							Case #PB_EventType_RightClick
								Debug "RightClick"
							Case #PB_EventType_DragStart
								Debug "DragStart"
								SendMessage_(WindowID(0),#WM_NCLBUTTONDOWN,#HTCAPTION,0)
						EndSelect
				EndSelect
			Case #PB_Event_CloseWindow
				CloseWindow(0)
				End
		EndSelect
	ForEver
EndIf