Better understanding sliders

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Better understanding sliders

Post by Jose Hidalgo » 15 May 2021, 13:06

boiler wrote:
15 May 2021, 12:24
Do you mean you want the Go subroutine to be executed when the user clicks on those text controls? If so, you would add gGo to the options for each of those controls.
No, sorry. I forgot that the subroutine applied only to clickable things. :oops: The two text controls aren't clickable. Clicking anywhere on the GUI except on the sliders has no effect.

The GUI is small and it has only two zones : a short top line of non-clickable text info (3 sections because 3 colors : Text 1, "+" separator, Text 2), and some sliders below.
- The texts are only updated by hotkeys (a hotkey modifies a given text variable and also its color)
- The sliders are updated by hotkeys and by mouse, exactly like on page 1 (that part is perfect)

Currently all the hotkeys call a complex DisplayGui function that basically destroys the GUI and rebuilds it entirely with updated variables. I'm trying to do better. :)

I suppose what you're asking is that I do something like this :
Gui, %guiName%: Add, Text, Section c%EQColor%, v%EQText%
Gui, %guiName%: Add, Text, Section ys c%HSVColor%, v%HSVText%
That should define EQText and HSVText as variables. I guess I don't need a g-label for them, since my texts aren't clickable.
But how can I define the colors as variables too, if they already have a "c" prefix ?

After that, I can do something like this :

Code: Select all

SetText(Listener, Txt1, Col1, Txt2, Col2)
{
  guiName := Listener "Gui"
  GuiControl,, EQColor, Col1
  GuiControl,, EQText, Txt1
  GuiControl,, HSVColor, Col2
  GuiControl,, HSVText, Txt2
  Gui, %guiName%: Submit, NoHide
}

Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Better understanding sliders

Post by Jose Hidalgo » 16 May 2021, 18:51

... OK, I finally cracked it. :D It wasn't easy to understand.
I was missing several bits of info. Thankfully I could find them online after lots of searching, and put everything together.
This simple code finally does what I want, dynamically changing both the text AND its color :

Code: Select all

EQText   := "LEFT TEXT"
HSVText  := "RIGHT TEXT"
EQColor  := "Red"
HSVColor := "Red"

Gui, Font, s24, Calibri
Gui, Add, Text, Section  w300 c%EQColor% vVAR1 Right, %EQText%
Gui, Add, Text, Section ys, +
Gui, Add, Text, Section ys w400 c%HSVColor% vVAR2, %HSVText%
Gui, Show
Return

; -----------------------------------

GuiClose:
ExitApp

#a::

If (EQColor = "Red")
{
  EQColor := "Green"
  EQText  := "LONGER LEFT TEXT"
}
Else
{
  EQColor := "Red"
  EQText  := "LEFT TEXT"
}
Gui, Font, c%EQColor%
GuiControl, Font, VAR1
GuiControl,, VAR1, %EQText%

If (HSVColor = "Red")
{
  HSVColor := "Yellow"
  HSVText  := "EVEN LONGER RIGHT TEXT"
}
Else
{
  HSVColor := "Red"
  HSVText  := "RIGHT TEXT"
}
Gui, Font, c%HSVColor%
GuiControl, Font, VAR2
GuiControl,, VAR2, %HSVText%

Return
I only wish the control widths could be dynamically adjustable. Having to define w300 and w400 once and for all isn't very elegant :
  • What if the texts are user-definable and a user defines a text that's longer that the control width ?
  • What if the font size is user-definable and a user defines a very big size ?
  • What if one of the two texts is really short ? It will be a waste of space : the GUI will be much wider than needed.
I guess there must a way to auto-adjust the control width to the text width. How could I do that ? That would probably be my last question on this matter. :)
Last edited by Jose Hidalgo on 16 May 2021, 20:44, edited 1 time in total.

User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: Better understanding sliders

Post by boiler » 16 May 2021, 20:08

You can dynamically adjust the widths using GuiControl, Move. The example below resizes the width of the text control based on the length of the text to be displayed, so it's not cut off even if it's longer than the original. If you use that approach, just be conservative with the width per letter, or use a monospaced font if you need to be precise.

Code: Select all

Gui, Color, Red
Gui, Add, Text, y20 cWhite vTextCtrl, Original text
Gui, Add, Button, x100 y50 w100 gEnterNewText, Enter new text
Gui, Show, x100 y100 w300 h90, My GUI
return

