Create a indicator showing which window is activated
Create a indicator showing which window is activated
Hello everybody
I like to work with multiple windows open side by side, sometimes is hard to tell which windows I'm currently on since the window animation to indicate it is too subtle.
I want to create a script that helps me to visualize which window I'm currently on, it can be a simple Tooltip on the top of the window bar.
I tried to look at the documentation somewhere related to WinActivated but I wasn't able to find a solution for it
In my mind the logic would be some kind of loop that checks which window is activate and assign a Tooltip to it
Once a new window is focused the Tooltip would be removed from the old one and attached to the new one
please help =)
I like to work with multiple windows open side by side, sometimes is hard to tell which windows I'm currently on since the window animation to indicate it is too subtle.
I want to create a script that helps me to visualize which window I'm currently on, it can be a simple Tooltip on the top of the window bar.
I tried to look at the documentation somewhere related to WinActivated but I wasn't able to find a solution for it
In my mind the logic would be some kind of loop that checks which window is activate and assign a Tooltip to it
Once a new window is focused the Tooltip would be removed from the old one and attached to the new one
please help =)
Re: Create a indicator showing which window is activated
Hallo,
try:
try:
Code: Select all
#Persistent
SetTimer, active, 300
Return
active:
ToolTip, active,20,20,9
Return
Re: Create a indicator showing which window is activated
Here's another solution using an overlay, this may be a bit overkill but I enjoy messing around with gdip =P
Code: Select all
gdip_startup()
Gui -Caption +E0x80000 +AlwaysOnTop +ToolWindow +hwndoverlayhwnd
Gui,Show, NA,Window Outlines
outlineSize := 8
outlineSizeHalf := outlineSize/2
outlinePen := gdip_createpen(0xFFFF0000,outlineSize)
hdc := CreateCompatibleDC(GetDc(overlayhwnd))
hbm := CreateDibSection(a_screenWidth,-a_screenheight,hdc)
SelectObject(hdc,hbm)
g := Gdip_graphicsfromhdc(hdc)
lastWindow := 0
borderDisplayTime := 1000 ;change 1000 to 0 if you want the border to stay forever
settimer,windowCheck,10
return
windowCheck:
hwnd := WinExist("a")
if (hwnd != lastWindow) {
sleep 10
wingetpos,x,y,w,h,% "ahk_id " hwnd
rect := GetClientRect(hwnd,w,h)
gdip_graphicsclear(g)
gdip_drawrectangle(g,outlinePen,rect[1]+outlineSizeHalf,outlineSizeHalf,w-1-(outlineSizeHalf+rect[1]*2),h-1-outlineSizeHalf-rect[1])
UpdateLayeredWindow(overlayhwnd, hdc, x, y, w, h)
lastWindow := hwnd
if (borderDisplayTime > 0)
settimer,clearWindow,% -borderDisplayTime
}
return
clearWindow:
gdip_graphicsclear(g)
UpdateLayeredWindow(overlayhwnd, hdc, 0, 0, 1, 1)
return
GetClientRect(hwnd,w,h) {
VarSetCapacity(rc, 16)
DllCall("GetClientRect", "uint", hwnd, "uint", &rc)
clientWidth := NumGet(rc, 8, "int")
clientHeight := NumGet(rc, 12, "int")
borderSize := floor(((w-clientWidth) / 2))-1
topBorderSize := floor(((h-clientHeight)) - borderSize)
return [borderSize,topBorderSize]
}
/*
***********************
Gdip functions copied from tic's gdip library found here -https://github.com/tariqporter/Gdip/blob/master/Gdip.ahk
***********************
*/
ReleaseDC(hdc, hwnd=0) {
Ptr := A_PtrSize ? "UPtr" : "UInt"
return DllCall("ReleaseDC", Ptr, hwnd, Ptr, hdc)
}
SelectObject(hdc, hgdiobj) {
Ptr := A_PtrSize ? "UPtr" : "UInt"
return DllCall("SelectObject", Ptr, hdc, Ptr, hgdiobj)
}
CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0) {
Ptr := A_PtrSize ? "UPtr" : "UInt"
hdc2 := hdc ? hdc : GetDC()
VarSetCapacity(bi, 40, 0)
NumPut(w, bi, 4, "uint")
NumPut(h, bi, 8, "uint")
NumPut(40, bi, 0, "uint")
NumPut(1, bi, 12, "ushort")
NumPut(0, bi, 16, "uInt")
NumPut(bpp, bi, 14, "ushort")
hbm := DllCall("CreateDIBSection", Ptr, hdc2, Ptr, &bi, "uint", 0, A_PtrSize ? "UPtr*" : "uint*", ppvBits, Ptr, 0, "uint", 0, Ptr)
if !hdc
ReleaseDC(hdc2)
return hbm
}
CreateCompatibleDC(hdc=0) {
return DllCall("CreateCompatibleDC", A_PtrSize ? "UPtr" : "UInt", hdc)
}
GetDC(hwnd=0) {
return DllCall("GetDC", A_PtrSize ? "UPtr" : "UInt", hwnd)
}
Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h) {
Ptr := A_PtrSize ? "UPtr" : "UInt"
return DllCall("gdiplus\GdipDrawRectangle", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
}
Gdip_CreatePen(ARGB, w) {
DllCall("gdiplus\GdipCreatePen1", "UInt", ARGB, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
return pPen
}
Gdip_GraphicsClear(pGraphics, ARGB=0x00ffffff) {
return DllCall("gdiplus\GdipGraphicsClear", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", ARGB)
}
Gdip_Startup() {
Ptr := A_PtrSize ? "UPtr" : "UInt"
if !DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
DllCall("LoadLibrary", "str", "gdiplus")
VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
DllCall("gdiplus\GdiplusStartup", A_PtrSize ? "UPtr*" : "uint*", pToken, Ptr, &si, Ptr, 0)
return pToken
}
Gdip_GraphicsFromHDC(hdc) {
DllCall("gdiplus\GdipCreateFromHDC", A_PtrSize ? "UPtr" : "UInt", hdc, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
return pGraphics
}
UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255) {
Ptr := A_PtrSize ? "UPtr" : "UInt"
if ((x != "") && (y != ""))
VarSetCapacity(pt, 8), NumPut(x, pt, 0, "UInt"), NumPut(y, pt, 4, "UInt")
if (w = "") ||(h = "")
WinGetPos,,, w, h, ahk_id %hwnd%
return DllCall("UpdateLayeredWindow", Ptr, hwnd, Ptr, 0, Ptr, ((x = "") && (y = "")) ? 0 : &pt, "int64*", w|h<<32, Ptr, hdc, "int64*", 0, "uint", 0, "UInt*", Alpha<<16|1<<24, "uint", 2)
}
Some of my AHK programs: 3D Voxel Game - Platformer Game - Langton's Ant - Raycast light/Pixel Water - Creating HD map of any game
Or check out my Youtube for these plus many more projects!
Or check out my Youtube for these plus many more projects!

Re: Create a indicator showing which window is activated
Hey , thanks for solutions, both works well
I was trying to twerk the first one, instead of showing a tooltip I'm want to blink the window I'm focused on and then do nothing, unless I switch the window, then it must blink again.
Here my code:
The problem is that the active window keeps blinking nonstop, it seems to have something wrong with the If statement
What I'm trying to say with the statement is: Only if the value of these variables are different, then blink the window, otherwise do nothing
Please help, my active window is a disco party =)
I was trying to twerk the first one, instead of showing a tooltip I'm want to blink the window I'm focused on and then do nothing, unless I switch the window, then it must blink again.
Here my code:
Code: Select all
blinkWindow() {
WinGetPos, X, Y, W, H, A
Gui Color, 0xbaafaf
Gui, +AlwaysOnTop +E0x20 +LastFound +Toolwindow -Caption
Gui, Show, NoActivate h%H% w%W% x%X% y%Y%, GUIID
WinSet, Transparent, 50
Sleep, 200
Gui, Destroy
}
WinGetActiveTitle, TitleWindow
#Persistent
SetTimer, active, 300
Return
active:
WinGetActiveTitle, TitleNew
If (TitleWindow != TitleNew) {
blinkWindow()
}
Return
Code: Select all
If (Titlewindow != TitleNew)
Please help, my active window is a disco party =)
Re: Create a indicator showing which window is activated
Hallo,
try:
try:
Code: Select all
blinkWindow()
{
WinGetPos, X, Y, W, H, A
Gui, +AlwaysOnTop +E0x20 +LastFound +Toolwindow -Caption -DPIScale
Gui, Color, 0xbaafaf
WinSet, Transparent, 50
Gui, Show, NoActivate h%H% w%W% x%X% y%Y%, GUIID
Sleep, 200
Gui, Destroy
}
WinGetActiveTitle, TitleWindow
#Persistent
SetTimer, active, 300
Return
active:
WinGetActiveTitle, TitleNew
If (TitleWindow != TitleNew)
blinkWindow()
TitleWindow := TitleNew
Return
Re: Create a indicator showing which window is activated
Rohwedder wrote: ↑24 Jan 2021, 12:57Hallo,
try:Code: Select all
blinkWindow() { WinGetPos, X, Y, W, H, A Gui, +AlwaysOnTop +E0x20 +LastFound +Toolwindow -Caption -DPIScale Gui, Color, 0xbaafaf WinSet, Transparent, 50 Gui, Show, NoActivate h%H% w%W% x%X% y%Y%, GUIID Sleep, 200 Gui, Destroy } WinGetActiveTitle, TitleWindow #Persistent SetTimer, active, 300 Return active: WinGetActiveTitle, TitleNew If (TitleWindow != TitleNew) blinkWindow() TitleWindow := TitleNew Return
Re: Create a indicator showing which window is activated
Hey thanks again!!Rohwedder wrote: ↑24 Jan 2021, 12:57Hallo,
try:Code: Select all
blinkWindow() { WinGetPos, X, Y, W, H, A Gui, +AlwaysOnTop +E0x20 +LastFound +Toolwindow -Caption -DPIScale Gui, Color, 0xbaafaf WinSet, Transparent, 50 Gui, Show, NoActivate h%H% w%W% x%X% y%Y%, GUIID Sleep, 200 Gui, Destroy } WinGetActiveTitle, TitleWindow #Persistent SetTimer, active, 300 Return active: WinGetActiveTitle, TitleNew If (TitleWindow != TitleNew) blinkWindow() TitleWindow := TitleNew Return
I had found a similar solution before I checked your message
Code: Select all
blinkWindow() {
WinGetPos, X, Y, W, H, A
If %H% { ; If variable %H% there's no value, then the code below will not run
Gui Color, 0xbaafaf
Gui, +AlwaysOnTop +E0x20 +LastFound +Toolwindow -Caption
Gui, Show, NoActivate h%H% w%W% x%X% y%Y%, GUIID
WinSet, Transparent, 50
Sleep, 200
Gui, Destroy
}
}
#Persistent
SetTimer, active, 300
Return
active:
WinGet, TitleNew, ID, A
If (Titlewindow != TitleNew) {
blinkWindow()
}
WinGet, TitleWindow, ID, A
Return
I solved the problem by creating the follow if statement within windowBlink():
Code: Select all
If %H% { ; If variable %H% there's no value, then the code below will not run
....
}
Last edited by xkooll on 24 Jan 2021, 14:30, edited 2 times in total.
Re: Create a indicator showing which window is activated
Hi, I'm trying to do something very similar. Your code here works, but it also spits up an error message every time I select a different window. Specifically this error message:Rohwedder wrote: ↑24 Jan 2021, 12:57Hallo,
try:Code: Select all
blinkWindow() { WinGetPos, X, Y, W, H, A Gui, +AlwaysOnTop +E0x20 +LastFound +Toolwindow -Caption -DPIScale Gui, Color, 0xbaafaf WinSet, Transparent, 50 Gui, Show, NoActivate h%H% w%W% x%X% y%Y%, GUIID Sleep, 200 Gui, Destroy } WinGetActiveTitle, TitleWindow #Persistent SetTimer, active, 300 Return active: WinGetActiveTitle, TitleNew If (TitleWindow != TitleNew) blinkWindow() TitleWindow := TitleNew Return
https://i.imgur.com/K4kecfB.png [Mod edit: Link fixed.]
Re: Create a indicator showing which window is activated
I was having the same error, I explained how I solved on my previous message, long story short, use that instead:JamesO2 wrote: ↑24 Jan 2021, 14:12Hi, I'm trying to do something very similar. Your code here works, but it also spits up an error message every time I select a different window. Specifically this error message:Rohwedder wrote: ↑24 Jan 2021, 12:57Hallo,
try:Code: Select all
blinkWindow() { WinGetPos, X, Y, W, H, A Gui, +AlwaysOnTop +E0x20 +LastFound +Toolwindow -Caption -DPIScale Gui, Color, 0xbaafaf WinSet, Transparent, 50 Gui, Show, NoActivate h%H% w%W% x%X% y%Y%, GUIID Sleep, 200 Gui, Destroy } WinGetActiveTitle, TitleWindow #Persistent SetTimer, active, 300 Return active: WinGetActiveTitle, TitleNew If (TitleWindow != TitleNew) blinkWindow() TitleWindow := TitleNew Return
https i.imgur.com /K4kecfB.png Broken Link for safety [Mod edit: Link fixed.]
Code: Select all
blinkWindow() {
WinGetPos, X, Y, W, H, A
If %H% { ; If variable %H% there's no value, then the code below will not run
Gui Color, 0xbaafaf
Gui, +AlwaysOnTop +E0x20 +LastFound +Toolwindow -Caption
Gui, Show, NoActivate h%H% w%W% x%X% y%Y%, GUIID
WinSet, Transparent, 50
Sleep, 200
Gui, Destroy
}
}