Can I color a Tooltip and Msgbox? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Can I color a Tooltip and Msgbox?

Post by LAPIII » 28 Jan 2022, 19:09

Is it possible to color the background and text. If so, I would like the scripts with the backgrounds to be teal, the hexadecimal color value is #008080, and have text to be green, the hexadecimal color value is #00FF00.

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

Re: Can I color a Tooltip and Msgbox?

Post by mikeyww » 28 Jan 2022, 19:17

Code: Select all

box("Message", "It worked.", "Red", 8080)
box("Message #2", "It worked again.", "Black", "Red")
box("Message #3", "It worked yet again.")

box(ttitle, ttext, textColor := "Black", bkg := "White") {
 Gui, Box:New,, %ttitle%
 Gui, Font, s10 c%textColor%
 Gui, Color, %bkg%
 Gui, Add, Text,, %ttext%
 Gui, Add, Button, w250 Default, OK
 Gui, Show
 WinWaitClose, %ttitle% ahk_class AutoHotkeyGUI
 Return
 BoxButtonOK:
 Gui, Destroy
 Return
}

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Can I color a Tooltip and Msgbox?

Post by LAPIII » 29 Jan 2022, 13:42

This is awesome, but how can I make this Tooltips?

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Can I color a Tooltip and Msgbox?

Post by BoBo » 29 Jan 2022, 14:15

Searching the forum?
viewtopic.php?t=4350

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Can I color a Tooltip and Msgbox?

Post by LAPIII » 29 Jan 2022, 16:45

The code is confusing me :? . Please make a simple script.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Can I color a Tooltip and Msgbox?

Post by BoBo » 29 Jan 2022, 17:43

Simply remove the caption and border from the GUI and you'll have a ToolTip-look-alike.

scriptor2016
Posts: 854
Joined: 21 Dec 2015, 02:34

Re: Can I color a Tooltip and Msgbox?  Topic is solved

Post by scriptor2016 » 30 Jan 2022, 00:37

found this script from Lexikos.

Code: Select all


z::
ToolTipColor("Red", "Yellow")
Tooltip, This Is A Colored Tooltip
sleep, 2000
Tooltip,
Return



; ToolTipOpt v1.004
; Changes:
;  v1.001 - Pass "Default" to restore a setting to default
;  v1.002 - ANSI compatibility
;  v1.003 - Added workarounds for ToolTip's parameter being overwritten
;           by code within the message hook.
;  v1.004 - Fixed text colour.
 
ToolTipFont(Options := "", Name := "", hwnd := "") {
    static hfont := 0
    if (hwnd = "")
        hfont := Options="Default" ? 0 : _TTG("Font", Options, Name), _TTHook()
    else
        DllCall("SendMessage", "ptr", hwnd, "uint", 0x30, "ptr", hfont, "ptr", 0)
}
 
ToolTipColor(Background := "", Text := "", hwnd := "") {
    static bc := "", tc := ""
    if (hwnd = "") {
        if (Background != "")
            bc := Background="Default" ? "" : _TTG("Color", Background)
        if (Text != "")
            tc := Text="Default" ? "" : _TTG("Color", Text)
        _TTHook()
    }
    else {
        VarSetCapacity(empty, 2, 0)
        DllCall("UxTheme.dll\SetWindowTheme", "ptr", hwnd, "ptr", 0
            , "ptr", (bc != "" && tc != "") ? &empty : 0)
        if (bc != "")
            DllCall("SendMessage", "ptr", hwnd, "uint", 1043, "ptr", bc, "ptr", 0)
        if (tc != "")
            DllCall("SendMessage", "ptr", hwnd, "uint", 1044, "ptr", tc, "ptr", 0)
    }
}
 
_TTHook() {
    static hook := 0
    if !hook
        hook := DllCall("SetWindowsHookExW", "int", 4
            , "ptr", RegisterCallback("_TTWndProc"), "ptr", 0
            , "uint", DllCall("GetCurrentThreadId"), "ptr")
}
 
_TTWndProc(nCode, _wp, _lp) {
    Critical 999
   ;lParam  := NumGet(_lp+0*A_PtrSize)
   ;wParam  := NumGet(_lp+1*A_PtrSize)
    uMsg    := NumGet(_lp+2*A_PtrSize, "uint")
    hwnd    := NumGet(_lp+3*A_PtrSize)
    if (nCode >= 0 && (uMsg = 1081 || uMsg = 1036)) {
        _hack_ = ahk_id %hwnd%
        WinGetClass wclass, %_hack_%
        if (wclass = "tooltips_class32") {
            ToolTipColor(,, hwnd)
            ToolTipFont(,, hwnd)
        }
    }
    return DllCall("CallNextHookEx", "ptr", 0, "int", nCode, "ptr", _wp, "ptr", _lp, "ptr")
}
 
_TTG(Cmd, Arg1, Arg2 := "") {
    static htext := 0, hgui := 0
    if !htext {
        Gui _TTG: Add, Text, +hwndhtext
        Gui _TTG: +hwndhgui +0x40000000
    }
    Gui _TTG: %Cmd%, %Arg1%, %Arg2%
    if (Cmd = "Font") {
        GuiControl _TTG: Font, %htext%
        SendMessage 0x31, 0, 0,, ahk_id %htext%
        return ErrorLevel
    }
    if (Cmd = "Color") {
        hdc := DllCall("GetDC", "ptr", htext, "ptr")
        SendMessage 0x138, hdc, htext,, ahk_id %hgui%
        clr := DllCall("GetBkColor", "ptr", hdc, "uint")
        DllCall("ReleaseDC", "ptr", htext, "ptr", hdc)
        return clr
    }
}

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Can I color a Tooltip and Msgbox?

Post by BoBo » 30 Jan 2022, 07:06

A simple script, indeed. :shifty: :lol:

Post Reply

Return to “Ask for Help (v1)”