如何为对话框中的控件提供提示信息?

 

[问题提出]

 当用户不知道你的按钮的具体功能时,工具条提示是一个不错的方法.

 [解决方法]

 提示功能是由MFC类库中的CToolTipCtrl来实现的.

 [实现程序]

 假设你有了名为My的对话框的工程.首先建立一个Button,方法:ResourceView中双击Dialog,添加Button采用默认值:IDC_BUTTON1.实现PreTranslateMessage消息的相应函数.

 class CMyDlg : public CDialog

 {

 public:

 CToolTipCtrl m_ToolTips;

 ...............

 };

 

 BOOL CMyDlg::OnInitDialog()

 {

 CDialog::OnInitDialog();

 

 // TODO: Add extra initialization here

 

 CButton *pButton;

 pButton=(CButton *)GetDlgItem(IDC_BUTTON1);

    m_ToolTips.Create(this);

 m_ToolTips.AddTool(pButton,"This is a ToolTips text for this Button");

 return TRUE; // return TRUE unless you set the focus to a control

 }

 

 BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)

 {

 // TODO: Add your specialized code here and/or call the base class

 switch(pMsg->message)

 {

 case WM_LBUTTONDOWN:

 case WM_LBUTTONUP:

 case WM_MOUSEMOVE:

      m_ToolTips.RelayEvent(pMsg);

 }

 return CDialog::PreTranslateMessage(pMsg);

 }

 好了,运行看看.

posted on 2006-06-26 23:32  路吾  阅读(320)  评论(0)    收藏  举报

导航