furrycow Posted February 27, 2009 Posted February 27, 2009 Hey, I'm creating a GUI that doesnt have a title bar, however i still wish for it to be able to be dragged around the screen, just by holding down mouse1 anywhere on the GUI...so far i have this code: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) AutoItSetOption("MouseCoordMode", 1) $FRMTest = GUICreate("", 330, 156, 304, 194, BitOR($WS_MINIMIZEBOX, $WS_DLGFRAME, $WS_POPUP, $WS_GROUP, $WS_CLIPSIBLINGS, $WS_EX_LAYERED)) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_PRIMARYDOWN,"_WindowDrag",$FRMTest) While 1 Sleep(1000) WEnd Func _WindowDrag() While $GUI_EVENT_PRIMARYDOWN $MousePos=MouseGetPos() WinMove ( "", "",$MousePos[0],$MousePos[1]) Sleep(5) WEnd EndFunc However, the mouse always goes to (0,0) of the GUI when it comes to dragging, whereas i want it to drag from wherever the user places their mouse. I was just looking for a few hints on what to do, as this code pretty much does all i want it to, just not where i want it to . Thanks! Instant Lockerz Invite - www.instantlockerzinvite.co.uk
Ealric Posted February 27, 2009 Posted February 27, 2009 Func Drag($GUI) DllCall("user32.dll", "int", "SendMessage", "hWnd", $GUI, "int", $WM_NCLBUTTONDOWN, "int", $HTCAPTION, "int", 0) EndFunc Just place the name of your GUI parent variable in the function and place it in your loop. For example: Drag($FRMTest) - place that in your loop. My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]
furrycow Posted February 27, 2009 Author Posted February 27, 2009 (edited) Ealric said: Func Drag($GUI) DllCall("user32.dll", "int", "SendMessage", "hWnd", $GUI, "int", $WM_NCLBUTTONDOWN, "int", $HTCAPTION, "int", 0) EndFunc Just place the name of your GUI parent variable in the function and place it in your loop. For example: Drag($FRMTest) - place that in your loop. Works a treat, cheers buddy! EDIT: I take that back, it does work, however, if i drag it, let go of mouse1, then open another window that i have minimized, the mouse arrow isn't able to move onto the windows taskbar....any thoughts? Edited February 27, 2009 by furrycow Instant Lockerz Invite - www.instantlockerzinvite.co.uk
PsaltyDS Posted February 27, 2009 Posted February 27, 2009 furrycow said: Hey, I'm creating a GUI that doesnt have a title bar, however i still wish for it to be able to be dragged around the screen, just by holding down mouse1 anywhere on the GUI...so far i have this code: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) AutoItSetOption("MouseCoordMode", 1) $FRMTest = GUICreate("", 330, 156, 304, 194, BitOR($WS_MINIMIZEBOX, $WS_DLGFRAME, $WS_POPUP, $WS_GROUP, $WS_CLIPSIBLINGS, $WS_EX_LAYERED)) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_PRIMARYDOWN,"_WindowDrag",$FRMTest) While 1 Sleep(1000) WEnd Func _WindowDrag() While $GUI_EVENT_PRIMARYDOWN $MousePos=MouseGetPos() WinMove ( "", "",$MousePos[0],$MousePos[1]) Sleep(5) WEnd EndFunc However, the mouse always goes to (0,0) of the GUI when it comes to dragging, whereas i want it to drag from wherever the user places their mouse. I was just looking for a few hints on what to do, as this code pretty much does all i want it to, just not where i want it to . Thanks! You need to calculate an offset between mouse pos and window pos, and use that offset when moving the window: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Misc.au3> Opt("GUIOnEventMode", 1) AutoItSetOption("MouseCoordMode", 1) HotKeySet("{ESC}", "_Quit") $FRMTest = GUICreate("", 330, 156, 304, 194, BitOR($WS_MINIMIZEBOX, $WS_DLGFRAME, $WS_POPUP, $WS_GROUP, $WS_CLIPSIBLINGS, $WS_EX_LAYERED)) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_WindowDrag", $FRMTest) While 1 Sleep(1000) WEnd Func _WindowDrag() ; Calculate offset $MouseOffset = WinGetPos($FRMTest) $MousePos = MouseGetPos() $MouseOffset[0] -= $MousePos[0] $MouseOffset[1] -= $MousePos[1] ConsoleWrite("Offset [0] = " & $MouseOffset[0] & " [1] = " & $MouseOffset[1] & @LF) ; Loop while PRIMARYDOWN While _IsPressed("01") $MousePos = MouseGetPos() $MousePos[0] += $MouseOffset[0] $MousePos[1] += $MouseOffset[1] ConsoleWrite("Move [0] = " & $MousePos[0] & " [1] = " & $MousePos[1] & @LF) WinMove($FRMTest, "", $MousePos[0], $MousePos[1]) Sleep(20) WEnd EndFunc ;==>_WindowDrag Func _Quit() Exit EndFunc ;==>_Quit Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
furrycow Posted February 27, 2009 Author Posted February 27, 2009 PsaltyDS said: You need to calculate an offset between mouse pos and window pos, and use that offset when moving the window: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Misc.au3> Opt("GUIOnEventMode", 1) AutoItSetOption("MouseCoordMode", 1) HotKeySet("{ESC}", "_Quit") $FRMTest = GUICreate("", 330, 156, 304, 194, BitOR($WS_MINIMIZEBOX, $WS_DLGFRAME, $WS_POPUP, $WS_GROUP, $WS_CLIPSIBLINGS, $WS_EX_LAYERED)) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_WindowDrag", $FRMTest) While 1 Sleep(1000) WEnd Func _WindowDrag() ; Calculate offset $MouseOffset = WinGetPos($FRMTest) $MousePos = MouseGetPos() $MouseOffset[0] -= $MousePos[0] $MouseOffset[1] -= $MousePos[1] ConsoleWrite("Offset [0] = " & $MouseOffset[0] & " [1] = " & $MouseOffset[1] & @LF) ; Loop while PRIMARYDOWN While _IsPressed("01") $MousePos = MouseGetPos() $MousePos[0] += $MouseOffset[0] $MousePos[1] += $MouseOffset[1] ConsoleWrite("Move [0] = " & $MousePos[0] & " [1] = " & $MousePos[1] & @LF) WinMove($FRMTest, "", $MousePos[0], $MousePos[1]) Sleep(20) WEnd EndFunc ;==>_WindowDrag Func _Quit() Exit EndFunc ;==>_Quit Thats the ticket! Thank you very much Psalty!! Instant Lockerz Invite - www.instantlockerzinvite.co.uk
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