question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TB_GETBUTTON does not populate tooltip button information struct

See original GitHub issue

Hi, I have created a Windows Forms application with a toolbar component which has 3 buttons. I would like to use SendMessage with TB_GETBUTTON message to fetch the first button information. Here is my code:

var tb = new ComCtl32.TBBUTTON();

var buttonCount = User32.SendMessage(mainToolbar.Handle, (uint)ComCtl32.ToolbarMessage.TB_BUTTONCOUNT, (IntPtr)0, 0);
var getButton = User32.SendMessage(mainToolbar.Handle, ComCtl32.ToolbarMessage.TB_GETBUTTON, 0, ref tb);

lblButtonCount.Text = buttonCount.ToString();
lblSuccess.Text = (getButton.ToInt32() != 0).ToString();
lblDWData.Text = tb.dwData.ToString();
lblFSStyle.Text = tb.fsStyle.ToString();
lblFSState.Text = tb.fsState.ToString();
lbliBitmap.Text = tb.iBitmap.ToString();

When I observe tb struct. all properties are zero and have not been populated even though getButton variable is 1 which means success.

The output looks like this: image

I created my own class (in naïve implementation) that looks like this:

public sealed class Win32
{
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public extern static int SendMessage(IntPtr hwnd, int msg, int wParam, int lParam);

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public extern static unsafe int SendMessage(IntPtr hwnd, int msg, int wParam, void* lParam);
}

And when I use this class in the same form like this:

var tb = new ComCtl32.TBBUTTON();

var buttonCount = Win32.SendMessage(mainToolbar.Handle, (int)ComCtl32.ToolbarMessage.TB_BUTTONCOUNT, 0, 0);

unsafe
{
    var getButton = Win32.SendMessage(mainToolbar.Handle, (int)ComCtl32.ToolbarMessage.TB_GETBUTTON, 0, &tb);
    
    lblButtonCount.Text = buttonCount.ToString();
    lblSuccess.Text = (getButton != 0).ToString();
    lblDWData.Text = tb.dwData.ToString();
    lblFSStyle.Text = tb.fsStyle.ToString();
    lblFSState.Text = tb.fsState.ToString();
    lbliBitmap.Text = tb.iBitmap.ToString();
}

It is populating the struct correctly: image

Am I missing anything here? Thanks.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
dahallcommented, Sep 28, 2022

Found the problem. I’ve committed the fix and it will go out in the next week into NuGet and within minutes on AppVeyor.

0reactions
dahallcommented, Sep 27, 2022

Thanks. I’ll look at the zip and what’s changed since 3.2.21.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TBBUTTON struct not working with SendMessage
I thought you had a means of accessing the button once you had the name. After a quick review, it appears that you...
Read more >
How to Display Tooltips for Buttons - Win32 apps
Set the tooltip text as the iString member of the TBBUTTON structure for each button. You must also send a TB_SETMAXTEXTROWS message and...
Read more >
How to Setup a Tooltip page link to a Button inste...
Solved: Hi, I have a requirement where i need to display a Tooltip page which contains info on the page that is being...
Read more >
Tooltip stuck when surrounding a disabled button #231
I think it's related to disabled buttons not firing mouse events. As a workaround you can wrap the button with an other element....
Read more >
Tooltips · Bootstrap v5.0
Documentation and examples for adding custom Bootstrap tooltips with CSS and JavaScript using CSS3 for animations and data-bs-attributes for local title ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found