Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

GUI moves with another window's movement


  • Please log in to reply
3 replies to this topic
EvilleMonkey
  • Members
  • 39 posts
  • Last active: Jul 15 2016 01:52 PM
  • Joined: 04 Feb 2014

Hello, I'm trying to have my GUI move with another window's movement.... let's say, with Notepad. When I drag the notepad window up.. the GUI moves up with it, or if i move the notepad window, down, left, right, etc.... I've already obtained the unique ID of the notepad window so the GUI is owned by the notepad window. Just need to figure out how to get it to move with it. Here's what I have.....

 

#NoEnv
#NoTrayIcon
#Persistent
#SingleInstance, Off
SetWinDelay, 0
SendMode Input
SetBatchLines, -1
SetTitleMatchMode, 2


;; Get ID of Notepad
WinGet, WinID, ID, ahk_class Notepad,,,
Gui, +Owner%WinID% +Border +ToolWindow 
;; add some buttons and stuff here

;; Position GUI next to Notepad and show
WinGetPos, X, Y,,, ahk_class Notepad
X := X - 56
Gui, Show, x%X% y%Y% w51 h431,%GuiTitle%

Thanks in advance. 

 

 

 



GEV
  • Members
  • 1364 posts
  • Last active:
  • Joined: 23 Oct 2013
SetTimer, ShowGui, 500

	ShowGui:	
WinWait, ahk_class Notepad
WinGetPos, X, Y,,, ahk_class Notepad
WinGet, WinID, ID, ahk_class Notepad,,,
IfWinNotExist, ahk_class AutohotkeyGUI
{
Gui, +Owner%WinID% +Border +ToolWindow 
Gui, Show, NoActivate x%X% y%Y% w51 h431, %GuiTitle%
}
else
{
WinGetPos, Xgui, , , ,  ahk_class AutohotkeyGUI
	If Xgui<>X - 56
	WinMove, ahk_class AutohotkeyGUI,  X - 56
}
return


EvilleMonkey
  • Members
  • 39 posts
  • Last active: Jul 15 2016 01:52 PM
  • Joined: 04 Feb 2014

Very interesting GEV.  :shy: and thank you.
The code does do exactly what I was describing, however I left out some important details. The GUI should be moved around the screen independently from Notepad and let the user leave the GUI in whatever position they feel on the screen. Only when Notepad moves, the GUI moves. Another thing is Notepad isn't the program being used, another program is and sometimes it has child windows that popup. This results in the GUI then "attaching" itself to the child window. (then GUI is closed when child window is..see code below.) I've changed the code slightly to keep it from closing but the GUI still "attaches" itself to the child window, but no longer closes after child window does.. yay. I'll include additional code below I should have included in the first place  :S 

 
;; Get ID of Notepad
WinGet, WinID, ID, ahk_class Notepad,,,
SetTimer, ShowGui, 1


ShowGui:
WinWait, ahk_class Notepad
WinGetPos, X, Y,,, ahk_class Notepad
;;;;WinGet, WinID, ID, ahk_class Notepad,,,
X := X - 56
IfWinNotExist, ahk_class AutohotkeyGUI
{
;;;;Gui, +Owner%WinID% +Border +ToolWindow 
Gui, Show, NoActivate x%X% y%Y% w51 h431, %GuiTitle%
}
else
{
WinGetPos, Xgui, , , ,  ahk_class AutohotkeyGUI
If Xgui<>X - 56
WinMove, ahk_class AutohotkeyGUI,  ;X - 56
}
return


;; Correct GUI postion if needed
WinGetPos, Horz, Vert,,, %GuiTitle%


If Horz < 0
{
X := X + 843 ;58
Gui, Show, x%X% y%Y% w51 h481,%GuiTitle%
}
If Horz > 3064
{
X := X - 843 ;58
Gui, Show, x%X% y%Y% w51 h481,%GuiTitle%
}
If Vert < 0
{
Y := Y + 58
Gui, Show, x%X% y%Y% w51 h481,%GuiTitle%
}
If Vert > 620
{
Y := Y - 58
Gui, Show, x%X% y%Y% w51 h481,%GuiTitle%
}
return


SetTimer, TerminateCheck, 250


;; Close program if Notepad closes
TerminateCheck:
IfWinNotExist, ahk_id %WinID% ;ahk_class Notepad
{
Gui, Destroy
ExitApp
return
}
return

Hope I'm making sense  :/



George88
  • Members
  • 9 posts
  • Last active: Jan 08 2016 02:46 AM
  • Joined: 13 Jul 2015

Thanks so much!! Just a cherry on top of my little program. Honestly that is really cool! :)