EnterNewText:
	InputBox, NewText, Enter Text, Enter some new text to display:,, 485, 135
	GuiControl, Move, TextCtrl, % "w" StrLen(NewText) * 10
	GuiControl,, TextCtrl, % NewText
return

GuiClose:
ExitApp

I'm not sure what the problem is with specifying a wider width than necessary from the beginning, though. If it's because the text isn't positioned where you want, you can use the Center option for the text control and make the width very wide. Then you don't have to resize it later. Example:

Code: Select all

Gui, Color, Red
Gui, Add, Text, x0 y20 w300 Center cWhite vTextCtrl, Centered, no matter the text length
Gui, Add, Button, x100 y50 w100 gEnterNewText, Enter new text
Gui, Show, x100 y100 w300 h90, My GUI
return

EnterNewText:
	InputBox, NewText, Enter Text, Enter some new text to display:,, 485, 135
	GuiControl,, TextCtrl, % NewText
return

GuiClose:
ExitApp

Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Better understanding sliders

Post by Jose Hidalgo » 16 May 2021, 20:53

Maybe I wasn't clear enough. One solution would be dynamically adjusting the GUI width to the total text width, without having to destroy it. The GUIs in your examples don't adjust.

My text is always in the form "Text1 + Text2"
Example 1 : AAA + BBB
Example 2 : AAA + CCCCCCCCCCCCCCCCCCC
Example 3 : DDDDDDDDDD + EEEEEEEEEEEEEE
If I define static control widths, I have to define a fixed width for the left section (able to accomodate the D text which is the longest) and another fixed width for the right section (able to accomodate the C text which is the longest). Like I did in my code with w300 and w400.
My GUI would then become very large, so when only displaying AAA and BBB there would be a lot of wasted space.
Last edited by Jose Hidalgo on 16 May 2021, 21:00, edited 2 times in total.

Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Better understanding sliders

Post by Jose Hidalgo » 16 May 2021, 20:58

An alternative would be storing all predefined texts in variables, and checking which one is the longest on startup, in order to determine the GUI width once and for all.
Let's call them Mode1 to Mode3 for instance. On startup I could try to do this :

Code: Select all

Mode1 := "AAA"
Mode2 := "BBBBBBB"
Mode3 := "CCCCCCCCCCCC"
MaxWidth := 0
Loop, 3
{
  TempText := Mode%A_Index%
  Gui, Temp: +HwndGuiID
  Gui, Temp: +OwnDialogs
  Gui, Temp: -Caption +ToolWindow AlwaysOnTop
  Gui, Temp: Margin, 0, 0
  Gui, Temp: Font, s%Size%, Calibri
  Gui, Temp: Add, Text, , %TempText%
  Gui, Temp: show, hide

  DetectHiddenWindows, On
  WinGetPos,,, guiWidth
  DetectHiddenWindows, Off

  MsgBox, %guiWidth%
  If (guiWidth > MaxWidth)
    MaxWidth := guiWidth

  Gui, Temp: Destroy
}
Unfortunately that doesn't work and I can't figure out why . guiWidth seems to always be empty, it's like the window isn't detected. :wtf:

User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: Better understanding sliders

Post by boiler » 16 May 2021, 21:27

The GUI can be made to be dynamic width just by Using Gui, Show again with a new width:

Code: Select all

Gui, Color, Red
Gui, Add, Text, y20 Center cWhite vTextCtrl, Original text
Gui, Add, Button, xm y50 gEnterNewText, Change
Gui, Show, x100 y100 h90, My GUI
return

EnterNewText:
	InputBox, NewText, Enter Text, Enter some new text to display:,, 485, 135
	GuiControl, Move, TextCtrl, % "w" StrLen(NewText) * 6
	GuiControl,, TextCtrl, % NewText
	Gui, Show, % "w" StrLen(NewText) * 6 + 10
return

GuiClose:
ExitApp

Jose Hidalgo wrote: I can't figure out why . guiWidth seems to always be empty, it's like the window isn't detected. :wtf:
You haven’t specified a WinTitle to identify the GUI window in your WinGetPos command:

Code: Select all

   WinGetPos,,, guiWidth,, ahk_id %GuiID%

Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Better understanding sliders

Post by Jose Hidalgo » 17 May 2021, 06:44

