VC Implementation dialog box on the display of information

Source: Internet
Author: User

Using VC AppWizard, you can easily implement the ToolTip of toolbars and menu items, or display Help on the status bar, but it is not easy to display ToolTip on the control of a dialog box and display control information on the status bar. Now, we use VC wm_setcursor and Ttn_needtext message can achieve the purpose. The specific actions are as follows:

First, the use of VC MFC AppWizard to generate an SDI or MDI application

Second, Edit the dialog box control string resources

For example: Idc_dbbutton1 = "This is Xiao Tianpeng's first homemade button \ Tian Peng",

Where the string "The first homemade button of this is Xiao Tianpeng" will appear on the status bar when the mouse is moved over the control, and the string "Tian Peng" will be displayed as a ToolTip.

III. Building a message map

In the header file (*.h) of the dialog box

Add 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()

The implementation file in the dialog box (*. CPP), add the following code:

BEGIN_MESSAGE_MAP(CFileOp1, CDialog)
//{{AFX_MSG_MAP(CFileOp1)
ON_WM_DESTROY()
ON_WM_SETCURSOR()
//}}AFX_MSG_MAP
ON_NOTIFY_EX(TTN_NEEDTEXT,0,OnTipNotify)
END_MESSAGE_MAP()

Iv. Edit Message Handler functions

BOOL cfileop1::onsetcursor
(cwnd* pwnd, UINT nhittest, UINT message)
{
//todo:add your message Han Dler
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);
}
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_setmessagestring, 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 szful LTEXT[256];
CString Strtiptext;
Afxloadstring (Nid,szfulltext);
Afxextractsubstring (Strtiptext,
szfulltext,1, ' \ n ');
if (! Strtiptext.isempty ())
strcpy (pttt->lpsztext,strtiptext);
pttt->hinst = AfxGetResourceHandle ();
return (TRUE);
}
}
return (FALSE);
}

V. Add the following directive to the Stdafx.h file:

#include 〈afxpriv.h>

#include 〈afxres.h>

VI the dialog box is used as a child of the main frame of an SDI or MDI application, and the ToolTip and status bar information of the control appears when you move the mouse over a control that must have a corresponding string resource.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.