SBrown Posted May 3, 2010 Share Posted May 3, 2010 How can i drag a gui by the gray background area? I want the user to be able to drag a popup around on their screen. Link to comment Share on other sites More sharing options...
picea892 Posted May 3, 2010 Share Posted May 3, 2010 (edited) Hi there Three examples for you to chew on. ;Created by Zedna, modified by Siao #include <GUIConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode",1) $gui = GuiCreate("Title",300,200,-1,-1,BitOR($WS_POPUP,$WS_BORDER,$WS_SIZEBOX)) GUISetOnEvent ($GUI_EVENT_CLOSE, "Quit" ) GUISetOnEvent ($GUI_EVENT_PRIMARYDOWN, "Drag" ) $a=GUICtrlCreateButton("Hi",100,100,50,50) GUICtrlSetOnEvent(-1,"runner") GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Func Drag() $a = GUIGetCursorInfo($gui) If $a[4] = 0 Then ;or exclude specific controlIDs dllcall("user32.dll","int","ReleaseCapture") dllcall("user32.dll","int","SendMessage","hWnd", $gui,"int",$WM_NCLBUTTONDOWN,"int", $HTCAPTION,"int", 0) EndIf EndFunc Func Quit() Exit EndFunc func runner() MsgBox(0,"","You pressed hi") EndFunc expandcollapse popup; Move any Window - Click & Drag ; Author Valuater Run("notepad.exe") WinWaitActive("") While WinExists("Untitled -") _WinMove("Untitled -") Sleep(10) WEnd ;=============================================================================== ; ; Description: Moves any Window by Left Mouse "Click & Drag" ; Syntax: _WinMove($hWnd) or _WinMove($s_Title) ; Parameter(s): $s_hWnd = as returned by GUICreate() ; $s_Title = title of window to be moved ; Requirement(s): None ; Return Value(s): On Success - Repositions the Window ; On Failure - Returns "" ; Author(s): Valuater, Valuater [at] aol [.com], Inspired by Martin ; ;=============================================================================== Func _WinMove($hWnd) If Not WinActive($hWnd) Then Return Local $a_R = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", '0x1') If @error Or BitAND($a_R[0], 0x8000) <> 0x8000 Then Return Local $a = WinGetPos($hWnd), $b = MouseGetPos() If $b[0] < $a[0] Or $b[1] < $a[1] Or $b[0] > $a[2] + $a[0] Or $b[1] > $a[3] + $a[1] Then Return While WinActive($hWnd) Local $c = MouseGetPos() WinMove($hWnd, '', $a[0] + $c[0] - $b[0], $a[1] + $c[1] - $b[1]) $a_R = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", '0x1') If @error Or BitAND($a_R[0], 0x8000) <> 0x8000 Then Return WEnd EndFunc ;==>_WinMove expandcollapse popup; press left and right mouse buttons #Include <Misc.au3> #Include <WinAPI.au3> #include <Constants.au3> #include <WindowsConstants.au3> global $dll = DllOpen("user32.dll") While 1 sleep(100) $hWnd =WinGetHandle("","") if _IsPressed("01", $dll) Then Do sleep(100) until _IsPressed("02", $dll) or not _IsPressed("01", $dll) $state = WinGetState($hWnd) if _IsPressed("02", $dll) and not BitAnd($state, 32) Then movewin($hWnd) ; MouseClick("left") EndIf EndIf WEnd func movewin($hWnd) Local $MousePos, $WinPos, $PosDiff[2] While 1 $MousePos = MouseGetPos () $WinPos = WinGetPos ("","") $PosDiff[0] = $WinPos[0] - $MousePos[0] $PosDiff[1] = $WinPos[1] - $MousePos[1] While _IsPressed ("01", $dll) $MousePos = MouseGetPos () WinMove ("", "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1]) $WinPos = WinGetPos ("","") Sleep (10) WEnd ExitLoop Sleep (10) WEnd EndFunc Edited May 3, 2010 by picea892 Link to comment Share on other sites More sharing options...
SBrown Posted May 3, 2010 Author Share Posted May 3, 2010 thanks a bunch Link to comment Share on other sites More sharing options...
rdwray Posted December 10, 2010 Share Posted December 10, 2010 Can this code be made to work with the right mouse button? I have tried and failed. Thanks...;Created by Zedna, modified by Siao #include <GUIConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode",1) $gui = GuiCreate("Title",300,200,-1,-1,BitOR($WS_POPUP,$WS_BORDER,$WS_SIZEBOX)) GUISetOnEvent ($GUI_EVENT_CLOSE, "Quit" ) GUISetOnEvent ($GUI_EVENT_PRIMARYDOWN, "Drag" ) $a=GUICtrlCreateButton("Hi",100,100,50,50) GUICtrlSetOnEvent(-1,"runner") GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Func Drag() $a = GUIGetCursorInfo($gui) If $a[4] = 0 Then ;or exclude specific controlIDs dllcall("user32.dll","int","ReleaseCapture") dllcall("user32.dll","int","SendMessage","hWnd", $gui,"int",$WM_NCLBUTTONDOWN,"int", $HTCAPTION,"int", 0) EndIf EndFunc Func Quit() Exit EndFunc func runner() MsgBox(0,"","You pressed hi") EndFunc “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
James Posted December 10, 2010 Share Posted December 10, 2010 Eww nasty. You should be looking more t GUIRegisterMsg and utilizing the WM_MOVE command. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 10, 2010 Moderators Share Posted December 10, 2010 rdwray,Could I suggest a read of the Moving and Resizing PopUp GUIs tutorial in the Wiki? Lots of good tips on how to do it there! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
rdwray Posted December 12, 2010 Share Posted December 12, 2010 rdwray, Could I suggest a read of the Moving and Resizing PopUp GUIs tutorial in the Wiki? Lots of good tips on how to do it there! M23 The very first piece of code I found on Wiki is strange. Normally if a control is placed on top of another one, both control retain their attributes, but here, the button becomes part of the label. How and why? If the button becomes a label, it loses its' value as an independent control. Thanks...#include <GuiconstantsEx.au3> #include <WindowsConstants.au3> HotKeySet("{ESC}", "On_Exit") $hGUI = GUICreate("X", 100, 100, -1, -1, $WS_POPUP) GUISetBkColor(0xFF0000, $hGUI) $hLabel = GUICtrlCreateLabel("", 0, 0, 100, 50, -1, $GUI_WS_EX_PARENTDRAG) GUICtrlSetBkColor(-1, 0x00FF00) ;GUICtrlSetState(-1, $GUI_DISABLE) $hButton = GUICtrlCreateButton("Test", 10, 35, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $hButton On_Button() Case $hLabel On_Exit() Case $hGUI MsgBox(0, "Hi", "GUI clicked") EndSwitch WEnd Func On_Button() MsgBox(0, "Hi", "Button Pressed") EndFunc ;==>On_Button Func On_Exit() Exit EndFunc ;==>On_Exit “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 12, 2010 Moderators Share Posted December 12, 2010 rdwray,Normally if a control is placed on top of another one, both control retain their attributesNot always so. If 2 active controls overlap, normally neither can be actioned - which is why background Pic controls need to be disabled. However, a label is actioned on mouse button down, while a button is actioned on mouse button up. So in this particular case, the label will be actioned on mouse button down and the mouse button up is swallowed by the system as indicating the end of the label action rather than acting as the button activation. I hope that makes sense - please ask if not. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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