How to change text color and allow click-through in small Gui? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
V0RT3X
Posts: 236
Joined: 20 May 2023, 21:59
Contact:

How to change text color and allow click-through in small Gui?

Post by V0RT3X » 02 Apr 2024, 07:37

The below is a simple volume display I am wanting to keep on the system tray and it works well.
My ask is can anyone direct me on hot to modify this to show the volume percent in Red if the volume is muted,
or even better, the word Mute in red instead of a volume level percentage?
And also if possible, to make the mini Gui click-through? At the moment I have it over the notification center,
but ideally I would like to place it as an overlay on the volume icon, but still be able to click the volume to change it.
My attempts at using GuiControl and the various examples I've found of +E0x20 have been fruitless.

image.png
image.png (8.19 KiB) Viewed 89 times

Code: Select all

GWide := A_ScreenWidth - 50
GHigh := A_ScreenHeight - 40

SetTimer, ShowVol, 500

Gui, 
    +AlwaysOnTop
    -Caption
    +Border
Gui, Color, 1B1F21
GUI, Margin, 3, 2

Gui, Font, s10 cFFFFFF, Calibri
Gui, Add, Text, x5 y5, VOL :

Gui, Font, s11 cLIME, Calibri
Gui, Add, Text, x5 y18 w45 vVolumeText, 

Gui, Show, x%GWide% y%GHigh% w45 h40, Vol-Level
;    OnMessage(0x0201, "WM_LBUTTONDOWNdrag") ; In case display is needed to move.
    SetTimer, UpdateVolume, 500
Return

UpdateVolume:
    SoundGet, Volume
    VolumePercentage := Round(Volume)
    GuiControl,, VolumeText, %VolumePercentage% `%
Return

ShowVol:
Gui, Show, NA, Vol-Level
Return

User avatar
mikeyww
Posts: 27009
Joined: 09 Sep 2014, 18:38

Re: How to change text color and allow click-through in small Gui?

Post by mikeyww » 02 Apr 2024, 08:12

Code: Select all

#Requires AutoHotkey v1.1.33.11
WS_EX_TRANSPARENT := 0x20
Gui % "+AlwaysOnTop +LastFound +E" WS_EX_TRANSPARENT
Gui Font, cBlue
Gui Add, Text, w200 vtxt1, TEST
Gui Show, x200 y0 NoActivate
WinSet Transparent, 190
Sleep 1000
SoundBeep 1500
Gui Font, cRed
GuiControl Font, txt1

User avatar
V0RT3X
Posts: 236
Joined: 20 May 2023, 21:59
Contact:

Re: How to change text color and allow click-through in small Gui?

Post by V0RT3X » 02 Apr 2024, 08:26

Thank you @mikeyww, you always come up with creative ways.
This should definitely get me straightened out with this. Many Thanks!!

User avatar
V0RT3X
Posts: 236
Joined: 20 May 2023, 21:59
Contact:

Re: How to change text color and allow click-through in small Gui?

Post by V0RT3X » 02 Apr 2024, 09:04

Okay, so while your test script works exactly as anticipated, when I try adapting to what I have I still can't click-through.
I managed to get this to say Mute if the volume is all the way down, but still in the color lime and the preference would be
any time the volume is muted regardless of level, that it showed Mute in red. I'm assuming it's placement issues, but honestly I have no idea.
My modified attempt below if you can point out where I'm messing this up?

Code: Select all

GWide := A_ScreenWidth - 50
GHigh := A_ScreenHeight - 40
WS_EX_TRANSPARENT := 0x20 	 ;; WS_EX_ Click-Thru

SetTimer, ShowVol, 500

Gui % "+AlwaysOnTop -Caption +Border +ToolWindow +E" WS_EX_TRANSPARENT 	 ;; WS_EX_ Click-Thru

Gui, Color, 1B1F21
GUI, Margin, 3, 2

Gui, Font, s10 cFFFFFF, Calibri
Gui, Add, Text, x5 y5, VOL :

Gui, Font, s11 cLIME, Calibri
Gui, Add, Text, x5 y18 w45 vVolumeText, 

Gui, Show, x%GWide% y%GHigh% w45 h40, Vol-Level
WinSet Transparent, 255 	 ;; WS_EX_ Click-Thru
;    OnMessage(0x0201, "WM_LBUTTONDOWNdrag") ; In case display is needed to move.
    SetTimer, UpdateVolume, 500
Return

UpdateVolume:
    SoundGet, Volume
    VolumePercentage := Round(Volume)
    if (Volume == 0) {
        GuiControl, -Redraw, VolumeText
            Gui, Font, cRed
            GuiControl Font, vVolumeText
        GuiControl, +Redraw, VolumeText
        GuiControl,, VolumeText, Mute 	;; Muted
    }
    else {
        GuiControl, -Redraw, VolumeText
        GuiControl, Font, cLime
        GuiControl, +Redraw, VolumeText
        GuiControl,, VolumeText, %VolumePercentage% `% 	 ;; Not Muted
    }
