Anchoring Two GUI Windows together

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
canisdibellum
Posts: 47
Joined: 09 Oct 2014, 11:44

Anchoring Two GUI Windows together

23 Jun 2016, 14:43

I've really been wanting to implement Colored buttons on the GUI for this project I've been working on for over a year.
I found a solution that looks great here, posted by noonz78: https://autohotkey.com/board/topic/19694-color-buttons/
The problem is, it relies on 2 overlaying windows and being set to always on top.
That means the window(s) cannot be moved or it breaks, it also means that another window can be slid in between them.

I've been trying to come up with a way to "anchor" or "dock" the two windows together so they can be moved, deactivated, minimized/maximized, and otherwise resized.

Any help would be greatly appreciated...I know the topic of colored buttons has been circulating the forums for years (this post is from 2007) but I've yet to find one as good-looking as this one. There just seems to be one more hurdle to jump before I can implement.

hopefully the newer versions of AHK have support for something that will work that I'm not aware of and have not been able to find. (I'm woefully uninformed about messages and DLL calls.

Again, this is NOT my creation I had nothing to do with it, I just found it and liked it and am hoping I can figure a way to implement it because the end result looks like exactly what I've been hoping for.

Code: Select all

;~ https://autohotkey.com/board/topic/19694-color-buttons/
;~ Posted By noonz78

;General Window Settings
Gui, Font, s11 w700
Gui, -Caption +E0x200 +ToolWindow
TransColor = D4D1C8
Gui, Color, %TransColor%  ; This color will be made transparent later below.

bgColor = White ; Background color
;Button number, as found using the number pad
Seven = x10 y10 w100 h100 cWhite
Eight = x120 y10 w100 h50 cBlue
Nine = x230 y10 w100 h100 cRed
Four = x10 y120 w100 h100 c6698cb
Five = x120 y120 w100 h100 cFFC128
Six = x230 y120 w100 h100 c90D8EF
One = x10 y230 w100 h100 cf7f7e8
Two = x120 y230 w100 h100 c99cc99
Three = x230 y230 w100 h100 ceeee22

Gui, Add, Button, %Seven%, Drudge
Gui, Add, Button, %Eight%, MSNBC
Gui, Add, Button, %Nine%, Close
Gui, Add, Button, %Four%, MySpace
Gui, Add, Button, %Five%, YAHOO
Gui, Add, Button, %Six%, AutoHotKey
Gui, Add, Button, %One%, EHR
Gui, Add, Button, %Two%, WebPortal
Gui, Add, Button, %Three%, AD
Gui, Show, x400 y400 h340 w340

WinGet, k_ID, ID, A   ; Get its window ID.
WinSet, AlwaysOnTop, On, ahk_id %k_ID%
WinSet, TransColor, %TransColor% 170, ahk_id %k_ID%

Gui, 2:-Caption +E0x200 +ToolWindow
Gui, 2:Color, %bgColor% ; Set background color here

Gui, 2:Add, Progress, %Seven%, 100
Gui, 2:Add, Progress, %Eight%, 100
Gui, 2:Add, Progress, %Nine%, 100
Gui, 2:Add, Progress, %Four%, 100
Gui, 2:Add, Progress, %Five%, 100
Gui, 2:Add, Progress, %Six%, 100
Gui, 2:Add, Progress, %One%, 100
Gui, 2:Add, Progress, %Two%, 100
Gui, 2:Add, Progress, %Three%, 100
Gui, 2:Show, x400 y400 h340 w340
Return

ButtonClose:
ExitApp

ButtonAutoHotKey:
Run, http://www.autohotkey.com/
ExitApp

ButtonYahoo:
Run, http://www.yahoo.com/
ExitApp

ButtonMySpqace:
;Insert autologin code here
ExitApp

ButtonMSNBC:
Run, http://www.msnbc.com
ExitApp

ButtonDrudge:
Run, http://www.drudgereport.com
ExitApp

ButtonAD:
Run, mmc %systemroot%\system32\dsa.msc
WinWait, Active Directory Users and Computers, Active Directory Use
GoSub, LastFoundWindow
Send, {ALTDOWN}ai{ALTUP}
WinWait, Find Users`, Contacts`, and Groups, Select the storage f
GoSub, LastFoundWindow
Send, {SHIFTDOWN}{INS}{SHIFTUP}{ENTER}
Sleep 100
Send, {SPACE}{ALTDOWN}f{ALTUP}
Sleep 200
Send, r
ExitApp

LastFoundWindow: ;Duh
IfWinNotActive  ;automatically uses Last Found Window
    WinActivate  ;automatically uses Last Found Window
WinWaitActive  ;automatically uses Last Found Window
Return

StatusWaitDone: ; Used to wwait for a webpage to load before conintue
   SLEEP 100
   AHKID := WinExist("A")
   Ctr=0
   Loop
      {
      Sleep, 10
      Ctr+=1
      ControlGet, Progress, Visible,, msctls_progress321, ahk_id %AHKID%
      If (Progress=1)
         {
         Ctr=0
         Continue
         }
      If (Progress=0 AND Ctr>10)
      Break
      }
      StatusBarWait, Done, 10 
      RETURN
punchin
Posts: 439
Joined: 17 Jan 2014, 17:54

Re: Anchoring Two GUI Windows together

23 Jun 2016, 17:01

I just go in paint and build custom buttons. On click, replace with pressed image. On unlike put it back to up image and use a gLabel to process the "button" click.
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: Anchoring Two GUI Windows together

23 Jun 2016, 18:15

If you are looking at anchoring a AHK Gui button to another window, below is example code of attaching a child button to a parent window of Excel.

Code: Select all

Win_Hwnd := WinExist("ahk_exe excel.exe ahk_class XLMAIN")

; Gui Create
Gui, Font, s12, Bold Verdana
Gui, Margin, 0, 0
Gui, Add, Button, xp yp Default gButton, CHILD BUTTON
Gui, +LastFound +ToolWindow +AlwaysOnTop -Caption -Border HWNDGui_Hwnd
DllCall("SetParent", "uint", Gui_Hwnd, "uint", Win_Hwnd)
Gui, Show, x200 y0, Child Button
return

Button:
	MsgBox CRY
return
This child button will then move with its parent window.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
canisdibellum
Posts: 47
Joined: 09 Oct 2014, 11:44

Re: Anchoring Two GUI Windows together

23 Jun 2016, 20:02

FanaticGuru wrote:If you are looking at anchoring a AHK Gui button to another window, below is example code of attaching a child button to a parent window of Excel.

Code: Select all

Win_Hwnd := WinExist("ahk_exe excel.exe ahk_class XLMAIN")

; Gui Create
Gui, Font, s12, Bold Verdana
Gui, Margin, 0, 0
Gui, Add, Button, xp yp Default gButton, CHILD BUTTON
Gui, +LastFound +ToolWindow +AlwaysOnTop -Caption -Border HWNDGui_Hwnd
DllCall("SetParent", "uint", Gui_Hwnd, "uint", Win_Hwnd)
Gui, Show, x200 y0, Child Button
return

Button:
	MsgBox CRY
return
This child button will then move with its parent window.

FG
Ho...lee...crap....I think i can use that! as always I much appreciate the help! Thank you so much!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: bobstoner289, peter_ahk and 320 guests