|
Question : OnToolTipNotify() not called in CView class
|
|
I want to popup tooltips when hovering mouse in a CView class. I've had luck showing tooltips before in a CFrameWnd class before, but maybe there's a difference when it's a CView? Usually tooltips takes three simple steps:
This is what I've got:
1) Enable tooltips:
void CEventView::OnInitialUpdate() { CView::OnInitialUpdate(); EnableToolTips(); }
2) Override OnToolHitTest()
int CEventView::OnToolHitTest( CPoint PointCP, TOOLINFO* pTI ) const { pTI->hwnd = GetSafeHwnd(); pTI->uFlags = 0; pTI->lpszText = LPSTR_TEXTCALLBACK; //Do some clever hittest, and put index if rectangle that was hit into TOOLINFO pTI->uId = 1; //<-- index of rect that was hit return 1; }
3) Add TTN_NEEDTEXTW to the message map
BEGIN_MESSAGE_MAP(CEventView, CView) ON_NOTIFY(TTN_NEEDTEXTW, 0, OnToolTipNotify) ON_NOTIFY(TTN_NEEDTEXTA, 0, OnToolTipNotify) END_MESSAGE_MAP()
void CEventView::OnToolTipNotify(NMHDR *pNMHDR, LRESULT *pResult) { UINT uiID = pNMHDR->idFrom-1; //<-- index of the rect that was hit //what happends here is not important for the question, //OnToolTipNotify() is never called - question is why? }
I have OnToolHitTest() called, but not OnToolTipNotify(), why is that?
|
|
Answer : OnToolTipNotify() not called in CView class
|
|
int CMyView::OnToolHitTest( CPoint point, TOOLINFO* pTI ) const { pTI->hwnd = GetSafeHwnd(); pTI->uFlags = 0; pTI->lpszText = LPSTR_TEXTCALLBACK; //Do some clever hittest, and put index if rectangle that was hit into TOOLINFO pTI->uId = 1; //<-- index of rect that was hit
pTI->rect.left = 0; pTI->rect.top = 0; pTI->rect.right = 300; pTI->rect.bottom = 300;
return 1; } This calls back for tip text (to the VIEW) when cursor is inside the specified rectangle (0,0,300,300)
|
|
|
|