Win32 toolbar tooltip problem...

Started by
4 comments, last by Noods 14 years, 11 months ago
I have a toolbar with two buttons on which I would like to add tool tips. I have implemented the code off of the MSDN but I cannot get the tool tips to function Can someone have a look at this code for me? From my resource file:

/////////////////////////////////////////////////////////////////////////////
//
// String Table
//

STRINGTABLE
BEGIN
   IDS_OPEN_TOOLTIP    "Open"
   IDS_CLOSE_TOOLTIP   "Close"
END

#endif

Creating the toolbar

//Tool bar
TBBUTTON tbbToolBarButtons[NUMBEROFTOOLBARBUTTONS];   //Tool bar button structure
TBADDBITMAP tbabToolBarBitmap;   //Tool bar add bitmap structure

SendMessage(hButton[IDC_MAIN_TOOLBAR], TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);   //Send TB_BUTTONSTRUCTSIZE for backward compatibility

tbabToolBarBitmap.hInst = HINST_COMMCTRL;                                              //Set the handle of the common control 
tbabToolBarBitmap.nID = IDB_STD_SMALL_COLOR;                                           //Set the bitmap to be loaded
SendMessage(hButton[IDC_MAIN_TOOLBAR], TB_ADDBITMAP, 0, (LPARAM)&tbabToolBarBitmap);   //Load the images

ZeroMemory(tbbToolBarButtons, sizeof(tbbToolBarButtons));   //Zero the tbbToolBarButtonsUTTON structure
tbbToolBarButtons[0].iBitmap = STD_FILEOPEN;                //Set the button bitmap
tbbToolBarButtons[0].fsState = TBSTATE_ENABLED;             //Set the state
tbbToolBarButtons[0].fsStyle = TBSTYLE_BUTTON;              //Set the style
tbbToolBarButtons[0].idCommand = IDM_OPEN;                  //Set the menu command
tbbToolBarButtons[0].dwData = IDT_OPEN;                     //Set the button ID

tbbToolBarButtons[1].iBitmap = STD_DELETE ;                  //Set the button bitmap
tbbToolBarButtons[1].fsState = TBSTATE_INDETERMINATE;        //Set the state
tbbToolBarButtons[1].fsStyle = TBSTYLE_BUTTON;               //Set the style
tbbToolBarButtons[1].idCommand = IDM_CLOSE;                  //Set the menu command
tbbToolBarButtons[1].dwData = IDT_CLOSE;                     //Set the button ID

SendMessage(hButton[IDC_MAIN_TOOLBAR], TB_ADDBUTTONS, sizeof(tbbToolBarButtons)/sizeof(TBBUTTON), (LPARAM)&tbbToolBarButtons);   //Load the buttons


Handling the TBN_GETINFOTIP message:

case TBN_GETINFOTIP: 
	MessageBox(hWnd, "TBN_GETINFOTIP sent", "Message", MB_ICONERROR);
	LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT)lParam; 
    
	// Set the instance of the module that contains the resource.

	lpttt->hinst = (HINSTANCE) GetWindowLong(hWnd,GWL_HINSTANCE); 
	UINT_PTR idButton = lpttt->hdr.idFrom; 
	switch (idButton) 
	{ 
		case IDM_OPEN: 
			MessageBox(hWnd, "Open", "Message", MB_ICONERROR);
			lpttt->lpszText = MAKEINTRESOURCE(IDS_OPEN_TOOLTIP); 
			break; 
		case IDM_CLOSE: 
			MessageBox(hWnd, "Close", "Message", MB_ICONERROR);
			lpttt->lpszText = MAKEINTRESOURCE(IDS_CLOSE_TOOLTIP); 
			break; 
	} 
	break;

I receive the "TBN_GETINFOTIP sent" message box when I mouse over one of my buttons. However, I never receive the "Open" or "Close" message box. Am I implementing this incorrectly? Thanks for any help you can offer!
Advertisement
Just with a quick glance, I think you should be using IDT_OPEN in the switch case, not IDM_OPEN.
IDM_OPEN is when you process the button click.
I am not 100% sure as I haven't used a toolbar in a long time.
The lParam paremeter for TBN_GETINFOTIP contains a pointer to a NMTBGETINFOTIP structure, not a TOOLTIPTEXT structure. Also, generally, the idFrom member of the NMHDR structure is the id of the window sending the notification message (in this case the toolbar control), not the id of the item. See the docs for the TBN_GETINFOTIP notification message.
I found part of the problem.

The lparam of the message that is sent when I mouse-over a toolbar button is a pointer to a NMTTDISPINFO structure. The NMTTDISPINFO.hdr.idFrom member is supposed to be the command identifier of the toolbar button for which tool tips is needed. However, when I process the message, the NMTTDISPINFO.hdr.idFrom member is always the ID of the toolbar itself.

This is why I am not reaching my case statements. The ID sent is never a button ID. Any idea why it would be sending the ID of the toolbar instead of the ID of the button?
Quote:Original post by hikikomori-san
The lParam paremeter for TBN_GETINFOTIP contains a pointer to a NMTBGETINFOTIP structure, not a TOOLTIPTEXT structure. Also, generally, the idFrom member of the NMHDR structure is the id of the window sending the notification message (in this case the toolbar control), not the id of the item. See the docs for the TBN_GETINFOTIP notification message.


I didn't refresh my window before responding. I am looking into this now. Thanks for the help!
Fixed some message handling issues and I have my tool tips. Thanks for the help!

This topic is closed to new replies.

Advertisement