show tooltip on control
2581 ワード
http://www.borngeek.com/coding/dialog/control_tooltips.
Adding Tooltips to Dialog Controls
Back to the Coding Artcle Index
Enbaling Tooltips
Eabling tooltips on dialog controlls can be extremely useful、especially when a large number of controlls are.In this scenaro、they could be used to describe what particular controll does、as well as.cores ponding shot keys.Adding this feature is a relatively simple procedure.First we need to enable the tooltips by calling the following ling the of code in our
Next、add the
Adding Tooltips to Dialog Controls
Back to the Coding Artcle Index
Enbaling Tooltips
Eabling tooltips on dialog controlls can be extremely useful、especially when a large number of controlls are.In this scenaro、they could be used to describe what particular controll does、as well as.cores ponding shot keys.Adding this feature is a relatively simple procedure.First we need to enable the tooltips by calling the following ling the of code in our
OnInitDialog()
method:EnableToolTips(TRUE);
This function simplyenaboles the tooltip controll in our dialogwidow.We now need to add the follwiwing line of code to the message map inour dialog class.Note that the textOnToolTip
the cocode bebededethethethethethethethethethethethethethethethethethetheaathththththinininininininininininininininininininininininaaaaaaaththththththththththththththththththethethethethethethethethethethethethethethethethethethethethethethethethethethetheke.For the purposes of this article,we will stick with usingOnToolTip
as the method name.ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnToolTip)
Handling the TooltipsNext、add the
OnToolTip()
method declaration to the dialog class header file:afx_msg BOOL OnToolTip(UINT id, NMHDR* pTTTStruct, LRESULT* pResult);
After we have declead this method,we need to add its code to the dialog class CPP file.The definition for this method is shown below:BOOL CYourDlg::OnToolTip(UINT id, NMHDR* pNMHDR, LRESULT* pResult)
{
TOOLTIPTEXT *pTTT = (TOOLTIPTEXT*)pNMHDR;
UINT nID = pNMHDR->idFrom;
if(pTTT->uFlags & TTF_IDISHWND)
{
// idFrom is actually the HWND of the tool
nID = ::GetDlgCtrlID((HWND)nID);
if(nID)
{
pTTT->lpszText = MAKEINTRESOURCE(nID);
pTTT->hinst = AfxGetResourceHandle();
return(TRUE);
}
}
return(FALSE);
}
Now that our code is in place,we need to add the tooltip stregs to the string table reource.In the resoure editor,open the streing table(insert a new one if your project doesn't already have)Now add one string for each controll that you want to show a tooltip.Each string's value shound be set to the text to appar to appar in the tooltip.Most importly,each string's ID shout set the same the conress ID