With VC's AppWizard, you can easily implement tooltip and menu items, or display help on the status bar, but you want to display Tooltip on the controls on the dialog and display control information on the status bar is not easy to implement. Now, we use the WM_SETCURSOR in the VC to achieve the purpose with the TTN_NeedText message. The specific operation is as follows:
First, generate an SDI or MDI application with VC's MFC AppWizard
Second, edit the string resources of the dialog control
For example: idc_dbbutton1 = "this is Xiao Tianpeng's first homemade button Tianpeng",
The string "this IS Xiao Tianpeng's first homemade button" will appear on the status bar when the mouse is moved to the control, and the string "Tianpeng" will be displayed as Tooltip.
Third, establish a message mapping
In the header file (* .h) of the dialog
Adding the following code: protected: void SetStatusText (UINT nID = 0); // {{AFX_MSG (CFileOp1) afx_msg void OnDestroy (); afx_msg BOOL OnSetCursor (CWnd * pWnd, UINT nHitTest, UINT message); //}} AFX_MSG afx_msg BOOL OnTipNotify (UINT id, NMHDR * pNMHDR, LRESULT * pResult); DECLARE_MESSAGE_MAP () add the following code to the implementation file (* .CPP) dialog box: BEGIN_MESSAGE_MAP (CFileOp1, CDialog) // {{AFX_MSG_MAP (CFileOp1) ON_WM_DESTROY ( ) ON_WM_SETCURSOR () //}} AFX_MSG_MAP ON_NOTIFY_EX (TTN_NEEDTEXT, 0, OnTipNotvify) END_MESSAGE_MAP () IV edit message processing function BOOL CFileOp1 :: OnSetCursor (CWnd * pWnd, UINT nHitTest, UINT message) {// TODO: Add your message handler code here and / or call default if (pWnd == this) SetStatusText (); else {TOOLTIPTEXT m_psttt; m_psttt.hdr.hwndFrom = m_hWnd; m_psttt.hdr.idFrom = pWnd-> GetDlgCtrlID (); m_psttt.hdr.code = TTN_NEEDTEXT; m_psttt.uFlags = TTF_IDISHWND; SetStatusText (pWnd-> GetDlgCtrlID ()); this-> SendMessage (WM_NOTIFY, m_psttt.hdr.idFrom, (LPARAM) & m_psttt);} return CDialog :: OnSetCursor (pWnd, nHitTest, message } Vo id CFileOp1 :: OnDestroy () {SetStatusText (); CDialog :: OnDestroy ();} void CFileOp1 :: SetStatusText (UINT nID) {if (nID == 0) nID = AFX_IDS_IDLEMESSAGE; CWnd * pWnd = AfxGetMainWnd () -> GetDescendantWindow (AFX_IDW_STATUS_BAR); if (pWnd) {AfxGetMainWnd () -> SendMessage (WM_SETMESS ?? AGESTRING, nID); pWnd-> SendMessage (WM_IDLEUPDATECMDUI); pWnd-> UpdateWindow ();}} BOOL CFileOp1 :: OnTipNotify (UINT id , NMHDR * pnmhdr, lresult * presult) {tooltiptext * pttt = (tooltiptext *) PNMHDR;
UINT nID = pNMHDR-> idFrom; if (pTTT-> uFlags & TTF_IDISHWND) {nID = :: GetDlgCtrlID ((HWND) nID); if (nID) {TCHAR szFullText [256]; CString StrTipText; AfxLoadString (nID, szFullText) ; AfxExtractSubString (StrTipText, szFullText, 1, ''); if strcpy (pTTT-> lpszText, StrTipText) (StrTipText.IsEmpty ()!); pTTT-> hinst = AfxGetResourceHandle (); return (TRUE);}} return ( FALSE);} 5, the dialog box as a sub-window of an SDI or MDI application, generate such a dialog, when you move the mouse to a control (must have the corresponding string resources) When the control of the Tooltip and status information of the control will appear.