ToolTips for Controls
Jerry Hewett -- jhewett@ix.netcom.com Wednesday, June 26, 1996 Environment: VC++ 4.0, MFC, NT 3.51 (and Win95) This has probably been discussed before, but I can't find it in my MFC-L save directory, so apologies ahead of time if I'm covering old ground. Was wondering if there's a way to subclass the MFC tooltips so that I can use them someplace other than the toolbar. I'm part of a team writing an app that's heavily into custom owner-draw buttons within dialogs and property sheets, and it would be nice to be able to derive our own stuff from the class that's already built into MFC instead of rolling our own. Thanks! Jerry H.
Brad Wilson/Crucial Software -- crucial@pobox.com Sunday, June 30, 1996 [Mini-digest: 3 responses] > Was wondering if there's a way to subclass the MFC tooltips so that I can use > them someplace other than the toolbar. Yes. Use the Component Gallery to add tooltip support to a dialog. It's a trivial process. :-) -- Brad Wilson, Crucial Software http://pobox.com/~crucial crucial@pobox.com Objectvst @ Undernet Objectivist @ DALnet Software engineering services for Microsoft Windows NT and Windows 95 "Money is so noble a medium that it does not compete with guns and it does not make terms with brutality. It will not permit a country to survive as half-property, half-loot." - F. d'Anconia, Atlas Shrugged -----From: Roger Onslow/Newcastle/Computer Systems Australia/AU>This has probably been discussed before, but I can't find it in my MFC-L save >directory, so apologies ahead of time if I'm covering old ground. It is, but that's ok >Was wondering if there's a way to subclass the MFC tooltips so that I can use >them someplace other than the toolbar. I'm part of a team writing an app >that's heavily into custom owner-draw buttons within dialogs and property >sheets, and it would be nice to be able to derive our own stuff from the >class that's already built into MFC instead of rolling our own. No need -- all done for you by MFC, just need to turn it on and write a handler which supplies tool tip text (from string resource) If it is a property page, you need an additional step for redirecting pretranslate message (as per my previous posting). You will also have to add string resources for each control id that has a tool tip. Here's some code snippets (not including .h) : (largely from KB Q140595 ,and help on EnableToolTips()) === NOTE === Replace CDialog with CPropertyPage for property pages BEGIN_MESSAGE_MAP(CMyDialog, CDialog) //{{AFX_MSG_MAP(CMyDialog) ... //}}AFX_MSG_MAP ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT,0,0xFFFF,OnToolTipNotify) END_MESSAGE_MAP() BOOL CMyDialog::OnInitDialog() { ... EnableToolTips(TRUE); return TRUE; } BOOL CMyDialog::OnToolTipNotify( UINT, NMHDR * pNMHDR, LRESULT *) { TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR; UINT nID =pNMHDR->idFrom; if (pTTT->uFlags & TTF_IDISHWND) { // KB Q140595 doesn't have this nID = ::GetDlgCtrlID((HWND)nID); if(nID) { pTTT->lpszText = MAKEINTRESOURCE(nID); pTTT->hinst = AfxGetResourceHandle(); // better then AfxGetInstanceHandle(); return(TRUE); } } return(FALSE); } ==NOTE== if it's a page you also need.... BOOL CMyPropertyPage::PreTranslateMessage(MSG* pMsg) { return CWnd::PreTranslateMessage(pMsg); } /|\ Roger Onslow ____|_|.\ ============ _/.........\Senior Software Engineer /CCC.SSS..A..\ /CC..SS...A.A..\ Computer /.CC...SS..AAA...\ Systems /\.CC....SSAA.AA../ Australia \ \.CCCSSS.AA.AA_/ \ \...........// Ph: +61 49 577155 \ \...._____// Fax: +61 49 675554 \ \__|_/\_// RogerO@compsys.com.au \/_/ \// -----From: Marty Fried Are you aware of the CToolTipCtrl in MFC? It's pretty easy to use. Here is a summary of what's needed (I think this is all) - you can check the online docs for more info. CMyDialog::OnInitDialog(); { ... m_ToolTipCtl = new CToolTipCtrl; if(m_ToolTipCtl) { m_ToolTipCtl->Create(this); m_ToolTipCtl->AddTool(&m_FirstBtn, szFirst); m_ToolTipCtl->AddTool(&m_SecondBtn, szSecond); } ... } BOOL CMyDialog::PreTranslateMessage(MSG* pMsg) { m_ToolTipCtl->RelayEvent(pMsg); return CDialog::PreTranslateMessage(pMsg); }
| Вернуться в корень Архива |