ActiveX(HTML), how to underline a paragraph, change a sentence's background color and some words' font color Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
songdg
Posts: 699
Joined: 04 Oct 2017, 20:04

ActiveX(HTML), how to underline a paragraph, change a sentence's background color and some words' font color

01 May 2024, 11:55

I want to use teadrinker's HoverScrollbarGui()viewtopic.php?f=82&t=129423 to display some text with some features like underline, background color and font color for highlight purpose, how to do that?
teadrinker
Posts: 4562
Joined: 29 Mar 2015, 09:41
Contact:

Re: ActiveX(HTML), how to underline a paragraph, change a sentence's background color and some words' font color

01 May 2024, 17:42

Code: Select all

#Requires AutoHotkey v2

DecoratedTextGui()

DecoratedTextGui() {
    wnd := Gui()
    document := wnd.AddActiveX('w220 h130', 'HTMLFILE').Value
    document.Write('
    (
        <!DOCTYPE html>
        <html>
        <head>
            <style>
            * {
                margin: 0;
                padding: 0;
                overflow: hidden;
            }
            .sometext {
                position: absolute;
                width: 100%;
                height: 100%;
                font-family: Calibri;
                font-size: 14px;
                overflow-y: scroll;
            }
            .underline {
                text-decoration: underline;
            }
            .red-font-color {
                color: red;
            }
            .yellow-back-color {
                background-color: yellow;
            }
            </style>
        </head>
        <body>
            <div class="sometext"></div>
        </body>
        <html>
    )')
    document.getElementsByClassName('sometext').0.innerHTML := '
    ( Join
        <span class="underline">Lorem ipsum dolor sit amet,</span> consectetur adipiscing elit
        , <span class="red-font-color">sed do eiusmod tempor incididunt ut labore et dolore magna a
        liqua</span>. Ut enim ad minim veniam, <span class="yellow-back-color">quis nostrud exercitation</span> u
        llamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in volupta
        te velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sun
        t in culpa qui officia deserunt mollit anim id est laborum.
    )'
    wnd.Show()
}
This information is beyond the scope of the AHK programming language. You need knowledge of HTML and CSS to use these features. In addition, you should be aware that ActiveX HTMLFILE uses an outdated version of CSS, and not all modern features are supported.
songdg
Posts: 699
Joined: 04 Oct 2017, 20:04

Re: ActiveX(HTML), how to underline a paragraph, change a sentence's background color and some words' font color

01 May 2024, 18:39

@teadrinker
Very happy to get your answer, I run your code but encounter a problem.
Error: This value of type "HTMLDocument" has no method named "getElementsByClassName".

007: document := wnd.AddActiveX('w220 h130', 'HTMLFILE').Value
008: document.Write('<!DOCTYPE html>
<html>
<head>
<style>
* {
margin: 0;
padding: 0;
overflow: hidden;
}
.sometext {
position: absolute;
width: 100%;
height: 100%;
font-family: Calibri;
font-size: 14px;
overflow-y: scroll;
}
.underline {
text-decoration: underline;
}
.red-font-color {
color: red;
}
.yellow-back-color {
background-color: yellow;
}
</style>
</head>
<body>
<div class="sometext"></div>
</body>
<html>')
▶ 043: document.getElementsByClassName('sometext').0.innerHTML := '<span class="underline">Lorem ipsum dolor sit amet,</span> consectetur adipiscing elit, <span class="red-font-color">sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</span>. Ut enim ad minim veniam, <span class="yellow-back-color">quis nostrud exercitation</span> ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
052: wnd.Show()
053: }
teadrinker
Posts: 4562
Joined: 29 Mar 2015, 09:41
Contact:

Re: ActiveX(HTML), how to underline a paragraph, change a sentence's background color and some words' font color  Topic is solved

01 May 2024, 18:52

Try this fix:

Code: Select all

#Requires AutoHotkey v2

DecoratedTextGui()

DecoratedTextGui() {
    FixIE()
    wnd := Gui()
    document := wnd.AddActiveX('w220 h130', 'HTMLFILE').Value
    document.Write('
    (
        <!DOCTYPE html>
        <html>
        <head>
            <style>
            * {
                margin: 0;
                padding: 0;
                overflow: hidden;
            }
            .sometext {
                position: absolute;
                width: 100%;
                height: 100%;
                font-family: Calibri;
                font-size: 14px;
                overflow-y: scroll;
            }
            .underline {
                text-decoration: underline;
            }
            .red-font-color {
                color: red;
            }
            .yellow-back-color {
                background-color: yellow;
            }
            </style>
        </head>
        <body>
            <div class="sometext"></div>
        </body>
        <html>
    )')
    document.getElementsByClassName('sometext').0.innerHTML := '
    ( Join
        <span class="underline">Lorem ipsum dolor sit amet,</span> consectetur adipiscing elit
        , <span class="red-font-color">sed do eiusmod tempor incididunt ut labore et dolore magna a
        liqua</span>. Ut enim ad minim veniam, <span class="yellow-back-color">quis nostrud exercitation</span> u
        llamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in volupta
        te velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sun
        t in culpa qui officia deserunt mollit anim id est laborum.
    )'
    wnd.Show()
}

FixIE() {
    static regKey := 'HKCU\Software\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION'
    SplitPath A_IsCompiled ? A_ScriptFullPath : A_AhkPath, &exeName
    if RegRead(regKey, exeName, '') != '11000' {
        RegWrite '11000', 'REG_DWORD', regKey, exeName
    }
}
songdg
Posts: 699
Joined: 04 Oct 2017, 20:04

Re: ActiveX(HTML), how to underline a paragraph, change a sentence's background color and some words' font color

03 May 2024, 01:44

teadrinker wrote:
01 May 2024, 18:52
Try this fix:

Code: Select all

#Requires AutoHotkey v2

DecoratedTextGui()

DecoratedTextGui() {
    FixIE()
    wnd := Gui()
    document := wnd.AddActiveX('w220 h130', 'HTMLFILE').Value
    document.Write('
    (
        <!DOCTYPE html>
        <html>
        <head>
            <style>
            * {
                margin: 0;
                padding: 0;
                overflow: hidden;
            }
            .sometext {
                position: absolute;
                width: 100%;
                height: 100%;
                font-family: Calibri;
                font-size: 14px;
                overflow-y: scroll;
            }
            .underline {
                text-decoration: underline;
            }
            .red-font-color {
                color: red;
            }
            .yellow-back-color {
                background-color: yellow;
            }
            </style>
        </head>
        <body>
            <div class="sometext"></div>
        </body>
        <html>
    )')
    document.getElementsByClassName('sometext').0.innerHTML := '
    ( Join
        <span class="underline">Lorem ipsum dolor sit amet,</span> consectetur adipiscing elit
        , <span class="red-font-color">sed do eiusmod tempor incididunt ut labore et dolore magna a
        liqua</span>. Ut enim ad minim veniam, <span class="yellow-back-color">quis nostrud exercitation</span> u
        llamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in volupta
        te velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sun
        t in culpa qui officia deserunt mollit anim id est laborum.
    )'
    wnd.Show()
}

FixIE() {
    static regKey := 'HKCU\Software\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION'
    SplitPath A_IsCompiled ? A_ScriptFullPath : A_AhkPath, &exeName
    if RegRead(regKey, exeName, '') != '11000' {
        RegWrite '11000', 'REG_DWORD', regKey, exeName
    }
}
Thank you so much, I really appreciate all of your help. :bravo:

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: DavidP, Google [Bot], mikeyww, TomDonovan, vanove and 89 guests