VAN0 Posted May 1, 2022 Share Posted May 1, 2022 (edited) Hello. Example in the Moving and Resizing PopUp GUIs works well when dragged an empty window but when dragged a static control (label) - it doesn't move the window. #include <Windowsconstants.au3> #include <SendMessage.au3> HotKeySet("{ESC}", "On_Exit") $hGUI = GUICreate("Y", 100, 100, -1, -1, $WS_POPUP) GUISetBkColor(0x009F00) $hLabel = GUICtrlCreateLabel("", 0, 0, 100, 50) GUICtrlsetBkColor(-1, 0x9F0000) GUISetState() GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") While 1 Sleep(10) WEnd Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) _SendMessage($hGUI, $WM_SYSCOMMAND, 0xF012, 0) EndFunc Func On_Exit() Exit EndFunc In the example above only dragging green part moves the window. Then I've tried adopt PhoenixXL's example that forwards events from control to main GUI, but that moves window away from the cursor when clicked on red: expandcollapse popup#include <Windowsconstants.au3> #include <SendMessage.au3> #include <WinAPIDlg.au3> HotKeySet("{ESC}", "On_Exit") $hGUI = GUICreate("Y", 100, 100, -1, -1, $WS_POPUP) GUISetBkColor(0x00FF00) $hLabel = GUICtrlCreateLabel("", 0, 0, 100, 50) $hLabel = GUIctrlgethandle($hLabel) GUICtrlsetBkColor(-1, 0xFF0000) GUISetState() DeclareGlobals() GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") While 1 Sleep(10) WEnd Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) _SendMessage($hGUI, $WM_SYSCOMMAND, 0xF012, 0) EndFunc Func On_Exit() Exit EndFunc Func DeclareGlobals() ;used this to declare the globals required for the subclass. ;only to make the script look good. ;the function to release the resources upon exit OnAutoItExitRegister("Cleanup") ;callback Global $hStub = DllCallbackRegister("_WndProc", "long", "hwnd;uint;wparam;lparam") ;old window procedure Global $lpOldWndProc = _WinAPI_SetWindowLong($hLabel, $GWL_WNDPROC, DllCallbackGetPtr($hStub)) EndFunc ;==>DeclareGlobals Func _WndProc($hWnd, $iMsg, $iwParam, $ilParam) ;proceed the message to the parent Switch $iMsg Case $WM_LBUTTONDOWN Local $hParent = _WinAPI_GetParent($hWnd) Local $tPoint = DllStructCreate($tagPOINT) DllStructSetData($tPoint, 1, _WinAPI_LoWord($ilParam)) DllStructSetData($tPoint, 2, _WinAPI_HiWord($ilParam)) ;convert the points of the picture with respect to that of the parent. _WinAPI_ClientToScreen($hWnd, $tPoint) _WinAPI_ScreenToClient($hParent, $tPoint) ;make the new ilParam. $ilParam = _WinAPI_MakeLong(DllStructGetData($tPoint, 1), DllStructGetData($tPoint, 2)) ;send the message to the main GUI. _WinAPI_PostMessage($hParent, $WM_LBUTTONDOWN, $iwParam, $ilParam) Return 1 ;block the default processing EndSwitch Return _WinAPI_CallWindowProc($lpOldWndProc, $hWnd, $iMsg, $iwParam, $ilParam) EndFunc ;==>_WndProc ;release the resources Func Cleanup() _WinAPI_SetWindowLong($hLabel, $GWL_WNDPROC, $lpOldWndProc) DllCallbackFree($hStub) EndFunc ;==>Cleanup Any tips how to move window when clicked anywhere inside of it? Thank you. Edited May 1, 2022 by VAN0 Link to comment Share on other sites More sharing options...
Solution pixelsearch Posted May 1, 2022 Solution Share Posted May 1, 2022 In your 1st example, just change this line... $hLabel = GUICtrlCreateLabel("", 0, 0, 100, 50) to... $hLabel = GUICtrlCreateLabel("", 0, 0, 100, 50, -1, 0x00100000) ; $GUI_WS_EX_PARENTDRAG VAN0 1 Link to comment Share on other sites More sharing options...
VAN0 Posted May 1, 2022 Author Share Posted May 1, 2022 It can't be this simple...lol Thank you, it's perfect! Link to comment Share on other sites More sharing options...
pixelsearch Posted May 1, 2022 Share Posted May 1, 2022 Glad you liked the simple way You may be interested with another way (which doesn't register messages). It allows you to drag a popup window even if you don't click on a static label. This way of scripting isn't really recommended in case you'll deal with child GUI's one day : #include <GuiconstantsEx.au3> #include <WindowsConstants.au3> HotKeySet("{ESC}", "On_Exit") $hGUI = GUICreate("X", 100, 100, -1, -1, $WS_POPUP, $WS_EX_CONTROLPARENT) GUISetBkColor(0x00FF00, $hGUI) $hButton = GUICtrlCreateButton("Test", 10, 35, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $hButton On_Button() EndSwitch WEnd Func On_Button() MsgBox(0, "Hi", "Button Pressed") EndFunc ;==>On_Button Func On_Exit() Exit EndFunc ;==>On_Exit VAN0 1 Link to comment Share on other sites More sharing options...
VAN0 Posted May 1, 2022 Author Share Posted May 1, 2022 Even better. Thank you very much. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now