Got it now. So many things to remember ! :thumbup:

This new code works, except for a centering problem.
Using the decribed method, I test the lengths of various text strings, choose the longest, and adjust the control width accordingly. So the GUI width is defined once and for all and it's always wide enough to accomodate any of the defined texts. That's great.
In this case, since EQMode3 is a long text string, the TextWidth variable value is quite big.
So of course the final result isn't centered :
2021.05.17 - 13.37.45.png
2021.05.17 - 13.37.45.png (1.47 KiB) Viewed 589 times
2021.05.17 - 13.37.55.png
2021.05.17 - 13.37.55.png (2.35 KiB) Viewed 589 times
Isn't there a way to dynamically center the whole multi-section text ? So in the first image everything would be centered.
Basidally I'd just like the dynamic text to be centered accodring to its content and regardless of the control width.
That may require dynamically adjusting the control width, and I don't know how to do it.

Code: Select all

EQMode1 := "LEFT TEXT A"
EQMode2 := "BBBBB"
EQMode3 := "Much Longer Left Text A"
HSVMode1 := "RIGHT TEXT A"
HSVMode2 := "RIGHT TEXT B"

EQText   := EQMode1
PlusText := " + "
HSVText  := HSVMode1
EQColor  := "Red"
HSVColor := "Red"

Size        := 24
TextWidth   := 0
Width       := 0
guiWidth    := 0
MinGuiWidth := 500

Loop, 3
{
  TempText := EQMode%A_Index%
  TempW    := StrLen(TempText) * 14 * Round(Size / 24, 0)
  If (TempW > TextWidth)
    TextWidth := TempW
  Gui, Temp: +HwndGuiID
  Gui, Temp: +OwnDialogs
  Gui, Temp: -Caption +ToolWindow AlwaysOnTop
  Gui, Temp: Margin, 0, 0
  Gui, Temp: Font, s%Size%, Calibri
  Gui, Temp: Add, Text, , %TempText%
  Gui, Temp: show, hide
  DetectHiddenWindows, On
  WinGetPos,,, guiWidth,, ahk_id %GuiID%
  DetectHiddenWindows, Off
  If (guiWidth > Width)
    Width := guiWidth
  Gui, Temp: Destroy
}
Width := Width + 16

If (Width < MinGuiWidth)
  Width := MinGuiWidth

Gui, +HwndGuiID
Gui, +OwnDialogs
Gui, -Caption +ToolWindow AlwaysOnTop
Gui, Margin, 0, 0

Gui, Font, s%Size%, Calibri
Gui, Add, Text, Section w%TextWidth% c%EQColor% vVAR1 Right, %EQText%
Gui, Add, Text, Section ys, %PlusText%
Gui, Add, Text, Section w200 ys c%HSVColor% vVAR2, %HSVText%
Gui, Show
Return

; -----------------------------------

#c::
ExitApp

#a::

If (EQColor = "Red")
{
  EQColor := "Yellow"
  EQText  := EQMode3
}
Else
{
  EQColor := "Red"
  EQText  := EQMode1
}
Gui, Font, c%EQColor%
GuiControl, Font, VAR1
GuiControl,, VAR1, %EQText%
; GuiControlGet, postinfo, Pos, VAR1
; newX := postinfoX - postinfoW
; GuiControl, Move, vVAR1 , x%newx%
Gui, Show
Return

#w::

If (HSVColor = "Red")
{
  HSVColor := "Green"
  HSVText  := HSVMode2
}
Else
{
  HSVColor := "Red"
  HSVText  := HSVMode1
}
Gui, Font, c%HSVColor%
GuiControl, Font, VAR2
GuiControl,, VAR2, %HSVText%
; GuiControlGet, postinfo, Pos, VAR2
; newX := postinfoX - postinfoW
; GuiControl, Move, vVAR2 , x%newx%
Gui, Show
Return

User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: Better understanding sliders

Post by boiler » 17 May 2021, 09:44

Jose Hidalgo wrote: That may require dynamically adjusting the control width, and I don't know how to do it.
As I had shown before, just use GuiControl, Move with a new w option.

You can do math on the overall length of multiple text strings and change the widths and x positions accordingly. A monospaced font is pretty much necessary to be able to predict the widths accurately. Here's a demo:

Code: Select all

