Underlining text problem Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Underlining text problem

Post by WeedTrek » 31 Dec 2020, 17:03

I'm re-creating the XP shutdown menu and have run into a difficulty. As you can see in the following image, the second sentence is underlined:
shutdownhp5.png
shutdownhp5.png (26.24 KiB) Viewed 406 times
The problem is the first sentence ends on the same line as where the second one begins. If I try x+5 for a new text control, suddenly I'm off the edge of the first control's right side.
So it's a challenge, I've hammered on ideas like using single lined text controls but there's another potential issue: other languages are supposed to populate those text controls and some of those languages are longer/shorter than english, which means these controls have to be dynamic to grow or shrink to accommodate this.
Here is what I have so far, if you fiddle for two minutes you'll see the puzzle as well. Download needed files:
underline.zip
(23.46 KiB) Downloaded 12 times
...and here is my code extract:

Code: Select all

#SingleInstance, Force
DllCall("GDI32.DLL\AddFontResourceEx", Str,"XPtahoma.ttf",UInt,(FR_PRIVATE:=0x10), Int,0)	; loads XpTahoma.ttf
SysGet, MainMonitorNumber, MonitorPrimary									; gets primary monitor id
SysGet, MainMonitor, Monitor, %MainMonitorNumber%							; gets dimensions of primary monitor
Yposition := Round(MainMonitorBottom / 4 + 391)								; divides height by 4, adds 391 to get Y position

ShutdownUpdatesText = Click Turn Off to install important updates and turn off`nyour computer. Click here to turn off without installing`nupdates.

Gui, ShutdownUpdates: New
Gui, ShutdownUpdates: Margin, 0
Gui, ShutdownUpdates: Color, Black
Gui, ShutdownUpdates: Add, Picture, x1 y0 w313 h112, Bitmap20142updates.png
Gui, ShutdownUpdates: Add, Picture, x5 y12 w16 h-1 +BackgroundTrans, ShutdownUpdates.png
Gui, ShutdownUpdates: Add, Button, x225 y84 w78 h21 gCancel, Cancel
Gui, ShutdownUpdates: Font, cWhite s12 norm, fs tahoma 8px
Gui, ShutdownUpdates: Add, Text, x26 y11 w290 h100 +BackgroundTrans, %ShutdownUpdatesText%
Gui, ShutdownUpdates: +ToolWindow -Caption +AlwaysOnTop
Gui, ShutdownUpdates: Show, y%Yposition% w315 h113, ShutdownUpdates
return


Esc::
Cancel:
DllCall("GDI32.DLL\RemoveFontResourceEx",Str,"misc\XPtahoma.ttf",UInt,(FR_PRIVATE:=0x10),Int,0)	; XpTahoma.ttf
ExitApp
User avatar
mikeyww
Posts: 27095
Joined: 09 Sep 2014, 18:38

Re: Underlining text problem  Topic is solved

Post by mikeyww » 31 Dec 2020, 17:55

I'm not sure whether this helps; perhaps has the same issue.

Code: Select all

ShutdownUpdatesText  := "Click Turn Off to install important updates and turn off`nyour computer."
ShutdownUpdatesText2 := "                                  Click here to turn off without installing`nupdates."
Gui, ShutdownUpdates:Add, Text, x26 y11 +BackgroundTrans, %ShutdownUpdatesText%
Gui, ShutdownUpdates:Add, Text, xp  y25 +BackgroundTrans, %ShutdownUpdatesText2%
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Re: Underlining text problem

Post by WeedTrek » 31 Dec 2020, 19:59

That's a way I never thought of, and yes, that would totally work if this thing were to stay in English only. I might just keep it in english for this reason alone, thanks for that :)
But Odia language for example takes up more horizontal space in a text control so unless the text controls can be dynamically resized, other languages are out... and there's support already in the rest of the scripts (shutdown and logoff) for 109 languages (including Klingon).
Another language-related problem... even if single-line controls with partial sentences in them would potentially bleed over the right-side edge of the GUI or line-break itself into a strange place, so yah it's still a puzzle. English is solved though, that's a partial solution :D
My Weed Trek video archive: http://weedtrek.ca
User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: Underlining text problem

Post by Smile_ » 01 Jan 2021, 06:35

Not so perfect but It might help

Code: Select all

#SingleInstance, Force
DllCall("GDI32.DLL\AddFontResourceEx", Str,"XPtahoma.ttf",UInt,(FR_PRIVATE:=0x10), Int,0)	; loads XpTahoma.ttf
SysGet, MainMonitorNumber, MonitorPrimary									; gets primary monitor id
SysGet, MainMonitor, Monitor, %MainMonitorNumber%							; gets dimensions of primary monitor
Yposition := Round(MainMonitorBottom / 4 + 391)								; divides height by 4, adds 391 to get Y position

