'CToolTipCtrl is not showing
I have created a window which is derived from CWnd. The window has an icon and a text. Using DrawIconEx() and dc.DrawText() methods I am creating icon and text in onPaint() method. Technically I don't have any controls(like CStatic, CButton etc) in this window.
To create a tool tip I have added the following logic.
Header file: Added Member variable
CToolTipCtrl m_toolTipCtrl;
Source file: added the following in OnCreate() method.
m_toolTipCtrl.Create(this)
m_toolTipCtrl.AddTool(this, _T("Warning Message Tool-Tip"));
m_toolTipCtrl.Activate(TRUE);
Added RelayEvent in PreTranslateMessage(MSG* pMsg) virtual method m_toolTipCtrl.RelayEvent(pMsg);
Issue: A tooltip is not showing when I place the mouse cursor on this window. What I tried: I have observed that ToolTip is created But breakpoint in PreTranslateMessage() method is not hitting when the mouse hovers on the window.
Note: This window(A) is a child window of another window(B). B is derived by CView.
Can anyone please let me know what is wrong here?
Thanks in advance!
Solution 1:[1]
Usually you create a tooltip control by giving it the pointer to the parent window, and adding controls which are in that window. That means that the window pointer passed to create and the one passed to AddTool are not usually the same.
You want to create a tooltip control in the window itself, not a control.
You can create a tooltip for a rectangular area, and give it the whole window as the area (or only part of the window, if you prefer).
Here is an example of how to do it with the Windows API, without MFC: Create tooltip for whole window area
I have not yet found a good example in MFC; I'll try to find one and update this if I do. I can not test it myself because I currently do not have access to Visual Studio (sorry!).
In the meantime, perhaps the above example, combined with these docs will be enough information for you to figure it out.
You may also need to call SetToolTips on your window, as seen in this example
Do you have tooltips working elsewhere in your view? If not, you probably need to call EnableToolTips(true).
Solution 2:[2]
After a lot of suffering and searching, I found that it will work as this: I have a checkbox control IDC_CHECK_MY_BOX in MyPersonalDlg.
In MyPersonalDlg.h, I declared CToolTipCtrl m_toolTipCtrl.
In InitDialog of MyPersonalDlg.cpp:
CButton* control_pointer;
control_pointer= (CButton*)GetDlgItem(IDC_CHECK_MY_BOX);
m_toolTipCtrl.Create(this)
m_toolTipCtrl.AddTool(control_pointer, _T("Warning Message Tool-Tip"));
BOOL MyPersonalDlg::PreTranslateMessage(MSG* pMsg)
{
m_ToolTipCtrl.RelayEvent(pMsg);//this is why it didn't worked for me.
return CDialog::PreTranslateMessage(pMsg);
}
It worked for me without m_toolTipCtrl.Activate(TRUE); I wonder, why they couldn't make it easy, like in VB, when it's part of control property, it would be much easier to deal with.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Martin |
