Reference: MFC CToolBar toolbar display a message ToolTip
Add CxxxDlg.h in
CImageList m_imagelist;
CToolBar m_toolbar;
afx_msg BOOL OnToolTipNotify (UINT the above mentioned id, NMHDR * pNMHDR, LRESULT * pResult); // prompt for information
: In CxxxDlg.cpp file
is added in OnInitDialog () in
// the TODO: this additional initialization code m_imagelist.Create ( 32 , 32 , ILC_COLOR24 | ILC_MASK, . 1 , . 1 ); m_imagelist.Add (theApp.LoadIcon (IDI_ICON_BOOK_INFO)); m_imagelist.Add (theApp.LoadIcon (IDI_ICON_BOOK_IN) ); m_imagelist.Add (theApp.LoadIcon (IDI_ICON_QUERY)); m_imagelist.Add (theApp.LoadIcon (IDI_ICON_SYS_CONF)); m_imagelist.Add (theApp.LoadIcon (IDI_ICON_EXIT)); // toolbar button ID array UINT arrBtnID [ . 5 ] = { 7001 , 7002 , 7003 , 7004 , 7005 }; //Create a toolbar m_toolbar.Create ( the this ); m_toolbar.SetButtons (arrBtnID, 5 ); // m_toolbar.SetButtonText (0, _T ( "Book Information")); // m_toolbar.SetButtonText (1, _T ( "book storage ")); // m_toolbar.SetButtonText (2, _T (" sales query ")); // m_toolbar.SetButtonText (. 3, _T (" system configuration ")); // m_toolbar.SetButtonText (. 4, _T (" system exit ")); m_toolbar.GetToolBarCtrl () SetButtonWidth (. 60 , 120 ); m_toolbar.GetToolBarCtrl () SetImageList (. & m_imagelist); m_toolbar.SetSizes (CSize ( 60 , 60 ),CSize(32, 32)); RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0); m_toolbar.EnableToolTips(TRUE);//激活Tip
To add a prompt message
/// / information presentation // // // 1. header afx_msg BOOL OnToolTipNotify (UINT ID, the NMHDR pNMHDR *, * LRESULT pResult); // for information presentation // 2. The message map macro BEGIN_MESSAGE_MAP (CLibraryManagerDlg, CDialogEx ) ON_WM_SYSCOMMAND () ON_WM_PAINT () ON_WM_QUERYDRAGICON () ON_BN_CLICKED (IDOK, & CLibraryManagerDlg :: OnOK) // these are custom toolbar buttons ID, the corresponding mapping function ON_COMMAND ( 7001 , OnBookInfo) ON_COMMAND ( 7002 , OnBookIn) ON_COMMAND ( 7003 , OnSellQuery) ON_COMMAND ( 7004, OnSysConf) ON_COMMAND ( 7005 , OnSysExit) ON_NOTIFY_EX (the TTN_NEEDTEXT, 0 , OnToolTipNotify) // for prompt message END_MESSAGE_MAP () // 3. mapping function BOOL CLibraryManagerDlg :: OnToolTipNotify (UINT ID, the NMHDR pNMHDR *, * LRESULT pResult) { ToolTipText pTTT = * (* ToolTipText ) pNMHDR; CString STR; UINT the nID = pNMHDR-> idFrom; // Get toolbar button ID IF (the nID) { int index = m_toolbar.CommandToIndex (the nID); // acquisition button indexed by ID IF (index = -! 1 ) { Switch (index) { Case 0 : pTTT -> L = the lpszText " Book information " ; BREAK ; Case . 1 : pTTT -> L = the lpszText " book storage " ; BREAK ; Case 2 : pTTT -> L = the lpszText " Sales queries " ; BREAK ; Case 3 : pTTT-> L = the lpszText " System Configuration " ; BREAK ; Case . 4 : pTTT -> L = the lpszText " system exit " ; BREAK ; default : pTTT -> L the lpszText = " " ; BREAK ; } // Get Text toolbar pTTT- > = the hinst AfxGetResourceHandle (); return (TRUE); } } return (FALSE); }
****************