Click here to Skip to main content
15,921,382 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hello, I am here today to see you about a problem that I can't solve since many days...
I created a toolbar integrated into the Windows taskbar (like windows media player).
You will find an example here: http://goo.gl/PThTD
The problem is that the toolbar should be able to communicate with another application. I then realized that I needed to use the "Windows Messaging".
I found one that normally allows me to retrieve the bar buttons (TB_GETBUTTON).
Now I can not use it.
I found a tutorial on the internet, which gives an example of use:

C++
TBBUTTON tbButton;
TBBUTTON* ipRemoteBuffer = & tbButton; // unsafe
 
for ( int i = 0 ; i < count ; i++ )
{
    User32.SendMessage(
        hToolbar,
        TB_GETBUTTON,
        ( IntPtr ) i,
        ipRemoteBuffer );
}

Now in use, you get an error because the compiler no longer allows the use of this implementation ...
I can not find what to put in the last parameter of this function to retrieve the button.
C++
User32.SendMessage (
         toolbar,
         TB_GETBUTTON,
         IndexButton
         (IntPtr) variable);

My buttons are of the "ToolBarButton" my bar and type "ToolBar".
If you have any ideas or advice or anything, I'm interested.
Thank you in advance
-
Mat29100
Posted
Updated 9-May-11 0:54am
v2

Ok, thanks you. I'll try with your solution.
But i have an other question. What is the diference between the types 'TBBUTTON' and 'ToolBarButton' ?
 
Share this answer
 
Comments
strogg 10-May-11 16:16pm    
TBBUTTON is a structure defined in the Windows API. ToolBarButton is a class in the .Net Framework. They're totally different. Since you are interoping with the API (by calling SendMessage), you'll have to define the TBBUTTON structure in C#
The last parameter should be a pointer to a TBBUTTON structure.
And the message you send retrieves the toolbar button's details through that structure.
Eg
TBBUTTON tbBtn = new TBBUTTON();
SendMessage(hToolbar, TB_GETBUTTON, i,
  tbBtn);

The TBBUTTON structure holds some info like it's state/style etc.
Check the msdn for more details on the structure & usage.

Your interop definition for the function would be
C#
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, out TBBUTTON tbBtn);


(you'll have to define the TBBUTTON structure as well)
 
Share this answer
 
v2

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