Attach button to other GUI

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Hiney

Attach button to other GUI

19 Oct 2017, 11:08

The goal is to get my goal button in a certain area of another window. I will use note pad for example. I would like it to show up on the notepad window every time after the help item on the top menu.

The problem is that I can force it to happen based on my screen coordinates but the minute I am elsewhere or maybe I open a notepad file not in the exact position the button is not in the right place.

I tried looking for ways to tell Show, Gui what windows coordinates to place it on (my button is my gui) but I had no luck.

Other scripts I found talk about having a button move with another window but that is way out of my skill knowledge now, it would be great but im learning.

So I am posting some sample code, if anyone can help me and tell me what I do to tell my code to place my gui not based on the coordinates on my screen but based on the notepad coordinates. If you know a easy way to move with it that would be even more amazing.

Any help I am grateful for



run, notepad.exe

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
Gui, -Caption AlwaysOnTop
Gui Font, Bold c0xFF80FF, Segoe Print
Gui Add, Button, x-1 y0 w80 h23, Goals
Gui Font

Gui Show, x650 y152 w80 h23, Window
Return

GuiEscape:
GuiClose:
ExitApp


ESC::ExitApp
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Attach button to other GUI

19 Oct 2017, 14:09

It's not the most beautiful way, and I know there's some way to attach a window to another so they move better together (it's been shared on the forums in the past), but I've used this approach before:

SetTimer to repeatedly use
WinGetPos on your target window (like Notepad)
Then do some maths to add the offsets you need to the values retrieved by WinGetPos
And then WinMove your GUI (or re Gui, Show) to the position you calculated including the offsets
return

I personally add in a check to see if my target window has even moved from last time by storing "old coordinates" and checking them against the new coordinates retrieved by WinGetPos. If any are different, I'll allow my GUI to be moved.
Hiney

Re: Attach button to other GUI

19 Oct 2017, 14:32

Thank you, that is a bit more than I can handle.

How about just basic (no moving with) just when note pad is open throw my button in the same yx I specify within notepad, not within my entire screen.

I tried looking for the syntax to do that but no luck, its also possible I do not understand the syntax im seeing mixed in with the more advanced move with scripts.

Thyanks
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Attach button to other GUI

19 Oct 2017, 15:00

Assuming no moving of Notepad, you'd do something like this:

Code: Select all

WinGetPos, x, y, , , ahk_exe notepad.exe ; I omitted height and width because we're only working on offsets from the top left corner I assume
guix:=x+300
guiy:=y+30 ; or whatever these offsets may be
Gui, Show, x%guix% y%guiy%, MyGUI
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 339 guests