Tooltips for dynamically added buttons u
Jeremiah Talkar -- jtalkar@optika.com Friday, February 07, 1997 Environment: VC++ 4.2b, Win 95, NT 4.0 Hello! I have developed an application that creates three CToolBar related classes in addition to the standard one that AppWizard creates. For two of these toolbars, I dynamically add buttons when the application starts up. I have reserved a range of resource IDS for these and then handle the TTN_NEEDTEXT notification in the CToolbar derived classes to supply the tooltip text. All of this works just fine under Windows 95 but the tooltips do not display under Windows NT 4.0. I have verified that tooltips are enabled because there are other static buttons on the same toolbar for which the tooptips show up correctly. When debugging under NT 4.0, I set a break-point in the TTN_NEEDTEXT handler but control never got to that point. What am I missing here? Jeremiah
santoshu@riskinc.com Monday, February 10, 1997 Santosh Ulkande 02/10/97 10:07 AM Jimmy, You may have already gone through this but neverthless I am forwarding this. Bye Santosh. Override CFrameWnd::GetMessageString Quote from the doc: virtual void GetMessageString( UINT nID, CString& rMessage ) const; Parameters nID Resource ID of the desired message. rMessage CString object into which to place the message. Remarks Override this function to provide custom strings for command IDs. The default implementation simply loads the string specified by nID from the resource file. This function is called by the framework when the message string in the status bar needs updating. ---------- > From: Markus Seger> To: mfc-l@netcom.com > Subject: Adding toolbar buttons at run-time > Date: 7 ??????? 1997 ?. 10:41 > > Environment: VC++ 4.2b, Win 95, NT 4.0 > > I need to add certain buttons to a toolbar at run-time. My problem: how can > I specify the texts for the tooltips and the statusbar MFC displays when I > touch the button with the mouse. > > Normaly, these texts are specified in the string table resource. This can > not be done because my buttons are created at run-time. > > Can someone please help me? A pointer to the MFC source which loads the > strings from the resource would also be helpfull. TIA > > Markus >
Zeroth mark p sullivan -- msulliva@stevens-tech.edu Friday, February 14, 1997 > Environment: VC++ 4.2b, Win 95, NT 4.0 ^^^^^ vs ^^^^^ ah, there's the rub. > When debugging under NT 4.0, I set a break-point in the TTN_NEEDTEXT > handler but control never got to that point. What am I missing here? A few weeks back, I was working on an almost identical project. After a few frustrating hours, I did some digging: /*****************************************************************************\ * commctrl.h - - Interface for the Windows Common Controls * * Version 1.2 * * Copyright (c) 1991-1996, Microsoft Corp. All rights reserved. * \*****************************************************************************/ . . . #define TTN_FIRST (0U-520U) // tooltips #define TTN_LAST (0U-549U) . . . #define TTN_GETDISPINFOA (TTN_FIRST - 0) #define TTN_GETDISPINFOW (TTN_FIRST - 10) #ifdef UNICODE #define TTN_GETDISPINFO TTN_GETDISPINFOW #else #define TTN_GETDISPINFO TTN_GETDISPINFOA #endif #define TTN_NEEDTEXT TTN_GETDISPINFO #define TTN_NEEDTEXTA TTN_GETDISPINFOA #define TTN_NEEDTEXTW TTN_GETDISPINFOW #endif . . . /*****************************************************************************\ * End quote from commctrl.h - - Interface for the Windows Common Controls * \*****************************************************************************/ Essentially, the final compiled/linked/build value of TTN_NEEDTEXT depends on whether UNICODE was defined at compile-time. Windows sends a TTN_NEEDTEXTA notification when it wants an normal ANSI string (or maybe MBCS) and sends a TTN_NEEDTEXTW when it wants a Unicode string. I decided that it would be easier to handle both TTN_NEEDTEXTA and TTN_NEEDTEXTW messages myself (separately) than to figure out how to get Microsoft's code do it for me. My code (simplified) follows: /*****************************************************************************\ * My code * \*****************************************************************************/ CString& GetSomeCString(void); BOOL CMyToolBar::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { LPNMHDR pnmh = (LPNMHDR)lParam; LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT)lParam; switch( pnmh->code ) {case TTN_NEEDTEXTA: _tcscpy( lpttt->szText, GetSomeCString() ); return(TRUE); case TTN_NEEDTEXTW: #ifdef _MBCS mbstowcs( (wchar_t*)lpttt->szText, GetSomeCString(), (size_t)-1 ); #else wcscpy( lpttt->szText, GetSomeCString() ); #endif return(TRUE); } return CToolBar::OnNotify(wParam,lParam,pResult); } // end BOOL CMyToolBar::OnNotify( WPARAM wParam, LPARAM lParam, LRESULT* pResult ) /*****************************************************************************\ * End My code * \*****************************************************************************/ This will only work (I think, haven't tried) with a non-Unicode build. If I get a request for ANSI text, I copy from some CString into the lpttt's szText member. Unicode requests get a translation from my CString to the szText member. when I'm using MBCS, otherwizse Unicode requests get a copy. Fiddle with it! > Jeremiah 0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O O good luck . . . Zeroth mark p sullivan 0 0 msulliva@stevens-tech.edu http://attila.stevens-tech.edu/~msulliva/ O O To a wonderful universe! I am proud of my universe 0 0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O0O
Become an MFC-L member | Вернуться в корень Архива |