Moving a Gui

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Moving a Gui

04 Jun 2014, 21:39

I'm using the following code to move and resize a Gui:

Code: Select all

	sp = 40
	
	Gui, 95:Default
	GuiControlget, Slide, Pos
		
	C := SlideX
	V := SlideY
	
	loop, 23
	{			
		C += 5	
		V -= 4
		SlideW := SlideW * 1.018
		SlideH := SlideH * 1.018
		guicontrol, 95:movedraw, Slide, x%C%, y%V%, w%SlideW%, h%SlideH%
		sleep %sp%
		sp -= 1
	}
This works except that I'm getting some flickering as mentioned in the help manual. I tried using move rather than movedraw but then the effect was totally different with the Gui moving in a different direction and then just jumping to the final position. I'm trying to create a kind of accelerated slide. Can anyone suggest an alternative method? Thanks.
Leefme
Posts: 90
Joined: 30 Sep 2013, 22:13

Re: Moving a Gui

04 Jun 2014, 23:46

Why didn't you provide a working example to work with?
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Moving a Gui

05 Jun 2014, 00:58

Leefme wrote:Why didn't you provide a working example to work with?
Because it is part of a much larger script and I didn't think of it.
User avatar
xZomBie
Posts: 256
Joined: 02 Oct 2013, 02:57

Re: Moving a Gui

05 Jun 2014, 07:16

I found this code a while ago, maybe you can use some part of it :)
http://www.autohotkey.com/board/topic/1 ... ntry119240

Code: Select all

; EasyGlide 
; Based on Easy Window Dragging 
; 
;      AutoHotkey Version: 1.0.46+ (uses ?: operator)
;                Platform: XP/2k/NT
;                  Author: Paul Pliska (ManaUser)
; Performance Enhancement: Laszlo
; 
; Script Function: 
; Make the middle mouse button drag any window, in any internal point. 
; Additionally, if you let go while dragging, the window will "glide" 
; for short distance, and even bounce off the edges of the screen. 
; The distance and "bouncyness" can be adjusted by changing constants.

    INERTIA = 1 ;0.97 ; 1 means Glide forever, 0 means not at all. 
 BOUNCYNESS = 0.95 ;0.03 ; 1 means no speed is lost, 0 means don't bounce. 
SENSITIVITY = 0.99 ; Higher is more responsive, lower smooths out glitchs more.
                   ; Must be greater than 0 and no higher than 1.

#notrayicon
#SingleInstance Force 
#NoEnv 
SetBatchLines -1        ; Run faster 
SetWinDelay -1          ; Makes the window moves faster/smoother. 
CoordMode Mouse, Screen ; Switch to screen/absolute coordinates. 
SpeedA := 1 - SENSITIVITY
SetTimer WorkAreaCheck, 10000	;Just in case they move the task bar.
GoSub WorkAreaCheck		;or change resolution.

~*Escape::
ExitApp

~*LButton::             ; Clicking a mouse button stops glide. 
~*RButton:: 
   SetTimer Glide, Off 
Return 

MButton:: 
   SetTimer Glide, Off 
   MouseGetPos LastMouseX, LastMouseY, MouseWin 
   WinGet WinState, MinMax, ahk_id %MouseWin% 
   IfNotEqual WinState, 0 ; If the window is maximized, just to normal Middle Click
   {
       Click Middle
       Return
   }
   WinGetPos WinX, WinY, WinWidth, WinHeight, ahk_id %MouseWin% 
   SetTimer WatchMouse, 10       ; Track the mouse as the user drags it 
Return 

WatchMouse: 
   If !GetKeyState("MButton","P") { 
      SetTimer WatchMouse, Off   ; MButton has been released, so drag is complete. 
      SetTimer Glide, 10         ; Start gliding 
      Return 
   } 
                                 ; Drag: Button is still pressed 
   MouseGetPos MouseX, MouseY 
   WinX += MouseX - LastMouseX 
   WinY += MouseY - LastMouseY 

   ;Enforce Boundries 
   WinX := WinX < WorkAreaLeft ? WorkAreaLeft : WinX+WinWidth > WorkAreaRight ? WorkAreaRight-WinWidth : WinX 
   WinY := WinY < WorkAreaTop ? WorkAreaTop : WinY+WinHeight > WorkAreaBottom ? WorkAreaBottom-WinHeight : WinY 

   WinMove ahk_id %MouseWin%,, WinX, WinY 
   SpeedX := SpeedX*SpeedA + (MouseX-LastMouseX)*SENSITIVITY 
   SpeedY := SpeedY*SpeedA + (MouseY-LastMouseY)*SENSITIVITY 
   LastMouseX := MouseX,     LastMouseY := MouseY 
Return 

Glide: 
   SpeedX *= INERTIA 
   SpeedY *= INERTIA 
   If (Abs(SpeedX) < 0.2 AND Abs(SpeedY) < 0.2) { 
      SetTimer Glide, Off        ; It's barely moving, bring it to a complete stop 
      Return 
   } 

   WinX += SpeedX,   WinY += SpeedY 

   If (WinX < WorkAreaLeft  OR  WinX + WinWidth > WorkAreaRight) 
      SpeedX *= -BOUNCYNESS 
   If (WinY < WorkAreaTop  OR  WinY + WinHeight > WorkAreaBottom) 
      SpeedY *= -BOUNCYNESS 
   WinX := WinX < WorkAreaLeft ? WorkAreaLeft : WinX+WinWidth > WorkAreaRight ? WorkAreaRight-WinWidth : WinX 
   WinY := WinY < WorkAreaTop ? WorkAreaTop : WinY+WinHeight > WorkAreaBottom ? WorkAreaBottom-WinHeight : WinY 

   WinMove ahk_id %MouseWin%,, WinX, WinY 
Return

WorkAreaCheck:
SysGet WorkArea, MonitorWorkArea
Return
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Moving a Gui

12 Jun 2014, 01:45

Thanks for the replies. I'm still working through them. I think they are OK for moving the GUI but less so for moving and resizing it at the same time.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], pafec and 172 guests