ShutdownUpdatesText = Click Turn Off to install important updates and turn off`nyour computer.

Gui, ShutdownUpdates: New
Gui, ShutdownUpdates: Margin, 0
Gui, ShutdownUpdates: Color, Black
Gui, ShutdownUpdates: Add, Picture, x1 y0 w313 h112, Bitmap20142updates.png
Gui, ShutdownUpdates: Add, Picture, x5 y12 w16 h-1 +BackgroundTrans, ShutdownUpdates.png
Gui, ShutdownUpdates: Add, Button, x225 y84 w78 h21 gCancel, Cancel
Gui, ShutdownUpdates: Font, cWhite s12 norm, fs tahoma 8px
Gui, ShutdownUpdates: Add, Text, x26 y11 w290 h100 +BackgroundTrans, %ShutdownUpdatesText%
UnderlinedText = Click here to turn off without installing
Gui, ShutdownUpdates: Add, Text, x100 y24 +BackgroundTrans gApply vUText, %UnderlinedText%
Gui, ShutdownUpdates: Add, Text, x99 y36 +BackgroundTrans w186 0x10 vUText_ gApply
UnderlinedText = updates.
Gui, ShutdownUpdates: Add, Text, x26 y38 +BackgroundTrans gApply vUText__, %UnderlinedText%
Gui, ShutdownUpdates: Add, Text, x26 y50 +BackgroundTrans w43 0x10 gApply vUText___
Gui, ShutdownUpdates: +ToolWindow -Caption +AlwaysOnTop
Gui, ShutdownUpdates: Show, y%Yposition% w315 h113, ShutdownUpdates
OnMessage(0x200, "ClickIt")
Return

Apply:
    MsgBox, 36, Sure?, Are you sure about that?
    IfMsgBox, Yes
    {
        Gosub, Cancel
    }
Return

Esc::
Cancel:
    DllCall("GDI32.DLL\RemoveFontResourceEx",Str,"misc\XPtahoma.ttf",UInt,(FR_PRIVATE:=0x10),Int,0)	; XpTahoma.ttf
ExitApp

ClickIt(){
    Cursor := DllCall("LoadCursor","UInt","","Int",32649)
    If (A_GuiControl = "UText") || (A_GuiControl = "UText_") || (A_GuiControl = "UText__") || (A_GuiControl = "UText___")
        DllCall("SetCursor","UInt",Cursor)
}
ahk7
Posts: 575
Joined: 06 Nov 2013, 16:35

Re: Underlining text problem

Post by ahk7 » 01 Jan 2021, 08:53

Why not use an ActiveX control and html/css to style it? See joedf's tutorial https://www.autohotkey.com/boards/viewtopic.php?f=74&t=4588 as well
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Re: Underlining text problem

Post by WeedTrek » 01 Jan 2021, 14:32

thanks Smile_ that's handy to know and it actually works for english, but it needs to line break differently between different languages but I'll be able to use that method for other things :)
and thanks ahk7 :) I'm going to use that for other things for sure, I seem to remember doing the activeX thing for a few things years ago, but it wasn't as specific as joedf's code.
I'm going to mark mikeyww's answer as the most correct one, as the spaces placed at the beginning of the underlined section is key for allowing space on line 1 for other languages... I can customize that spacing to accurately pinpoint where on the line the second sentence can begin.
Thanks everyone for trying to crack this, I know AHK is not the most suited for these kinds of things. :D
My Weed Trek video archive: http://weedtrek.ca
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Re: Underlining text problem

Post by WeedTrek » 04 Jan 2021, 04:08

DIsregard last deleted post, I put the wrong stuff on display.
THIS is what I settled on, (with this demo there are no required files)

Code: Select all

Text34 := "Click Turn Off to install important updates and turn off`nyour computer."
Text35 := "`n	            "
Text36 := "`nClick here to turn off without installing"
Text37 := "updates."

gui, font, s12
gui, add, text, x10 y10 +BackgroundTrans, %Text34%
gui, add, text, x10 y10 +BackgroundTrans, %Text35%
gui, font, underline
gui, add, text, x+0 y10 +BackgroundTrans gLink, %Text36%
gui, add, text, x10 y+0 +BackgroundTransgLink gLink, %Text37%
gui, show
return

Link:
Gui, +OwnDialogs
MsgBox, Underlined text was clicked
return

GuiClose:
Esc::
ExitApp
Again, thanks very much you guys :) I've been adapting this to suit the different widths of languages and it works very well... the secret is the spacing in Text35
Can you tell the difference? The real XP menu is on the right (minus black border), mine is on the left.
Screenshot 2021-01-04 012340.jpg
Screenshot 2021-01-04 012340.jpg (144.75 KiB) Viewed 295 times
My Weed Trek video archive: http://weedtrek.ca
Post Reply

Return to “Ask for Help (v1)”