Gui, Color, Black
Gui, Font, s24, Courier New ; monospaced font
Gui, Add, Text, vLeftText
Gui, Add, Text, x+0 vMiddleText
Gui, Add, Text, x+0 vRightText

loop {
	CenterTextGroup("LEFT TEXT A", "Red", " + ", "White", "RIGHT TEXT A", "Red")
	Sleep, 1500
	CenterTextGroup("Much Longer Left Text A", "Yellow", " + ", "White", "RIGHT TEXT A", "Red")
	Sleep, 1500
}
return

Esc::ExitApp

CenterTextGroup(t1, c1, t2, c2, t3, c3) {
	static w := 19
	w1 := w * StrLen(t1)
	w2 := w * StrLen(t2)
	w3 := w * StrLen(t3)
	tw := w1 + w2 + w3
	gw := tw + 40

	Gui, Font, c%c1%
	GuiControl, Font, LeftText
	GuiControl, Move, LeftText, % "w" . w1 . " x" . (lpos := (gw - tw) / 2)
	GuiControl,, LeftText, % t1

	Gui, Font, c%c2%
	GuiControl, Font, MiddleText
	GuiControl, Move, MiddleText, % "w" . w2 . " x" . (lpos + w1)
	GuiControl,, MiddleText, % t2

	Gui, Font, c%c3%
	GuiControl, Font, RightText
	GuiControl, Move, RightText, % "w" . w3 . " x" . (lpos + w1 + w2)
	GuiControl,, RightText, % t3
	
	Gui, Show, % "x" . ((A_ScreenWidth - gw) / 2) . " w " . gw, Text Demo
}

Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Better understanding sliders

Post by Jose Hidalgo » 17 May 2021, 11:52

Not to brag or anything (I'm not in ANY position to brag, lol :lol: ), but thanks to your brilliant code, I think I've managed to improve it a little. :geek:
This code seems to work perfectly, and doesn't require a monotype font (as proven by the LeftText2 full of "i"). Any font and any size will do. Everything auto-adjusts perfectly ! :D

Code: Select all

Size       := 48
LeftText1  := "LEFT TEXT A"
LeftText2  := "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"
RightText1 := "RIGHT TEXT A"
RightText2 := "RIGHT TEXT BB"

Gui, +OwnDialogs
Gui, -Caption +ToolWindow AlwaysOnTop
Gui, Margin, 0, 0
Gui, Color, Black
Gui, Font, s%Size%, Calibri
Gui, Add, Text, vLeftText Right
Gui, Add, Text, x+0 vMiddleText Center
Gui, Add, Text, x+0 vRightText Left

loop
{
  CenterTextGroup(LeftText1, "Red", " + ", "White", RightText1, "Red")
  Sleep, 1500
  CenterTextGroup(LeftText2, "Yellow", " + ", "White", RightText2, "Red")
  Sleep, 1500
}
return

Esc::ExitApp

Measurew(t1, t2, t3)
{
  global
  loop, 3
  {
    Gui, Temp: +HwndGuiID
    Gui, Temp: +OwnDialogs
    Gui, Temp: -Caption +ToolWindow AlwaysOnTop
    Gui, Temp: Margin, 0, 0
    Gui, Temp: Font, s%Size%, Calibri
    Gui, Temp: Add, Text, , % t%A_Index%
    Gui, Temp: show, hide
    DetectHiddenWindows, On
    WinGetPos,,, guiWidth,, ahk_id %GuiID%
    DetectHiddenWindows, Off
    w%A_Index% := guiWidth
    Gui, Temp: Destroy
  }
}

CenterTextGroup(t1, c1, t2, c2, t3, c3)
{
  global
  Measurew(t1, t2, t3)
  tw := w1 + w2 + w3
  gw := tw + 20

  Gui, Font, c%c1%
  GuiControl, Font, LeftText
  GuiControl, Move, LeftText, % "w" . w1 . " x" . (lpos := (gw - tw) / 2)
  GuiControl,, LeftText, % t1

  Gui, Font, c%c2%
  GuiControl, Font, MiddleText
  GuiControl, Move, MiddleText, % "w" . w2 . " x" . (lpos + w1)
  GuiControl,, MiddleText, % t2

  Gui, Font, c%c3%
  GuiControl, Font, RightText
  GuiControl, Move, RightText, % "w" . w3 . " x" . (lpos + w1 + w2)
  GuiControl,, RightText, % t3
	
  Gui, Show, % "x" . ((A_ScreenWidth - gw) / 2) . " w " . gw, Text Demo
}
Thank you so much boiler. Once more, you saved the day ! :dance: :dance: :dance:

User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: Better understanding sliders

Post by boiler » 17 May 2021, 11:57

That’s a good idea for getting the actual width of the text controls. :thumbup:

Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Better understanding sliders

Post by Jose Hidalgo » 17 May 2021, 12:30

Thank you very much Sir. Learning slowly but surely. ;)
Icing on the cake : how could I just make the GUI background completely transparent ? (only the background, not the text). I've tried several options without success :
  • Deleting the Gui, Color line for starters
  • Adding BackgroundTrans :

    Code: Select all

    Gui, Add, Text, BackgroundTrans vLeftText Right
    Gui, Add, Text, BackgroundTrans x+0 vMiddleText Center
    Gui, Add, Text, BackgroundTrans x+0 vRightText Left
    And later :

    Code: Select all

    GuiControl +BackgroundTrans, t1
    GuiControl +BackgroundTrans, t2
    GuiControl +BackgroundTrans, t3
