kaotkbliss Posted August 16, 2011 Posted August 16, 2011 I'm not sure of what to look for, or how I would code this (apart from a complicated get desktop size and divide it up into my own grid) I was wanting to have my gui act in the same manner as normal desktop gadgets where they auto-snap to the desktop's grid, how would I do this in AutoIt or get autoit to interact with the desktop grid to do this? 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy!
pieeater Posted August 16, 2011 Posted August 16, 2011 (edited) well you could use a buch of if statements to check if the gui is not at a predetermined coord, then have it move to thata location if it is outside the area you defined, however that would require a lot of if statements an knowing exactly where you want it to snap Edit: you would also have to add an And statment checking if the position is'nt past the next part of the grid to every if statement. not sure if it is the best way to do it but its just my contribution Edited August 16, 2011 by pieeater [spoiler]My UDFs: Login UDF[/spoiler]
kaotkbliss Posted August 16, 2011 Author Posted August 16, 2011 Yeah, I thought of that using @desktopwidth and @desktopheight then dividing by the gui's width and height to "make" my own grid, but I would much prefer to use the one the desktop already has to it is sure to line up with other desktop gadgets. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy!
wakillon Posted August 16, 2011 Posted August 16, 2011 (edited) Try this #include <WinApi.au3> ConsoleWrite ( "$_TaskbarHeight : " & _GetTaskbarHeight ( ) & @Crlf ) Func _GetTaskbarHeight ( ) Local Const $SPI_GETWORKAREA = 48 Local $WorkArea, $stRect = DllStructCreate ( "long left;long top;long right;long bottom" ) Local $iResult = _WinAPI_SystemParametersInfo ( $SPI_GETWORKAREA, 0, DllStructGetPtr ( $stRect ), 0 ) If $iResult = True Then $WorkArea = DllStructGetData ( $stRect, "bottom" ) - DllStructGetData ( $stRect, "top" ) If Not @error Then Return @DesktopHeight - $WorkArea EndIf EndFunc ;==> _GetTaskbarHeight ( ) look at _WinAPI_GetWorkArea function too. Edited August 16, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
kaotkbliss Posted August 16, 2011 Author Posted August 16, 2011 well, I just found thread and apparently doesn't look very easy. I was hoping there was some dll or api or whatever that could be tapped into to access "the grid" but apparently not. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy!
monoscout999 Posted August 16, 2011 Posted August 16, 2011 I think that you have to check if the new coords of the windows is to close to another windows or the desktop edge and do the cases
AdmiralAlkex Posted August 16, 2011 Posted August 16, 2011 Am I the only one not sure what "grid" kaotkbliss means? Explanation? .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
monoscout999 Posted August 16, 2011 Posted August 16, 2011 (edited) Am I the only one not sure what "grid" kaotkbliss means? Explanation? a grid is like the koda.. when you move a control inside the koda the control moves from one point of the grid to another.. is the same but with windows.look at this, maybe it is useful Edited August 16, 2011 by monoscout999
kaotkbliss Posted August 16, 2011 Author Posted August 16, 2011 Thanks MS for that find, looks like it may help make things a lot easier @Admiral - I'm pretty sure there is an invisible grid or checkerboard on the desktop mostly used to align icons, but many desktop gadgets also use an invisible checkerboard to line up the gadgets. When you are moving the gadget and get close to the edge of one of these squares, the gadget auto aligns itself with that edge. At least, that's how I percieve it. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy!
AdmiralAlkex Posted August 16, 2011 Posted August 16, 2011 (edited) @kaotkbliss The desktop is just a listview, and the gadgets is most likely the application itself doing it. I don't think Windows has anything to do with it. Edit: light edit Edited August 16, 2011 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
ZacUSNYR Posted August 16, 2011 Posted August 16, 2011 Yea the icons are a list view and you can "align to grid" which is handled by the actual desktop. Windows/Widgets i'd think you'd have to do the math yourself to have it snap to edges, but you'd have to be aware of other windows open as well so you're not limited to just one. Thinking of making an AutoIt widget?
kaotkbliss Posted August 16, 2011 Author Posted August 16, 2011 Thanks guys. Going to take a bit of work but at least I know where to start. @Zac - Already have one, for the most part. The only thing is it doesn't "snap to grid" but is "free floating" like typical windows. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy!
kaotkbliss Posted August 18, 2011 Author Posted August 18, 2011 Ok, so I've been playing around with some ideas of how to do this, but I just can't seem to get it. I'm using Valik's wonderful _sendmessage function to make the popup gui dragable and it almost seems like it's a blocking function. basically what I was thinking was take the screen width and divide by the width of the gui to give me x numbers across, then loop through x while checking the position of the gui. If the gui is within so many pixels of the "line" then winmove it to the line. Also do the same with height. However, I haven't been able to get it, even when adding the code directly to the sendmessage include. it seems to only do the check when I release the mouse instead of while it's held down. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <Misc.au3> #include <SendMessage.au3> HotKeySet("{ESC}", "Terminate") Global $ver = "Program Launcher 2.7" $iW = 128 $iH = 170 $t = TimerInit();starts the timer in 't' $q = 0 Global $__MonitorList[1][5] $__MonitorList[0][0] = 0 Global $curres[2] Global $resmatch = 1 Global Const $SC_DRAGMOVE = 0xF012 ;end setting variables $mainmon = _GetMonitorFromPoint() If $mainmon = 0 Then $mainmon = 1 $res1 = _GetMonitors() $resx = $res1[$mainmon][3] $resy = $res1[$mainmon][4] $curres[0] = $resx $curres[1] = $resy $hGUI = GUICreate($ver, $iW, $iH, @DesktopWidth - $iW, (@DesktopHeight - $iH) / 2, BitOR($WS_SYSMENU, $WS_POPUP, $WS_BORDER), $WS_EX_TOOLWINDOW) $ListView = GUICtrlCreateListView("col1|col2", 0, 30, $iW + 40, $iH - 40) GUISetState(@SW_SHOW) While 1;start infinate loop Sleep(10);pause for 10 milliseconds $mainpos = WinGetPos($ver) $mainmon = _GetMonitorFromPoint($mainpos, $mainpos[1]) If $mainmon = 0 Then $mainmon = 1 $res1 = _GetMonitors() $resx = $res1[$mainmon][3] $resy = $res1[$mainmon][4] If $mainpos[0]+$mainpos[2] > $resx Then WinMove($ver,"",$resx-$mainpos[2],$mainpos[1]) EndIf If $mainpos[0] < 0 Then WinMove($ver,"",0,$mainpos[1]) EndIf If $mainpos[1]+$mainpos[3] > $resy - _GetTaskbarHeight() Then WinMove($ver,"",$mainpos[0],$resy-$mainpos[3] - _GetTaskbarHeight()) EndIf If $mainpos[1] < 0 Then WinMove($ver,"",$mainpos[0],0) EndIf Switch GUIGetMsg();check the gui for messages Case $GUI_EVENT_PRIMARYDOWN;if left mouse is clicked $xgrid = $resx / $mainpos[2] $ygrid = ($resy - _GetTaskbarHeight()) / $mainpos[3] $wincol = WinList() $extrax = 2 $extray = 2 $wpos = WinGetPos($ver);get the position of the main gui $mpos = MouseGetPos();get the mouse position $ipos = ControlGetPos($ver, "", $ListView);get the list area If $mpos[0] > $wpos[0] + $ipos[0] + $extrax And $mpos[1] > $wpos[1] + $ipos[1] + $extray And $mpos[0] < $wpos[0] + $ipos[0] + $extrax + $ipos[2] And $mpos[1] < $wpos[1] + $ipos[1] + $extray + $ipos[3] Then If TimerDiff($t) <= 500 And $q = 1 Then;if left click is in the list area MsgBox(0, "", "Double Clicked", 2) Else $t = TimerInit();reset the timer $q = 1 EndIf ElseIf $mpos[0] > $wpos[0] + $extrax And $mpos[1] > $wpos[1] + $extray And $mpos[0] < $wpos[0] + $ipos[0] + $extrax + $ipos[2] And $mpos[1] < $wpos[1] + $ipos[1] + $extray + $ipos[3] Then ;if the click is not in the list but in the main gui While _IsPressed("01");while the left button is held ;snap to grid will go here ;$wpos = WinGetPos($ver) ;$mposs = MouseGetPos() ;For $gridx = 0 to $xgrid _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0);move the gui ; If $mposs[0] >= ($gridx * $wpos[2] - 30) And $mposs[0] <= ($gridx * $wpos[2] + 30) Then ; WinMove($ver,"",$gridx * $wpos[2],$wpos[1]) ; EndIf ;Next ;For $gridy = 0 to $ygrid ; _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0);move the gui ; If $mposs[1] >= ($gridy * $wpos[3] - 30) And $mposs[1] <= ($gridy * $wpos[3] + 30) Then ; WinMove($ver,"",$wpos[0],$gridy * $wpos[3]) ; EndIf ;Next WEnd EndIf EndSwitch WEnd Func _GetTaskbarHeight() Local Const $SPI_GETWORKAREA = 48 Local $WorkArea, $stRect = DllStructCreate("long left;long top;long right;long bottom") Local $iResult = _WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($stRect), 0) If $iResult = True Then $WorkArea = DllStructGetData($stRect, "bottom") - DllStructGetData($stRect, "top") If Not @error Then Return @DesktopHeight - $WorkArea EndIf EndFunc ;==>_GetTaskbarHeight #Region thanks to xrxca for these functions Func _GetMonitorFromPoint($XorPoint = 0, $y = 0) Local $MousePos, $myX, $myY If @NumParams = 0 Then $MousePos = MouseGetPos() $myX = $MousePos[0] $myY = $MousePos[1] ElseIf (@NumParams = 1) And IsArray($XorPoint) Then $myX = $XorPoint[0] $myY = $XorPoint[1] Else $myX = $XorPoint $myY = $y EndIf If $__MonitorList[0][0] == 0 Then _GetMonitors() EndIf Local $i = 0 Local $Monitor = 0 For $i = 1 To $__MonitorList[0][0] If ($myX >= $__MonitorList[$i][1]) _ And ($myX < $__MonitorList[$i][3]) _ And ($myY >= $__MonitorList[$i][2]) _ And ($myY < $__MonitorList[$i][4]) Then $Monitor = $i Next Return $Monitor EndFunc ;==>_GetMonitorFromPoint Func _GetMonitors() $__MonitorList[0][0] = 0 ; Added so that the global array is reset if this is called multiple times Local $handle = DllCallbackRegister("_MonitorEnumProc", "int", "hwnd;hwnd;ptr;lparam") DllCall("user32.dll", "int", "EnumDisplayMonitors", "hwnd", 0, "ptr", 0, "ptr", DllCallbackGetPtr($handle), "lparam", 0) DllCallbackFree($handle) Local $i = 0 For $i = 1 To $__MonitorList[0][0] If $__MonitorList[$i][1] < $__MonitorList[0][1] Then $__MonitorList[0][1] = $__MonitorList[$i][1] If $__MonitorList[$i][2] < $__MonitorList[0][2] Then $__MonitorList[0][2] = $__MonitorList[$i][2] If $__MonitorList[$i][3] > $__MonitorList[0][3] Then $__MonitorList[0][3] = $__MonitorList[$i][3] If $__MonitorList[$i][4] > $__MonitorList[0][4] Then $__MonitorList[0][4] = $__MonitorList[$i][4] Next Return $__MonitorList EndFunc ;==>_GetMonitors Func _MonitorEnumProc($hMonitor, $hDC, $lRect, $lParam) Local $Rect = DllStructCreate("int left;int top;int right;int bottom", $lRect) $__MonitorList[0][0] += 1 ReDim $__MonitorList[$__MonitorList[0][0] + 1][5] If $hDC = $hDC Then EndIf If $lParam = $lParam Then EndIf $__MonitorList[$__MonitorList[0][0]][0] = $hMonitor $__MonitorList[$__MonitorList[0][0]][1] = DllStructGetData($Rect, "left") $__MonitorList[$__MonitorList[0][0]][2] = DllStructGetData($Rect, "top") $__MonitorList[$__MonitorList[0][0]][3] = DllStructGetData($Rect, "right") $__MonitorList[$__MonitorList[0][0]][4] = DllStructGetData($Rect, "bottom") Return 1 ; Return 1 to continue enumeration EndFunc ;==>_MonitorEnumProc #EndRegion thanks to xrxca for these functions Func Terminate() Exit 0 EndFunc ;==>Terminate a trimmed down reproducer. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy!
kaotkbliss Posted August 19, 2011 Author Posted August 19, 2011 If anyone has any ideas, I'm at a loss. I tried: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <Misc.au3> #include <SendMessage.au3> HotKeySet("{ESC}", "Terminate") Global $ver = "Program Launcher 2.7" $iW = 128 $iH = 170 $t = TimerInit();starts the timer in 't' $q = 0 Global $__MonitorList[1][5] $__MonitorList[0][0] = 0 Global $curres[2] Global $resmatch = 1 Global Const $SC_DRAGMOVE = 0xF012 ;end setting variables $mainmon = _GetMonitorFromPoint() If $mainmon = 0 Then $mainmon = 1 $res1 = _GetMonitors() $resx = $res1[$mainmon][3] $resy = $res1[$mainmon][4] $curres[0] = $resx $curres[1] = $resy $hGUI = GUICreate($ver, $iW, $iH, @DesktopWidth - $iW, (@DesktopHeight - $iH) / 2, BitOR($WS_SYSMENU, $WS_POPUP, $WS_BORDER), $WS_EX_TOOLWINDOW) $ListView = GUICtrlCreateListView("col1|col2", 0, 30, $iW + 40, $iH - 40) GUISetState(@SW_SHOW) While 1;start infinate loop Sleep(10);pause for 10 milliseconds $mainpos = WinGetPos($ver) $mainmon = _GetMonitorFromPoint($mainpos, $mainpos[1]) If $mainmon = 0 Then $mainmon = 1 $res1 = _GetMonitors() $resx = $res1[$mainmon][3] $resy = $res1[$mainmon][4] If $mainpos[0]+$mainpos[2] > $resx Then WinMove($ver,"",$resx-$mainpos[2],$mainpos[1]) EndIf If $mainpos[0] < 0 Then WinMove($ver,"",0,$mainpos[1]) EndIf If $mainpos[1]+$mainpos[3] > $resy - _GetTaskbarHeight() Then WinMove($ver,"",$mainpos[0],$resy-$mainpos[3] - _GetTaskbarHeight()) EndIf If $mainpos[1] < 0 Then WinMove($ver,"",$mainpos[0],0) EndIf Switch GUIGetMsg();check the gui for messages Case $GUI_EVENT_PRIMARYDOWN;if left mouse is clicked $xgrid = $resx / $mainpos[2] $ygrid = ($resy - _GetTaskbarHeight()) / $mainpos[3] $wincol = WinList() $extrax = 2 $extray = 2 $wpos = WinGetPos($ver);get the position of the main gui $mpos = MouseGetPos();get the mouse position $ipos = ControlGetPos($ver, "", $ListView);get the list area If $mpos[0] > $wpos[0] + $ipos[0] + $extrax And $mpos[1] > $wpos[1] + $ipos[1] + $extray And $mpos[0] < $wpos[0] + $ipos[0] + $extrax + $ipos[2] And $mpos[1] < $wpos[1] + $ipos[1] + $extray + $ipos[3] Then If TimerDiff($t) <= 500 And $q = 1 Then;if left click is in the list area MsgBox(0, "", "Double Clicked", 2) Else $t = TimerInit();reset the timer $q = 1 EndIf ElseIf $mpos[0] > $wpos[0] + $extrax And $mpos[1] > $wpos[1] + $extray And $mpos[0] < $wpos[0] + $ipos[0] + $extrax + $ipos[2] And $mpos[1] < $wpos[1] + $ipos[1] + $extray + $ipos[3] Then ;if the click is not in the list but in the main gui For $gridx = 0 To $xgrid For $gridy = 0 To $ygrid $wpos = WinGetPos($ver) $mposs = MouseGetPos() If ($mposs[0] >= ($gridx * $wpos[2] - 30) And $mposs[0] <= ($gridx * $wpos[2] + 30)) And ($mposs[1] >= ($gridy * $wpos[3] - 30) And $mposs[1] <= ($gridy * $wpos[3] + 30)) Then WinMove($ver, "", $gridx * $wpos[2], $gridy * $wpos[3]) EndIf _SendMessage($hGUI, $gridx, $gridy, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0);move the gui Next Next EndIf EndSwitch WEnd Func _GetTaskbarHeight() Local Const $SPI_GETWORKAREA = 48 Local $WorkArea, $stRect = DllStructCreate("long left;long top;long right;long bottom") Local $iResult = _WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($stRect), 0) If $iResult = True Then $WorkArea = DllStructGetData($stRect, "bottom") - DllStructGetData($stRect, "top") If Not @error Then Return @DesktopHeight - $WorkArea EndIf EndFunc ;==>_GetTaskbarHeight #Region thanks to xrxca for these functions Func _GetMonitorFromPoint($XorPoint = 0, $y = 0) Local $MousePos, $myX, $myY If @NumParams = 0 Then $MousePos = MouseGetPos() $myX = $MousePos[0] $myY = $MousePos[1] ElseIf (@NumParams = 1) And IsArray($XorPoint) Then $myX = $XorPoint[0] $myY = $XorPoint[1] Else $myX = $XorPoint $myY = $y EndIf If $__MonitorList[0][0] == 0 Then _GetMonitors() EndIf Local $i = 0 Local $Monitor = 0 For $i = 1 To $__MonitorList[0][0] If ($myX >= $__MonitorList[$i][1]) _ And ($myX < $__MonitorList[$i][3]) _ And ($myY >= $__MonitorList[$i][2]) _ And ($myY < $__MonitorList[$i][4]) Then $Monitor = $i Next Return $Monitor EndFunc ;==>_GetMonitorFromPoint Func _GetMonitors() $__MonitorList[0][0] = 0 ; Added so that the global array is reset if this is called multiple times Local $handle = DllCallbackRegister("_MonitorEnumProc", "int", "hwnd;hwnd;ptr;lparam") DllCall("user32.dll", "int", "EnumDisplayMonitors", "hwnd", 0, "ptr", 0, "ptr", DllCallbackGetPtr($handle), "lparam", 0) DllCallbackFree($handle) Local $i = 0 For $i = 1 To $__MonitorList[0][0] If $__MonitorList[$i][1] < $__MonitorList[0][1] Then $__MonitorList[0][1] = $__MonitorList[$i][1] If $__MonitorList[$i][2] < $__MonitorList[0][2] Then $__MonitorList[0][2] = $__MonitorList[$i][2] If $__MonitorList[$i][3] > $__MonitorList[0][3] Then $__MonitorList[0][3] = $__MonitorList[$i][3] If $__MonitorList[$i][4] > $__MonitorList[0][4] Then $__MonitorList[0][4] = $__MonitorList[$i][4] Next Return $__MonitorList EndFunc ;==>_GetMonitors Func _MonitorEnumProc($hMonitor, $hDC, $lRect, $lParam) Local $Rect = DllStructCreate("int left;int top;int right;int bottom", $lRect) $__MonitorList[0][0] += 1 ReDim $__MonitorList[$__MonitorList[0][0] + 1][5] If $hDC = $hDC Then EndIf If $lParam = $lParam Then EndIf $__MonitorList[$__MonitorList[0][0]][0] = $hMonitor $__MonitorList[$__MonitorList[0][0]][1] = DllStructGetData($Rect, "left") $__MonitorList[$__MonitorList[0][0]][2] = DllStructGetData($Rect, "top") $__MonitorList[$__MonitorList[0][0]][3] = DllStructGetData($Rect, "right") $__MonitorList[$__MonitorList[0][0]][4] = DllStructGetData($Rect, "bottom") Return 1 ; Return 1 to continue enumeration EndFunc ;==>_MonitorEnumProc #EndRegion thanks to xrxca for these functions Func Terminate() Exit 0 EndFunc ;==>Terminate but it seems maybe _sendmessage is a blocking function so I even tried changing to ElseIf $mpos[0] > $wpos[0] + $extrax And $mpos[1] > $wpos[1] + $extray And $mpos[0] < $wpos[0] + $ipos[0] + $extrax + $ipos[2] And $mpos[1] < $wpos[1] + $ipos[1] + $extray + $ipos[3] Then ;if the click is not in the list but in the main gui For $gridx = 0 To $xgrid For $gridy = 0 To $ygrid _SendMessage2($hGUI, $gridx, $gridy, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0);move the gui Next Next EndIf and adding this Func _SendMessage2($hWnd, $iMsg, $wParam = 0, $lParam = 0, $iReturn = 0, $wParamType = "wparam", $lParamType = "lparam", $sReturnType = "lresult") Local $aResult = DllCall("user32.dll", $sReturnType, "SendMessageW", "hwnd", $hWnd, "uint", $iMsg, $wParamType, $wParam, $lParamType, $lParam) If @error Then Return SetError(@error, @extended, "") If $iReturn >= 0 And $iReturn <= 4 Then $wpos = WinGetPos($ver) $mposs = MouseGetPos() If ($mposs[0] >= ($gridx * $wpos[2] - 30) And $mposs[0] <= ($gridx * $wpos[2] + 30)) And ($mposs[1] >= ($gridy * $wpos[3] - 30) And $mposs[1] <= ($gridy * $wpos[3] + 30)) Then WinMove($ver, "", $gridx * $wpos[2], $gridy * $wpos[3]) EndIf Return $aResult[$iReturn] EndIf Return $aResult EndFunc ;==>_SendMessage but all have the same result, it only checks the grid AFTER I release the left mouse button instead of while dragging... I tried just a simple winmove to the mouse location but the gui flickered pretty badly. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy!
monoscout999 Posted August 19, 2011 Posted August 19, 2011 (edited) Sorry but i don`t know why you complicated so much... What you want to do is that little window snap to the edges of the screen, Am i correct?... PD SendMessage() is a blocking function... _winapi_postmessage() isn`t. EDIT: registing a function for this msg will help" WM_MOVING " Edited August 19, 2011 by monoscout999
kaotkbliss Posted August 19, 2011 Author Posted August 19, 2011 (edited) I've not seen the postmessage function yet. Thanks for the tip *edit* not just to edges of screen, but also in a tic-tac-toe board across the screen. While dragging the gui to a new spot, if it comes close to the edges of this tic-tac-toe board, it snaps to that box. *edit again* I'm not sure what to put for the last 2 parameters ($iwParam, $ilParam) not sure what they are. The help file just links to MSDN and I really don't understand what they are saying Edited August 19, 2011 by kaotkbliss 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy!
monoscout999 Posted August 19, 2011 Posted August 19, 2011 Look at this... maybe you can adapt it because this doesn´t flick.. you only need to fill the cases expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Winapi.au3> Global Const $WM_MOVING = 0x0216 HotKeySet("{ESC}", "Terminate") $hGUI = GUICreate("SnapGUI by monoscout999", 150, 150, -1,-1, -1, $WS_EX_TOOLWINDOW) $ListView = GUICtrlCreateListView("col1|col2", 0, 0,150, 150) GuiRegisterMsg($WM_MOVING, "WM_MOVING") GUISetState(@SW_SHOW) Do Until GuiGetMsg() = - 3 Func Terminate() Exit EndFunc Func WM_MOVING($hWndGUI, $MsgID, $WParam, $LParam) $tRect = DllStructCreate($tagRect,$LParam) $left = DllStructGetData($tRect, "left") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $left = ' & $left & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console $top = DllStructGetData($tRect, "top") $right = DllStructGetData($tRect, "right") $bottom = DllStructGetData($tRect, "bottom") Select Case $Left < 50 and $right > 200 DllStructSetData($tRect,"left",50) case $Left < 50 DllStructSetData($tRect,"left",0) Case $Right > @DesktopWidth - 50 and $Left < @DesktopWidth - 200 DllStructSetData($tRect,"Right",@DesktopWidth - 50) case $Right > @DesktopWidth - 50 DllStructSetData($tRect,"Right",@DesktopWidth) Case $top < 50 and $Bottom > 200 DllStructSetData($tRect,"Top",50) case $top < 50 DllStructSetData($tRect,"Top",0) Case $Bottom > @DesktopHeight - 50 and $Top < @DesktopHeight - 200 DllStructSetData($tRect,"Bottom",@DesktopHeight - 50) case $Bottom > @DesktopHeight - 50 DllStructSetData($tRect,"Bottom",@DesktopHeight) EndSelect Return "GUI_RUNDEFMSG" EndFunc
monoscout999 Posted August 19, 2011 Posted August 19, 2011 This version works funny... but is enough for me... continue you with this madness.. :S expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Winapi.au3> #include <array.au3> Global Const $WM_MOVING = 0x0216 HotKeySet("{ESC}", "Terminate") $oShell = ObjCreate("shell.application") ;~ $oShell.MinimizeAll sleep(500) $BackGUI = GuiCreate("test",@DesktopWidth,@DesktopHeight,-1,-1,$WS_POPUP) GuiSetBkColor(0) winsettrans($BackGUI,"",100) GUISetState(@SW_SHOW) $hDC = _WinAPI_GetWindowDC($BackGUI) ; DC of entire screen (desktop) $hPen = _WinAPI_CreatePen($PS_SOLID, 3, 0x00FF00) $obj_orig = _WinAPI_SelectObject($hDC, $hPen) $hGUI = GUICreate("SnapGUI by monoscout999", 150, 150, -1,-1, -1, $WS_EX_TOOLWINDOW) $pos = winGetPos($hGUI) ; Some Auxiliary Variables. $t = Int(@DesktopWidth/$pos[2]) Global $xPoints[$t] For $i = 1 to $t $xPoints[$i-1] = $i*$pos[2] _winapi_drawline($hDC,$i*$pos[2],0,$i*$pos[2],@DesktopHeight) Next $t = Int(@DesktopWidth/$pos[3]) Global $yPoints[$t] For $i = 1 to $t $yPoints[$i-1] = $i*$pos[3] _winapi_drawline($hDC,0,$i*$pos[3],@DesktopWidth,$i*$pos[3]) Next $ListView = GUICtrlCreateListView("col1|col2", 0, 0,150, 150) GuiRegisterMsg($WM_MOVING, "WM_MOVING") GUISetState(@SW_SHOW) Do Until GuiGetMsg() = - 3 Terminate() Func Terminate() _WinAPI_SelectObject($hDC, $obj_orig) _WinAPI_DeleteObject($hPen) _WinAPI_ReleaseDC($BackGUI, $hDC) Exit EndFunc Func WM_MOVING($hWndGUI, $MsgID, $WParam, $LParam) $tRect = DllStructCreate($tagRect,$LParam) $left = DllStructGetData($tRect, "left") $top = DllStructGetData($tRect, "top") $right = DllStructGetData($tRect, "right") $bottom = DllStructGetData($tRect, "bottom") ;~ ConsoleWrite($Left - $xPoints[4] & @crlf) ;### Debug Console For $i = 0 to ubound($xPoints) - 1 Select Case $Left - $xPoints[$i] > - 15 and $Left - $xPoints[$i] < 15 For $a = 0 to ubound($yPoints) - 1 Select Case $Top - $yPoints[$a] > - 15 and $Top - $yPoints[$a] < 15 DllStructSetData($tRect,"left",$xPoints[$i]) DllStructSetData($tRect,"Top",$yPoints[$a]-17) Case $bottom - $yPoints[$a] > - 15 and $bottom - $yPoints[$a] < 15 DllStructSetData($tRect,"left",$xPoints[$i]) DllStructSetData($tRect,"bottom",$yPoints[$a]) EndSelect Next EndSelect Next Return "GUI_RUNDEFMSG" EndFunc
kaotkbliss Posted August 19, 2011 Author Posted August 19, 2011 I've only been able to play around with these for a little bit, but so far no luck It seems to be making my gui non-movable (I think because my gui is a popup and doesn't have the title bar) so normal dragging methods don't work. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy!
monoscout999 Posted August 19, 2011 Posted August 19, 2011 (edited) Take a look at this. #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> $hGUI = GuiCreate("Moving POPUP Windows by monoscout999",-1,-1,-1,-1,$WS_POPUP) GuiCtrlCreateLabel("Click Me and Drag Me",20,20,150,40,-1,$GUI_WS_EX_PARENTDRAG) GuiCtrlSetBkColor(-1, 0xFFFFFF) GuiSetBkColor(0) GuiSetState() Do Until GuiGetMsg() = -3 GuiDelete($hGUI) $hGUI = GuiCreate("Moving POPUP Windows by monoscout999",-1,-1,-1,-1,$WS_POPUP) GuiCtrlCreateLabel("Click anywhere and Drag Me",20,20,150,40,-1,$GUI_WS_EX_PARENTDRAG) GuiCtrlSetBkColor(-1, 0xFFFFFF) GuiSetBkColor(0) GuiSetState() GUIRegisterMsg($WM_NCHITTEST,"WM_NCHITTEST") Do Until GuiGetMsg() = -3 Func WM_NCHITTEST($hWndGUI, $MsgID, $WParam, $LParam) If $hWndGUI = $hGUI then Return $HTCAPTION EndFunc Edited August 19, 2011 by monoscout999
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