Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

floating window


  • Please log in to reply
7 replies to this topic
newtopic
  • Guests
  • Last active:
  • Joined: --
how to modify this code to make a window constantly moving at random direction across the screen, = floating

LOOP, 999999
{ 

wingetpos x, y,,, Calculator   ; get coordinates of the active window
   X += 1            ; 
   Y += 1           ; 
   winmove, Calculator,,%x%, %y%  ; make the active window use the new coordinates
  

}
 return              ; finish

the problem with this code is that it will move the window outside of screen

Klaus
  • Members
  • 333 posts
  • Last active: Feb 17 2015 09:31 AM
  • Joined: 12 May 2005
Hi, newtopic,
you have to keep X between 0 and A_ScreenWidth and Y between 0 and A_ScreenHeight. Additionally, you have to consider the width and height of the window that should float. "WinGetPos" will help you to detect these values. Thus, you keep X between 0 and (A_ScreenWidth - windowWidth) and Y between 0 and (A_ScreenHeight - Window Height).
And as a last hint, you have to change the floating direction when the floating window touches any of the screen's border.
Have fun and post your result!
Klaus

  • Guests
  • Last active:
  • Joined: --
hmmmm, doesnt seem to work, is there any grammar error in this coding

Z = 55
I = 55

  LOOP, 999
{ 

wingetpos x, y,,, Calculator   ; get coordinates of the active window


X += Z
Y += I
if (X > A_ScreenWidth) {
    Z = - Z
} 
if (Y > A_ScreenHeight) {
    I = - I
} 

   winmove, Calculator,,%x%, %y%  ; make the active window use the new coordinates
  

}
 return              ; finish


Odlanir
  • Members
  • 775 posts
  • Last active: Mar 06 2014 11:02 AM
  • Joined: 07 Aug 2011
Try this.

LOOP, 999 
{ 
	WinGetPos, x,y,w,h,Calculator ; get coordinates of the active window 
	X += 30 
	Y += 30 
	if ((X + w) > A_ScreenWidth) { 
		x = - x 
	} 
	if ((Y + h) > A_ScreenHeight) { 
		y = - y 
	} 
	WinMove, Calculator,,%x%, %y%  ; make the active window use the new coordinates 	  
} 
 ExitApp
 ; Set A hotkey just to stop whenever you want
 esc:: 
   ExitApp
return

Regards

  • Guests
  • Last active:
  • Joined: --
x = - x


:?: :?: :?:


You are" lucky" that it is interpreted as 0 :!: :!:
But it is not correct!


x = 30
x = -x

msgbox %x%



Odlanir
  • Members
  • 775 posts
  • Last active: Mar 06 2014 11:02 AM
  • Joined: 07 Aug 2011
Guest
I agree with you. The correct code should be
if ((X + w) > A_ScreenWidth) { 
	x = 0
} 
if ((Y + h) > A_ScreenHeight) { 
	y = 0
}

but my focus were to correct the test

if (X > A_ScreenWidth)

in

if ((X + w) > A_ScreenWidth)

as Klaus suggest.
Regards.

Odlanir
  • Members
  • 775 posts
  • Last active: Mar 06 2014 11:02 AM
  • Joined: 07 Aug 2011
as suggested by Klaus

... change the floating direction when the floating window touches any of the screen's border.

pgmName := A_Language = 0410 ? "Calcolatrice" : "Calculator"

xdirection = Forward
ydirection = Forward
LOOP, 999 
{ 	
	WinGetPos, x,y,w,h,%pgmName% ; get coordinates of the active window 
	if ((X + w) > A_ScreenWidth)
		xdirection = Back
	if ((Y + h) > A_ScreenHeight) 		
		ydirection = Back
	if (X <= 0)
		xdirection = Forward
	if (Y <= 0) 
		ydirection = Forward
	x := xdirection = "Forward" ? x+15 : x-15
	y := ydirection = "Forward" ? y+15 : y-15
	WinMove, %pgmName%,,%x%, %y%  ; make the active window use the new coordinates 	  
} 
ExitApp

Ciao.

Gogo
  • Guests
  • Last active:
  • Joined: --
WinGetPos x,y,w,h,Calculator

Loop 1000

  WinMove Calculator,, Abs(x:=(x > A_ScreenWidth-w)? -x : x+5), Abs(y:=(y > A_ScreenHeight-h)? -y : y+5)