Prev: Copy A Dialog from Project to Project
Next: open .chm file from VC++ - with Table Of Contents hidden - HTMLHel
From: Woody on 1 Jun 2010 03:14 I have moved a project from VS6 to VS2005. The app is an MFC dialog, with tracking tooltips in a list control. When the app was built in VS6, the tracking tooltips performed as expected, but when the app is built in VS2005, no tooltips appear. I cannot figure out why this is happening, and would appreciate some advice. Here is the code, same in both VS6 and VS2005: Creation of the tooltip, CToolTipCtrlEx: // Set up the tooltip which will display variable values in the list control toolTipCtrl.Create(this,TTS_ALWAYSTIP); toolTipCtrl.AddWindowTool(&pgmCtrl,LPSTR_TEXTCALLBACK); // tooltip will not show until activated toolTipDisplayed=false; toolInfo.cbSize = sizeof (TOOLINFO); // set up the stuff needed for message processing toolInfo.hwnd = this->m_hWnd; toolInfo.uId = (UINT) pgmCtrl.m_hWnd; In PreTranslateMessage, the tooltip is activated and its position set when we are within the list control: if(pMsg->message==WM_MOUSEMOVE) { if(pMsg->hwnd==pgmCtrl.m_hWnd) // mouse move within list control { if(!toolTipDisplayed) { ::SendMessage (toolTipCtrl.m_hWnd,TTM_TRACKACTIVATE, (WPARAM)TRUE, (LPARAM) &toolInfo); // Above message is sent in both VS6 and VS2005 } ::SendMessage(toolTipCtrl.m_hWnd,TTM_TRACKPOSITION,0,(LPARAM) (DWORD) MAKELONG(pMsg->pt.x+15, pMsg->pt.y-15)); toolTipPos=pMsg->pt; } else // mouse move outside list control { if(toolTipDisplayed) { ::SendMessage (toolTipCtrl.m_hWnd,TTM_TRACKACTIVATE, (WPARAM)FALSE, (LPARAM) &toolInfo); toolTipDisplayed=false; } } } return CDialog::PreTranslateMessage(pMsg); Here is where we should come when the tooltip is to be displayed. In VS2005, this is never reached; in VS6 it is. BOOL CMasterDlg::OnNeedText( UINT id, NMHDR * pTTTStruct, LRESULT * pResult ) { .... } In class CToolTipCtrlEx (adapted from Proise): BOOL CToolTipCtrlEx::AddWindowTool (CWnd* pWnd, LPCTSTR pszText) { TOOLINFO ti; ti.cbSize = sizeof (TOOLINFO); ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE; ti.hwnd = pWnd->GetParent ()->GetSafeHwnd (); ti.uId = (UINT) pWnd->GetSafeHwnd (); ti.hinst = AfxGetInstanceHandle (); ti.lpszText = (LPTSTR) pszText; return (BOOL) SendMessage (TTM_ADDTOOL, 0, (LPARAM) &ti); } I noticed someone's post suggesting that there might be a mismatch between commctrl.dll and WINVER, so I also tried using the older TOOLINFO (v2) structure, but that didn't make any difference. On my both systems, WINVER=501.
From: Cameron_C on 1 Jun 2010 11:56 Hello Woody, I am not sure if this will be helpful or not. I use ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnGetToolTipTextForFinalizeButton) and ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnGetToolTipTextForFinalizeButton) For the ToolTips Needt Text messages. I know aI spent a fair bit of effort to get this to work. "Woody" wrote: > I have moved a project from VS6 to VS2005. The app is an MFC dialog, > with tracking tooltips in a list control. When the app was built in > VS6, the tracking tooltips performed as expected, but when the app is > built in VS2005, no tooltips appear. I cannot figure out why this is > happening, and would appreciate some advice. > > Here is the code, same in both VS6 and VS2005: > > Creation of the tooltip, CToolTipCtrlEx: > // Set up the tooltip which will display variable values in the list > control > toolTipCtrl.Create(this,TTS_ALWAYSTIP); > toolTipCtrl.AddWindowTool(&pgmCtrl,LPSTR_TEXTCALLBACK); // tooltip > will not show until activated > toolTipDisplayed=false; > toolInfo.cbSize = sizeof (TOOLINFO); // set up the stuff needed for > message processing > toolInfo.hwnd = this->m_hWnd; > toolInfo.uId = (UINT) pgmCtrl.m_hWnd; > > In PreTranslateMessage, the tooltip is activated and its position set > when we are within the list control: > if(pMsg->message==WM_MOUSEMOVE) > { > if(pMsg->hwnd==pgmCtrl.m_hWnd) // mouse move within list control > { > if(!toolTipDisplayed) > { > ::SendMessage (toolTipCtrl.m_hWnd,TTM_TRACKACTIVATE, > (WPARAM)TRUE, (LPARAM) &toolInfo); > // Above message is sent in both VS6 and VS2005 > } > ::SendMessage(toolTipCtrl.m_hWnd,TTM_TRACKPOSITION,0,(LPARAM) > (DWORD) MAKELONG(pMsg->pt.x+15, pMsg->pt.y-15)); > toolTipPos=pMsg->pt; > } > else // mouse move outside list control > { > if(toolTipDisplayed) > { > ::SendMessage (toolTipCtrl.m_hWnd,TTM_TRACKACTIVATE, > (WPARAM)FALSE, (LPARAM) &toolInfo); > toolTipDisplayed=false; > } > } > } > return CDialog::PreTranslateMessage(pMsg); > > Here is where we should come when the tooltip is to be displayed. In > VS2005, this is never reached; in VS6 it is. > BOOL CMasterDlg::OnNeedText( UINT id, NMHDR * pTTTStruct, LRESULT * > pResult ) > { > .... > } > > In class CToolTipCtrlEx (adapted from Proise): > > BOOL CToolTipCtrlEx::AddWindowTool (CWnd* pWnd, LPCTSTR pszText) > { > TOOLINFO ti; > ti.cbSize = sizeof (TOOLINFO); > ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE; > ti.hwnd = pWnd->GetParent ()->GetSafeHwnd (); > ti.uId = (UINT) pWnd->GetSafeHwnd (); > ti.hinst = AfxGetInstanceHandle (); > ti.lpszText = (LPTSTR) pszText; > > return (BOOL) SendMessage (TTM_ADDTOOL, 0, (LPARAM) &ti); > } > > I noticed someone's post suggesting that there might be a mismatch > between commctrl.dll and WINVER, so I also tried using the older > TOOLINFO (v2) structure, but that didn't make any difference. On my > both systems, WINVER=501. > > > > > > > . >
From: Woody on 1 Jun 2010 14:07 On Jun 1, 8:56 am, Cameron_C <Camer...(a)discussions.microsoft.com> wrote: > I am not sure if this will be helpful or not. > I use ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, > OnGetToolTipTextForFinalizeButton) It was extremely helpful. Armed with this hint, I experimented and discovered that my original code worked fine if I changed my message map entry from ON_NOTIFY_EX(TTN_NEEDTEXT, IDC_ListCtrl, OnNeedText) to ON_NOTIFY_EX(TTN_NEEDTEXT ,0, OnNeedText) In other words, the notification doesn't include the control's ID. I have no idea why this works. You example included both Unicode and ASCII messages, and all possible IDs, which I narrowed down to just what I needed. BTW, apparently the reason it worked in VS6 was that the message map entry there was ON_NOTIFY_EX(TTN_NEEDTEXT, NULL, OnNeedText) but this doesn't work in VS2005.
From: Cameron_C on 2 Jun 2010 10:26
Woody, I am happy that you worked this one out. "Woody" wrote: > On Jun 1, 8:56 am, Cameron_C <Camer...(a)discussions.microsoft.com> > wrote: > > I am not sure if this will be helpful or not. > > I use ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, > > OnGetToolTipTextForFinalizeButton) > > It was extremely helpful. Armed with this hint, I experimented and > discovered that my original code worked fine if I changed my message > map entry from > > ON_NOTIFY_EX(TTN_NEEDTEXT, IDC_ListCtrl, OnNeedText) > to > ON_NOTIFY_EX(TTN_NEEDTEXT ,0, OnNeedText) > > In other words, the notification doesn't include the control's ID. I > have no idea why this works. You example included both Unicode and > ASCII messages, and all possible IDs, which I narrowed down to just > what I needed. > > BTW, apparently the reason it worked in VS6 was that the message map > entry there was > > ON_NOTIFY_EX(TTN_NEEDTEXT, NULL, OnNeedText) > > but this doesn't work in VS2005. > > . > |