Supporting ToolTips

You can add ToolTips support to your toolbar by specifying the TBSTYLE_TOOLTIPS style and creating a string table in your RC file that contains the text to display. You then process the WM_NOTIFY message that is sent to the parent window procedure of the toolbar, as shown in the following code:

case WM_NOTIFY:
switch (((LPNMHDR)lParam)->code)
{
case TTN_NEEDTEXT:
// Display the ToolTip text.
lpToolTipText = (LPTOOLTIPTEXT)lParam;
LoadString (hInst,
lpToolTipText->hdr.idFrom, // string ID == cmd ID
szBuf,
sizeof (szBuf));
lpToolTipText->lpszText = szBuf;
break;
§

This step is a bit different for those developing in MFC. The standard lists currently provided with MFC do not include the WM_NOTIFY message. As a result, you need to put a function directly into the view class:

LRESULT CMfctoolView::WindowProc (UINT message, WPARAM wParam,
LPARAM lParam)
{
static CHAR szBuf [128];
LPTOOLTIPTEXT lpToolTipText;

if (message == WM_NOTIFY)
{
switch (((LPNMHDR)lParam)->code)
{
case TTN_NEEDTEXT:
// Display the ToolTip text.
lpToolTipText = (LPTOOLTIPTEXT)lParam;
::LoadString (AfxGetResourceHandle (),
lpToolTipText->hdr.idFrom, // string ID == cmd ID
szBuf,
sizeof (szBuf));
lpToolTipText->lpszText = szBuf;
break;
§