StatusBar SBARS_TOOLTIPS

Get help with using AutoHotkey and its commands and hotkeys
User avatar
TheDewd
Posts: 1340
Joined: 19 Dec 2013, 11:16
Location: USA

StatusBar SBARS_TOOLTIPS

01 Mar 2017, 13:34

I'm not able to apply the following style to my StatusBar control: SBARS_TOOLTIPS (0x800)
Displays a tooltip when the mouse hovers over a part of the status bar that: 1) has too much text to be fully displayed; or 2) has an icon but no text.

The text of the ToolTip can be set via:
Gui +LastFound
SendMessage, 0x410, 0, "Text to display", msctls_statusbar321
https://autohotkey.com/docs/misc/Styles.htm#StatusBar

I'm trying with the following code, however the Tooltip only displays the first letter of the text. For example, "Sample Text" shown in the SendMessage command will only display "S" in the Tooltip.

Code: Select all

Gui, Add, StatusBar, vStatusBar gStatusBar 0x800, Very Long Text Very Long Text Very Long Text Very Long Text Very Long Text Very Long Text Very Long Text Very Long Text

StatusBar() {
    Global
    SendMessage, 0x410, 0, "Sample Tooltip", msctls_statusbar321, ahk_id %ScanGui%
}
What am I doing wrong?
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
User avatar
jNizM
Posts: 2508
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: StatusBar SBARS_TOOLTIPS

02 Mar 2017, 03:17

Code: Select all

; GLOBAL SETTINGS ===============================================================================================================

#NoEnv
#SingleInstance Force
SetBatchLines -1

; GUI ===========================================================================================================================

Gui, Margin, 5, 5
Gui, Add, Edit, xm ym w300 h300 0x800
Gui, Add, StatusBar, 0x800 hWndhMySB
Gui, Show, AutoSize

SB_SetParts(75)
SB_SetText("Short Text", 1)
SB_SetText("Very Long Text Very Long Text Very Long Text Very Long Text Very Long Text", 2)

SB_SETTIPTEXT(hMySB, "Sample ToolTip", 1)
return

; FUNCTIONS =====================================================================================================================

SB_SETTIPTEXT(handle, msg, index := 0) ; zero-based part index (0 - xxx)
{
    static WM_USER := 0x0400
    static SB_SETTIPTEXTA := WM_USER + 0x10   ; Ansi     -> 0x0410
    static SB_SETTIPTEXTW := WM_USER + 0x11   ; Unicode  -> 0x0411

    DllCall("user32.dll\SendMessage", "ptr", handle, "uint", SB_SETTIPTEXTW, "ptr", index, "ptr", &msg)
}

; EXIT ==========================================================================================================================

GuiEscape:
GuiClose:
ExitApp

; ===============================================================================================================================

Ref:
SBARS_TOOLTIPS (msdn)
SB_SETTIPTEXT message (msdn)
CommCtrl.h wrote:

Code: Select all

#define SB_SETTIPTEXTA          (WM_USER+16)
#define SB_SETTIPTEXTW          (WM_USER+17)

Added Suggestions on documentation improvements
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
TheDewd
Posts: 1340
Joined: 19 Dec 2013, 11:16
Location: USA

Re: StatusBar SBARS_TOOLTIPS

02 Mar 2017, 09:17

@jNizM,

Thank you!

I modified the function to automatically choose ANSI or Unicode. Also, the index is no longer zero-based.

Code: Select all

Gui, Margin, 10, 10
Gui, Add, StatusBar, 0x800 HWNDhStatusBar
Gui, Show, w400 h200, Example

SB_SetParts(100)
SB_SetText("Part 1 Text", 1)
SB_SetText("Part 2 Text Part 2 Text Part 2 Text Part 2 Text Part 2 Text Part 2 Text Part 2 Text Part 2 Text Part 2 Text", 2)

SB_SETTIPTEXT(hStatusBar, "Sample ToolTip", 2)
return

SB_SETTIPTEXT(Handle, Text, Part := 1) {
    DllCall("User32.dll\SendMessage", "Ptr", Handle, "UInt", 1040 + (A_IsUnicode ? 1 : 0), "Ptr", Part - 1, "Ptr", &Text)
}
To automatically set the text and ToolTip at the same time, I created the function below: SB_SetTextWithTip()

Code: Select all

SB_SetTipText(Handle, Text, Part := 1) {
    DllCall("User32.dll\SendMessage", "Ptr", Handle, "UInt", 1040 + (A_IsUnicode ? 1 : 0), "Ptr", Part - 1, "Ptr", &Text)
}

SB_SetTextWithTip(Handle, Text, Part := 1, Style := 0) {
    SB_SetText(Text, Part, Style)
    SB_SetTipText(%Handle%, Text, Part)
}
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
iPhilip
Posts: 422
Joined: 02 Oct 2013, 12:21

Re: StatusBar SBARS_TOOLTIPS

06 Oct 2017, 14:44

Hi TheDewd,

It turns out that the ToolTip doesn't show up correctly if it contains tabs, as used to center or right-justify the text. Below is an updates version of the SB_SetTipText() function that addresses that problem:

Code: Select all

SB_SetTipText(Handle, Text, Part := 1) {
   Text := RegExReplace(Text, "`t")
   DllCall("User32.dll\SendMessage", "Ptr", Handle, "UInt", 1040 + (A_IsUnicode ? 1 : 0), "Ptr", Part - 1, "Ptr", &Text)
}
Also, the SB_SetTextWithTip() function contains an error: %Handle% should be Handle. Below is the corrected function:

Code: Select all

SB_SetTextWithTip(Handle, Text, Part := 1, Style := 0) {
    SB_SetText(Text, Part, Style)
    SB_SetTipText(Handle, Text, Part)
}
Cheers!
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
User avatar
SKAN
Posts: 384
Joined: 29 Sep 2013, 16:58

Re: StatusBar SBARS_TOOLTIPS

08 Oct 2018, 11:07

Thank you both!.
Same problem and googled for "Status bar tooltip 0x410" and this is the second result.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Bort P, flyingDman and 211 guests