dedecms织梦内容管理系统      
首页 | 51单片机 | 休闲娱乐 | 手工乐园 | 免费软件 | 理财专区 | 串口通信 | UNIX/LINUX | TurboC | 专题 | 会员中心 | 支持论坛
  当前位置:主页>MFC/C++>文档内容
对话框中使用ToolBar并显示ToolsTip
来源:http://www.codeproject.com/dialog/dialog_tips.asp 作者:温柔老胡 发布时间:2007-06-28  
你会看到这个提示,那是因为你的系统无法识别某栏目的模型信息,或者你新建模型后,没为这个模型设计单独的模板。不同模型的文档浏览页的模板为:article_模型名字标识.htm 如“article_article.htm”,更多的信息你可以在频道模型管理的地方查看。
body  
It is relatively easy to place a toolbar in a dialog box, but I had a hard time making the tooltips appear since none of the TTN_xxxx message handlers are present in a CDialog derived class. This article describes a simple technique for getting tooltips when you have a toolbar in a dialog. It also gives a brief overview of the steps involved in adding a toolbar to a dialog box.
Step 1
In the dialog's header file you must add a CToolBar instance and an entry in the message map to handle the tooltip messages.
protected:
    CToolBar cToolBar;
at the bottom of the wizard generated message map entries add:
    //}}AFX_MSG
    afx_msg BOOL OnToolTipText(UINT nID, NMHDR* pNMHDR, LRESULT* pResult);
    DECLARE_MESSAGE_MAP()
Step 2
In dialog's implementation file add the following to the end of OnInitDialog to show the toolbar.
    //add the tool bar to the dialog
    cToolBar.Create(this);
    cToolBar.LoadToolBar(IDR_TOOLBAR);
    cToolBar.ShowWindow(SW_SHOW);
    cToolBar.SetBarStyle(CBRS_ALIGN_TOP | CBRS_TOOLTIPS | CBRS_FLYBY);
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
At the bottom of the message map add the following:
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
END_MESSAGE_MAP()
Finally add the message handler method as entered in the message map:
Collapse
BOOL CToolBarTipTestDialog::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
{
    ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW);
 
    // if there is a top level routing frame then let it handle the message
    if (GetRoutingFrame() != NULL) return FALSE;
 
    // to be thorough we will need to handle UNICODE versions of the message also !!
    TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
    TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
    TCHAR szFullText[512];
    CString strTipText;
    UINT nID = pNMHDR->idFrom;
 
    if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
        pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
    {
        // idFrom is actually the HWND of the tool
        nID = ::GetDlgCtrlID((HWND)nID);
    }
 
    if (nID != 0) // will be zero on a separator
    {
        AfxLoadString(nID, szFullText);
        strTipText=szFullText;
 
#ifndef _UNICODE
        if (pNMHDR->code == TTN_NEEDTEXTA)
        {
            lstrcpyn(pTTTA->szText, strTipText, sizeof(pTTTA->szText));
        }
        else
        {
            _mbstowcsz(pTTTW->szText, strTipText, sizeof(pTTTW->szText));
        }
#else
        if (pNMHDR->code == TTN_NEEDTEXTA)
        {
            _wcstombsz(pTTTA->szText, strTipText,sizeof(pTTTA->szText));
        }
        else
        {
            lstrcpyn(pTTTW->szText, strTipText, sizeof(pTTTW->szText));
        }
#endif
 
        *pResult = 0;
 
        // bring the tooltip window above other popup windows
        ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0,
            SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER);
       
        return TRUE;
    }
 
    return FALSE;
}
 

[收藏] [推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
用户名: 新注册) 密码: 匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论:
  热点文档
·使用C++编写的 双向链表C++类
·使用C++编写的 CString类
·RichEditCtrl 使用方法
·对话框中使用ToolBar最简方法
·CRichEdit 动态加入带有格式的文
  相关文档
·CRichEdit 动态加入带有格式的文
·RichEditCtrl 使用方法
·使用C++编写的 CString类
·使用C++编写的 双向链表C++类
·对话框中使用ToolBar最简方法
  推荐文档
·RichEditCtrl 使用方法
·CRichEdit 动态加入带有格式的文
·对话框中使用ToolBar最简方法
·使用C++编写的 双向链表C++类
·使用C++编写的 CString类

 Powered by 温柔老胡 System by www.dedecms.com