But it doesn't work just yet.

User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: Better understanding sliders

Post by boiler » 17 May 2021, 14:00

Example:

Code: Select all

Gui, +HwndGuiID -Caption
Gui, Color, AABBCC
Gui, Font, s24
Gui, Add, Text, cYellow, Sample text
Gui, Show
WinSet, TransColor, AABBCC, ahk_id %GuiID%
return

Esc::ExitApp

Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Better understanding sliders

Post by Jose Hidalgo » 17 May 2021, 15:02

Thank you. It works, of course your example works. They always do. :mrgreen:

Except that my previous code doesn't ! :wtf: I have literally just copy/pasted the 3 relevant lines, I haven't changed anything else. It SHOULD work !
The GUI background color changes to AABBCC, but not to transparency.
That's my problem with AHK : when it doesn't work, I really don't understand why...

Code: Select all

Size       := 48
LeftText1  := "LEFT TEXT A"
LeftText2  := "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"
RightText1 := "RIGHT TEXT A"
RightText2 := "RIGHT TEXT BB"

Gui, +HwndGuiID -Caption ; ---------------------------------- I have added this one
; Gui, +OwnDialogs
; Gui, -Caption +ToolWindow AlwaysOnTop
Gui, Margin, 0, 0
Gui, Color, AABBCC ; ---------------------------------- I have added this one
Gui, Font, s%Size%, Calibri
Gui, Add, Text, vLeftText Right
Gui, Add, Text, x+0 vMiddleText Center
Gui, Add, Text, x+0 vRightText Left

loop
{
  CenterTextGroup(LeftText1, "Red", " + ", "White", RightText1, "Red")
  Sleep, 1500
  CenterTextGroup(LeftText2, "Yellow", " + ", "White", RightText2, "Red")
  Sleep, 1500
}
return

Measurew(t1, t2, t3)
{
  global
  loop, 3
  {
    Gui, Temp: +HwndGuiID
    Gui, Temp: +OwnDialogs
    Gui, Temp: -Caption +ToolWindow AlwaysOnTop
    Gui, Temp: Margin, 0, 0
    Gui, Temp: Font, s%Size%, Calibri
    Gui, Temp: Add, Text, , % t%A_Index%
    Gui, Temp: show, hide
    DetectHiddenWindows, On
    WinGetPos,,, guiWidth,, ahk_id %GuiID%
    DetectHiddenWindows, Off
    w%A_Index% := guiWidth
    Gui, Temp: Destroy
  }
  return
}

CenterTextGroup(t1, c1, t2, c2, t3, c3)
{
  global
  Measurew(t1, t2, t3)
  tw := w1 + w2 + w3
  gw := tw + 20

  Gui, Font, c%c1%
  GuiControl, Font, LeftText
  GuiControl, Move, LeftText, % "w" . w1 . " x" . (lpos := (gw - tw) / 2)
  GuiControl,, LeftText, % t1

  Gui, Font, c%c2%
  GuiControl, Font, MiddleText
  GuiControl, Move, MiddleText, % "w" . w2 . " x" . (lpos + w1)
  GuiControl,, MiddleText, % t2

  Gui, Font, c%c3%
  GuiControl, Font, RightText
  GuiControl, Move, RightText, % "w" . w3 . " x" . (lpos + w1 + w2)
  GuiControl,, RightText, % t3
	
  Gui, Show, % "x" . ((A_ScreenWidth - gw) / 2) . " w " . gw, Text Demo
  WinSet, TransColor, AABBCC, ahk_id %GuiID% ; ---------------------------------- I have added this one
  return
}

