VC implementation of information on dialog box

zhaozj2021-02-11  195

VC implementation of information on dialog box

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: 1. Generate an SDI or MDI application II to edit the string resources of the Edit dialog control, for example: idc_dbbutton1 = "The first homemade button / N Tianpeng" of this is Xiao Tianpeng The string "this is Xiao Tianpeng's first homemade button" will be displayed on the status bar when the mouse moves to the control, and the string "Tianpeng" will be displayed as Tooltip.

Third, the establishment message mapping adds the following code in the header file (* .h) of the dialog: protected: void setStatustext (uint nid = 0); // {{AFX_MSG (cfileop1) AFX_MSG void ONDESTROY (); afx_msg bool onsetcursor CWND * PWND, UINT NHITTEST, UINT MESSAGE : 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 (PW nd, nHitTest, message);} void 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 *

转载请注明原文地址:https://www.9cbs.com/read-4010.html

New Post(0)