PreTraslateMessage(MSG *) used with CToolTipCtrl

When you try to build tooltips with CToolTipCtrl, it is interesting to find the mouse messages are not passed automatically to the tool tip window unless you turn on TTF_SUBCLASS flags when you call CToolTipCtrl::AddTools().

If you did not turn TTS_SUBCLASS flag on, you have to use CToolTipCtrl::RelayEvent(MSG *) in the parent window of the tooltip window such that all events including the mouse events are routed to the tooltip window.

Where should you put the RelayEvent() function call? It looks like that you have to put this call somewhere in the message loop of the thread that controls the parent window.

The CWinThread::PreTranslateMessage(MSG *) is the place you are looking for.

CWinThread::Run()

+--> CWinThread::PumpMessage()

+--> AfxInternalPumpMessage()

+--> GetMessage(...)
____...
____if (AfxPreTranslateMessage(...) )
____{
________TranslateMessage(...);
________DispatchMessage(...);
____}

AfxPreTranslateMessage() calls CWinThread::PreTranslateMessage(pMsg) and calls CWnd::WalkPreTranslateTree(..., pMsg)

CWnd::WalkPreTranslateTree(...) calls CWnd::PreTranslateMessage(pMsg)

 

Therefore, in each of your CWnd derived class, you can override PreTranslateMessage(pMsg) and has a chance to forward each message that is sent to this particular window.

For example:

override CFormView::PreTranslateMessage() to call m_myToolTip.RelayEvent(pMsg) so that your tooltip control has the chance to process mouse events sent to your form view.