Esc::ExitApp

User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: Better understanding sliders

Post by boiler » 17 May 2021, 15:40

It's because you used the same variable to store the HWND for different GUIs so you've overwritten the one you added for the main GUI. You can change the lines with the HWND for your temp GUI in your Measurew function to this:

Code: Select all

    Gui, Temp: +HwndTempGuiID
    ; ...
    WinGetPos,,, guiWidth,, ahk_id %TempGuiID%

If you don't like the color of the fringe that's left around the letters, you could change the GUI background and transparent color from AABBCC to something else.

Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Better understanding sliders

Post by Jose Hidalgo » 18 May 2021, 12:06

Got the idea, it was indeed an ID problem. :thumbup:
This code now works, but the transparency only appears after the first iteration. It seems I just can't get it right ! :crazy:
I suppose it's because the WinSet is placed after the Gui, Show. But if I place it before, it doesn't work.
To make transparency appear from the start, I had to add two other lines after the WinSet : a Gui, Show, Hide and a new Gui, Show. But I'm sure there must be a better way. :think:

Code: Select all

Size       := 48
LeftText1  := "LEFT TEXT A"
LeftText2  := "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"
RightText1 := "RIGHT TEXT A"
RightText2 := "RIGHT TEXT BB"

Gui, +HwndGuiID
Gui, +OwnDialogs
Gui, -Caption +ToolWindow AlwaysOnTop
Gui, Margin, 0, 0
Gui, Color, 1E1E1E
Gui, Font, s%Size%, Calibri
Gui, Add, Text, vLeftText Right
Gui, Add, Text, x+0 vMiddleText Center
Gui, Add, Text, x+0 vRightText Left

loop
{
  CenterTextGroup(LeftText1, "Red", " + ", "White", RightText1, "Red")
  Sleep, 1500
  CenterTextGroup(LeftText2, "Yellow", " + ", "White", RightText2, "Red")
  Sleep, 1500
}
return

Measurew(t1, t2, t3)
{
  global
  loop, 3
  {
    Gui, Temp: +HwndTempGuiID
    Gui, Temp: +OwnDialogs
    Gui, Temp: -Caption +ToolWindow AlwaysOnTop
    Gui, Temp: Margin, 0, 0
    Gui, Temp: Font, s%Size%, Calibri
    Gui, Temp: Add, Text, , % t%A_Index%
    Gui, Temp: show, hide
    DetectHiddenWindows, On
    WinGetPos,,, guiWidth,, ahk_id %TempGuiID%
    DetectHiddenWindows, Off
    w%A_Index% := guiWidth
    Gui, Temp: Destroy
  }
  return
}

CenterTextGroup(t1, c1, t2, c2, t3, c3)
{
  global
  Measurew(t1, t2, t3)
  tw := w1 + w2 + w3
  gw := tw + 20

  Gui, Font, c%c1%
  GuiControl, Font, LeftText
  GuiControl, Move, LeftText, % "w" . w1 . " x" . (lpos := (gw - tw) / 2)
  GuiControl,, LeftText, % t1

  Gui, Font, c%c2%
  GuiControl, Font, MiddleText
  GuiControl, Move, MiddleText, % "w" . w2 . " x" . (lpos + w1)
  GuiControl,, MiddleText, % t2

  Gui, Font, c%c3%
  GuiControl, Font, RightText
  GuiControl, Move, RightText, % "w" . w3 . " x" . (lpos + w1 + w2)
  GuiControl,, RightText, % t3
	
  Gui, Show, % "x" . ((A_ScreenWidth - gw) / 2) . " w " . gw, Text Demo
  WinSet, TransColor, 1E1E1E, ahk_id %GuiID%

  return
}

Esc::ExitApp

User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: Better understanding sliders

Post by boiler » 18 May 2021, 12:24

You don’t need to use Gui, Show, Hide first. You just need to set DetectHiddenWindows, On before the WinSet command so it can find it even though it’s not shown yet.

Post Reply

Return to “Ask for Help (v1)”