📄 display_dialog_tooltips.shtml
字号:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta name="Author" content="Kirk Stowell"><title>Toolbar - How to display tooltips for a toolbar in a dialog</title></head><body background="/fancyhome/back.gif" bgcolor="#FFFFFF"><!-- A word from our sponsors... --><table border="0" width="100%"> <tr> <td align="center"><!--#exec cgi="/cgi/ads.cgi"--></td> <td></td> </tr></table><!-- Article Title --><font color="#a0a099"><h3 align="center"><b>How to display tooltips for a toolbar in a dialog</b></h3></font><hr><!-- Author and contact details --><p>This article was contributed by <!-- Author Email and Author Name --> <a href="mailto:rmore@cri.com">Randy More</a>. </p><p><!-- Text --> It is relatively easy to place a toolbar in a dialog box, but I had a hard time makingthe tooltips appear since none of the TTN_xxxx message handlers are present in a CDialogderived class. This article describes a simple technique for getting tooltips when youhave a toolbar in a dialog. It also gives a brief overview of the steps involved in addinga toolbar to a dialog box.</p><p><b><i>Step 1</i></b></p><p>In the dialog's header file you must add a CToolBar instance and an entry in themessage map to handle the tooltip messages.<br><font color="#990000"><tt><br><!-- start a block of source code -->protected:<br> CToolBar cToolBar;<br></tt></font></p><!-- end the block of source code --><p>at the bottom of the wizard generated message map entries add:</p><p><font color="#990000"><tt><!-- start a block of source code --> //}}AFX_MSG<br>afx_msg BOOL OnToolTipText(UINT nID, NMHDR* pNMHDR, LRESULT* pResult);<br>DECLARE_MESSAGE_MAP()<br></tt></font></p><!-- end the block of source code --><p><b><i>Step 2</i></b></p><p>In dialog's implementation file add the following to the end of <b>OnInitDialog</b> toshow the toolbar.</p><p><font color="#990000"><tt><!-- start a block of source code --> //add the tool bar to the dialog<br>cToolBar.Create(this);<br>cToolBar.LoadToolBar(IDR_TOOLBAR);<br>cToolBar.ShowWindow(SW_SHOW);<br>cToolBar.SetBarStyle(CBRS_ALIGN_TOP | CBRS_TOOLTIPS | CBRS_FLYBY);<br>RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);<br></tt></font></p><!-- end the block of source code --><p>At the bottom of the message map add the following:</p><p><font color="#990000"><tt><!-- start a block of source code --> FX_MSG_MAP<br>ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)<br>ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)<br>END_MESSAGE_MAP()<br></tt></font></p><!-- end the block of source code --><p>Finally add the message handler method as entered in the message map:</p><p><font color="#990000"><tt><!-- start a block of source code --> BOOL CToolBarTipTestDialog::OnToolTipText(UINT, NMHDR*pNMHDR, LRESULT* pResult)<br>{<br> ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code== TTN_NEEDTEXTW);<br><br> // if there is a top level routing frame then let it handlethe message<br> if (GetRoutingFrame() != NULL) return FALSE;<br><br> // to be thorough we will need to handle UNICODE versions ofthe message also !!<br> TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;<br> TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;<br> TCHAR szFullText[512];<br> CString strTipText;<br> UINT nID = pNMHDR->idFrom;<br><br> if (pNMHDR->code == TTN_NEEDTEXTA &&(pTTTA->uFlags & TTF_IDISHWND) ||<br> pNMHDR->code == TTN_NEEDTEXTW&& (pTTTW->uFlags & TTF_IDISHWND))<br> {<br> // idFrom is actually the HWNDof the tool <br> nID =::GetDlgCtrlID((HWND)nID);<br> }<br><br> if (nID != 0) // will be zero on a separator<br> {<br> AfxLoadString(nID,szFullText);<br> strTipText=szFullText;<br><br>#ifndef _UNICODE<br> if (pNMHDR->code ==TTN_NEEDTEXTA)<br> {<br> lstrcpyn(pTTTA->szText,strTipText, sizeof(pTTTA->szText));<br> }<br> else<br> {<br> _mbstowcsz(pTTTW->szText,strTipText, sizeof(pTTTW->szText));<br> }<br>#else<br> if (pNMHDR->code ==TTN_NEEDTEXTA)<br> {<br> _wcstombsz(pTTTA->szText,strTipText,sizeof(pTTTA->szText));<br> }<br> else<br> {<br> lstrcpyn(pTTTW->szText,strTipText, sizeof(pTTTW->szText));<br> }<br>#endif<br><br> *pResult = 0;<br><br> // bring the tooltip windowabove other popup windows<br> ::SetWindowPos(pNMHDR->hwndFrom,HWND_TOP, 0, 0, 0, 0,SWP_NOACTIVATE|<br> SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER);return TRUE;<br> }<br>} </tt></font></p><!-- end the block of source code --><p>Date Posted: 5 June, 1998<!-- date here --> </p><hr><!-- Codeguru contact details --><table border="0" width="100%"> <tr> <td width="33%"><a href="http://www.codeguru.com"><font size="2">Goto HomePage</font></a></td> <td width="33%"><p align="center"><font size="1">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -