Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
Hi,

How can I get all the button from toolbar and press the button?

I had using TB_BUTTONCOUNT to count got how many button inside my toolbar.
The result return to me is correct.
C#
string sNotifyIconClass = "NotifyIconOverflowWindow";
hwndNotify = FindWindow(sNotifyIconClass, null);

hwndNotifyChild = FindWindowEx((IntPtr)hwndNotify, IntPtr.Zero, "ToolbarWindow32", null);

Int32 iCount = Convert.ToInt32(SendMessage((int)hwndNotifyChild,TB_BUTTONCOUNT,0,IntPtr.Zero));


However, I can't retrieve each of the button inside the toolbar by using TBBUTTONINFO.
C#
TBBUTTONINFO[] buttons = new TBBUTTONINFO[iCountItem];

for (int k = 0; k < iCountItem; k++)
{
    TBBUTTONINFO ti = new TBBUTTONINFO();
    ti.dwMask = TBIF_BYINDEX | TBIF_TEXT;
    ti.cbSize = (uint)Marshal.SizeOf(ti);

    SendMessage(new HandleRef(null, hwndChild), TB_GETBUTTONINFO, (IntPtr)k, ref ti);
    buttons[k] = ti;

    Int32 iCount = SendMessage((int)hwndChild, TB_PRESSBUTTON, 0, IntPtr.Zero);

}


Please help. Thanks in advanced.
Posted
Comments
Prasad Khandekar 29-May-14 5:24am    
Please have a look at this article on CodeProject. (http://www.codeproject.com/Articles/14519/Using-Windows-APIs-from-C-again)
sandra_tay 29-May-14 20:49pm    
i had search for this article before, but is not the same situation. Because I didn't get the button from the toolbar, so I cannot send message to the button.
RDBurmon 30-May-14 11:21am    
Probably, you have to read this document and try to co-relate your code with the methods specified in the blog

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900