Return

ShowVol:
Gui, Show, NA, Vol-Level
Return

User avatar
mikeyww
Posts: 27009
Joined: 09 Sep 2014, 18:38

Re: How to change text color and allow click-through in small Gui?

Post by mikeyww » 02 Apr 2024, 10:03

If the v option is vVolumeText, then the control ID should be VolumeText rather than vVolumeText, right?

tabr3
Posts: 11
Joined: 25 Feb 2024, 04:06

Re: How to change text color and allow click-through in small Gui?

Post by tabr3 » 02 Apr 2024, 10:18

Code: Select all

SetTimer, ShowVol, 500

GWide := A_ScreenWidth - 50
GHigh := A_ScreenHeight - 40

Gui +AlwaysOnTop -Caption +Border +ToolWindow +LastFound 

Gui, Color, 1B1F21
GUI, Margin, 3, 2

Gui, Font, s10 cFFFFFF, Calibri
Gui, Add, Text, x5 y5, VOL :

Gui, Font, s11 cLIME, Calibri
Gui, Add, Text, x5 y18 w45 vVolumeText, 

Gui, Show, x%GWide% y%GHigh% w45 h40 NoActivate, Vol-Level
WinSet Transparent, 255 	 ;; WS_EX_ Click-Thru
WinSet ExStyle, +0x20 
SetTimer, UpdateVolume, 500
Return

UpdateVolume:
SoundGet, Volume
VolumePercentage := Round(Volume)
if (VolumePercentage = 0) {
Gui, font, Cred
GuiControl, Font, volumetext
GuiControl,, VolumeText, MUTE
return
}

Gui, font, cLIME
GuiControl, Font, volumetext
GuiControl,, VolumeText, %VolumePercentage% `%
Return

ShowVol:
Gui, Show, NA, Vol-Level
Return
Sorry for any interruption. Here is my verison by mixing all of our codes.
One thing that bothers me is that you need to set a timer to force "showvol" to stay on top. Is there a better way to do it? Also, keeping it "show" every 500ms (using a timer) without destroying the "old" one, will it be a problem?

User avatar
V0RT3X
Posts: 236
Joined: 20 May 2023, 21:59
Contact:

Re: How to change text color and allow click-through in small Gui?

Post by V0RT3X » 02 Apr 2024, 10:44

Ugg... something so small. Thank you for spotting that.
So now if volume level is Zero the display shows Mute in red as wanted, but when raising the volume above Zero again it stays red.
Shouldn't the 'else' in this script show the volume % in lime again once it goes to One or above?

Code: Select all

UpdateVolume:
    SoundGet, Volume
    VolumePercentage := Round(Volume)
    if (Volume == 0) {
        GuiControl, -Redraw, VolumeText
            Gui, Font, cRed
            GuiControl Font, VolumeText
        GuiControl, +Redraw, VolumeText
        GuiControl,, VolumeText, Mute 	;; Muted
    }
    else {
        GuiControl, -Redraw, VolumeText
        GuiControl, Font, cLime
        GuiControl, +Redraw, VolumeText
        GuiControl,, VolumeText, %VolumePercentage% `% 	 ;; Not Muted
    }
Return

User avatar
mikeyww
Posts: 27009
Joined: 09 Sep 2014, 18:38

Re: How to change text color and allow click-through in small Gui?  Topic is solved

Post by mikeyww » 02 Apr 2024, 10:56

I see. The magical solution is to examine the documentation. The section that you want is the following one.

https://www.autohotkey.com/docs/v1/lib/GuiControl.htm#Font

You will notice two commands there. That is what you want. An example of these two commands is provided in the script that you have written and posted, on lines 6 and 7.

User avatar
V0RT3X
Posts: 236
Joined: 20 May 2023, 21:59
Contact:

Re: How to change text color and allow click-through in small Gui?

Post by V0RT3X » 02 Apr 2024, 12:05

I think I need some sleep. I shouldn't be making these kinds of mistakes.

Code: Select all

; THIS
Gui, Font, cLime
GuiControl, Font, VolumeText

; NOT THIS
GuiControl, Font, cLime
Paying attention to the details matters!
Sorry for taking up your time with my carelessness!

Seriously, Thank you VERY much!!

Post Reply

Return to “Ask for Help (v1)”