Article ID: 141871
Article Last Modified on 11/21/2006
#include <afxcmn.h>Note
Do not perform this step in Visual C++ .NET.
The header file Afxcmn.h contains declarations for MFC classes that
serve as wrappers to Windows Common Controls including CToolTipCtrl.
CToolTipCtrl m_ttip;
void RelayEvent(UINT message, WPARAM wParam, LPARAM lParam); The RelayEvent method will be used by the mouse message handlers to
relay those messages to the ToolTip control.
if (!m_ttip.Create(this))
TRACE0("Unable to create tip window.");
else
if (!m_ttip.AddTool(this, LPCTSTR(m_ToolTipText)))
TRACE0("Unable to add tip for the control window.");
else
m_ttip.Activate(m_ShowToolTip);
void CBasicCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
RelayEvent(WM_LBUTTONDOWN, (WPARAM)nFlags,
MAKELPARAM(LOWORD(point.x), LOWORD(point.y)));
COleControl:: OnLButtonDown(nFlags, point);
}
void CBasicCtrl::OnLButtonUp(UINT nFlags, CPoint point)
{
RelayEvent(WM_LBUTTONUP, (WPARAM)nFlags,
MAKELPARAM(LOWORD(point.x), LOWORD(point.y)));
COleControl::OnLButtonUp(nFlags, point);
}
void CBasicCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
RelayEvent(WM_MOUSEMOVE, (WPARAM)nFlags,
MAKELPARAM(LOWORD(point.x), LOWORD(point.y)));
COleControl::OnMouseMove(nFlags, point);
}
// implementation of the CBasicCtrl::RelayEvent method:
void CBasicCtrl::RelayEvent(UINT message, WPARAM wParam, LPARAM
lParam)
{
if (NULL != m_ttip.m_hWnd) {
MSG msg;
msg.hwnd= m_hWnd;
msg.message= message;
msg.wParam= wParam;
msg.lParam= lParam;
msg.time= 0;
msg.pt.x= LOWORD (lParam);
msg.pt.y= HIWORD (lParam);
m_ttip.RelayEvent(&msg);
}
} While it might seem reasonable to call CWnd::GetCurrentMessage instead
of manually building a message, the value of the point that is returned is
expressed in screen coordinates. When the ToolTip performs a hit test to
determine if the point of the relayed message falls within the boundary of the
client rectangle of any associated tools, the test will fail, and the ToolTip
will not be displayed.
PX_Bool(pPX, _T("ShowToolTip"), (BOOL&)m_ShowToolTip, FALSE);In order to view tooltip, this must be true.
PX_String(pPX, _T("ToolTipText"), m_ToolTipText, _T("")); And we need to add some text in _T(“ ...”)Property Name: ShowToolTip ToolTipText Property Type: VARIANT_BOOL BSTR Variable name: m_ShowToolTip m_ToolTipText Notification function: OnShowToolTipChanged OnToolTipTextChangedShowToolTip will allow the user to suppress the display of the ToolTip, and ToolTipText will track the text that is to be displayed when the ToolTip is visible.
void CBasicCtrl::OnToolTipTextChanged()
{
if (m_ttip.m_hWnd && AmbientUserMode()) {
m_ttip.UpdateTipText(LPCTSTR(m_ToolTipText), this);
SetModifiedFlag();
}
}
void CBasicCtrl::OnShowToolTipChanged()
{
if (m_ttip.m_hWnd && AmbientUserMode()) {
m_ttip.Activate(m_ShowToolTip);
SetModifiedFlag();
}
}Additional query words: kbvc400 kbvc410 kbvc420 kbvc500 kbvc600
Keywords: kbctrlcreate kbhowto kbtooltip KB141871