Link something like toaster popup to specific window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
smbs
Posts: 98
Joined: 27 Feb 2014, 11:07

Link something like toaster popup to specific window

18 Jun 2017, 17:06

I want to create a toaster popup in a specific window at for instance top left corner that will move with the window if window is moved or resized.
Is this possible?
Many thanx
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Link something like toaster popup to specific window

18 Jun 2017, 17:27

This is how I manage moving a window, though I think a better way was shared on the forums.

Code: Select all

#Persistent ; this is a code snippet; there are otherwise hotkeys that make this script persistent

SetTimer, chatmove, 100 ; make it more frequent if you'd like it to be smoother when updating, though a higher frequency is a bit more work on the CPU
return

chatmove:
IfWinExist, fd://0 - VLC media player
    WinSetTitle, fd://0 - VLC media player,,%streamer%
IfWinNotExist, %streamer% ahk_exe vlc.exe
{
SetTimer, chatmove, Off
return
}

; So the stuff above is not necessary to the chat movement, technically


WinGetPos, x, y, w, h, %streamer% ahk_exe vlc.exe
If (x=xo) && (y=yo) && (w=wo) && (h=ho)
    return

; We get the position of the parent window that we want to tie another window to. If it has not changed, no need to do anything to the tied window.
; the vlc.exe is the parent window
; This script actually has two tied windows to one parent (three total). FirefoxLS and Twitch Emotes are the tied windows.
WinMove, ahk_pid %firefoxLS%,, % x+w, % y+emoteH, 316,% h-emoteH
WinMove, Twitch Emotes,, % x+w, % y, 316, % emoteH


; because we recognize the window has moved, we will update the "old" coordinates to the current coordinates, so we can track future changes. 
xo:=x
yo:=y
wo:=w
ho:=h
return
smbs
Posts: 98
Joined: 27 Feb 2014, 11:07

Re: Link something like toaster popup to specific window

20 Jun 2017, 14:22

Many thanx u set me on the right road and I sorted it out
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Link something like toaster popup to specific window

20 Jun 2017, 16:44

Below is an example of setting a window as a parent of a Gui.

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 will make a button on an Excel window that will then move, minimize, maximize, etc. with the parent window.

The key is DllCall("SetParent", "uint", Gui_Hwnd, "uint", Win_Hwnd).

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
smbs
Posts: 98
Joined: 27 Feb 2014, 11:07

Re: Link something like toaster popup to specific window

04 Jul 2017, 02:49

Many thanx again but is there a way of giving background colors and font color?
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Link something like toaster popup to specific window

05 Jul 2017, 11:55

smbs wrote:Many thanx again but is there a way of giving background colors and font color?
The same as you would for any GUI.

There is a Font and Color option for GUIs.

Code: Select all

	Gui,MyGUI:Color, 202020 ;background color
	Gui,MyGUI:Font, c5C5CF0 s17 wbold, Arial ; font color, size, weight, style
There are several toaster type notification scripts on the forum. Most of them make the notification popup in a location on the screen but they could probably be modified to tied to an existing window. I remember CornerNotify as one. There might be newer better ones, not sure, but a search should be able to find something.

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
smbs
Posts: 98
Joined: 27 Feb 2014, 11:07

Re: Link something like toaster popup to specific window

26 Jul 2017, 08:48

FG
Sorry --never saw your post regarding colors
Your suggestions

Code: Select all

	Gui,MyGUI:Color, 202020 ;background color
	Gui,MyGUI:Font, c5C5CF0 s17 wbold, Arial ; font color, size, weight, style
Does not seem to work unless I am missing something
Have searched the forum and found this in an old post--- see code below

Code: Select all

Gui, -Caption +e0x80 +Toolwindow
TransColor = D4D1C8
Gui, Color, %transColor%
Gui, Add, Button, x2 y2 w100 h24 , Test1
;~ Gui, Add, Button, x104 y2 w100 h24 , Test2
;~ Gui, Add, Button, x206 y2 w100 h24 , Test3
Gui, Show, x800 y500 w308 h28

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

Gui, 2:-Caption +e0x80 +Toolwindow
Gui, 2:Color, white
Gui, 2:Add, Progress, x2 y2 w100 h24    c00B050, 100 ; cFFFF66, 100
;~ Gui, 2:Add, Progress, x104 y2 w100 h24 c87BBFF, 100
;~ Gui, 2:Add, Progress, x206 y2 w100 h24 c00B050, 100
Gui, 2:Show, x800 y500 w308 h28

Return

ButtonTest1:
MsgBox You clicked Test1.
Return

ButtonTest2:
MsgBox You clicked Test2.
Return

ButtonTest3:
MsgBox You clicked Test3.
Return

Esc::ExitApp
How can I implement above code into your script you posted and change the background and font colors of the GUI?
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Link something like toaster popup to specific window

26 Jul 2017, 10:14

smbs wrote:FG
Sorry --never saw your post regarding colors
Your suggestions

Code: Select all

	Gui,MyGUI:Color, 202020 ;background color
	Gui,MyGUI:Font, c5C5CF0 s17 wbold, Arial ; font color, size, weight, style
Does not seem to work unless I am missing something
I misspoke. Font and Color does not work with buttons. Buttons are special and Windows does most of the work in creating them and uses the default colors of the theme of the window.

The code you show tries to get around this by making a button, setting its background to transparent, and then putting another Gui with a colored progress bar under it to simulate a background.

This is not a great solution but it is one of the simpler ones. There are a ton of post on the forums about making pretty buttons. Another common work around is to create a picture of a button and use Gui, Add, Picture and then make the picture respond to mouse clicks.

But your original post was about a toaster popup, if you don't actually need a button, then you can just use a text Gui. I only used a button as an example because it is what I had in one of my scripts that I could easily copy and paste to show how to "link" a Gui to a window.

This will add a simple text box with green background and red text.

Code: Select all

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

; Gui Create
Gui, Color, Green
Gui, Font, s12 cRed, Bold Verdana
Gui, Add, Text,, This is Text
Gui, +LastFound +ToolWindow +AlwaysOnTop -Caption -Border HWNDGui_Hwnd
DllCall("SetParent", "uint", Gui_Hwnd, "uint", Win_Hwnd)
Gui, Show, x200 y100
return

Esc::ExitApp
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
smbs
Posts: 98
Joined: 27 Feb 2014, 11:07

Re: Link something like toaster popup to specific window

26 Jul 2017, 10:34

Many thanx thats exactly what I needed
smbs
Posts: 98
Joined: 27 Feb 2014, 11:07

Re: Link something like toaster popup to specific window

12 May 2020, 04:57

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
The above code has been working for me since first posted using vlc media player- I want to use it with mpv media player however it does not work when I input the correct mpv parameters into first line of script-the script runs but no popup is seen---why is mpv behavior different from other media apps?
Many thanx

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 121 guests