Article ID: 201540
Article Last Modified on 4/29/2005
CWindow m_wndToolTip;
#include <commctrl.h>
HRESULT InPlaceActivate(LONG iVerb, const RECT* prcPosRect=NULL)
{
HRESULT hr;
hr = CComControlBase::InPlaceActivate(iVerb, prcPosRect);
if (m_wndToolTip.m_hWnd == NULL)
{
// If we're windowless we still need an HWND
if (m_bWndLess)
{
HDC hDC;
// Get the HDC from the client
m_spInPlaceSite->GetDC(NULL, OLEDC_NODRAW, &hDC);
m_hTheWnd = WindowFromDC(hDC);
m_spInPlaceSite->ReleaseDC(hDC);
}
else
m_hTheWnd = m_hWnd;
//Load the Common control library and create tooltip control
InitCommonControls();
m_wndToolTip.m_hWnd =
::CreateWindow(TOOLTIPS_CLASS, (LPTSTR)NULL, TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, (HMENU) NULL, _Module.GetModuleInstance(), NULL);
// Ensure the tooltip always appears above our window
::SetWindowPos(m_wndToolTip.m_hWnd, HWND_TOPMOST,0,0,0,0,
SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOSIZE);
TOOLINFO ti;
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = 0;
ti.hwnd = m_hTheWnd;
ti.uId = 1;
ti.hinst = NULL;
ti.lpszText = m_bWndLess ? ti.lpszText = _T("My Windowless Tip") : ti.lpszText = _T("My Windowed Tip");
m_wndToolTip.SendMessage(TTM_ADDTOOL, 0, (LPARAM)&ti);
}
return hr;
}
void RelayEvent(UINT message, WPARAM wParam, LPARAM lParam)
{
if (NULL != m_wndToolTip.m_hWnd)
{
MSG msg;
msg.hwnd= m_hTheWnd;
msg.message= message;
msg.wParam= wParam;
msg.lParam= lParam;
msg.time= 0;
msg.pt.x= LOWORD (lParam);
msg.pt.y= HIWORD (lParam);
::SendMessage(m_wndToolTip.m_hWnd, TTM_RELAYEVENT, 0, (LPARAM)&msg);
}
}
LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam,BOOL bHandled)
{
bHandled = FALSE;
RelayEvent(uMsg, (WPARAM)wParam,MAKELPARAM(LOWORD(lParam), HIWORD(lParam)));
return 0L;
}
LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam,BOOL& bHandled)
{
if (m_wndToolTip.m_hWnd)
{
POINT pt;
static uId;
pt.x = LOWORD(lParam);
pt.y = HIWORD(lParam);
TOOLINFO ti;
ti.cbSize = sizeof(TOOLINFO);
ti.hwnd = m_hTheWnd;
ti.uId = 1;
ti.rect.left = pt.x;
ti.rect.right = pt.x+1;
ti.rect.top = pt.y;
ti.rect.bottom = pt.y+1;
m_wndToolTip.SendMessage(TTM_NEWTOOLRECT, 0, (LPARAM)&ti);
RelayEvent(uMsg, wParam, lParam);
}
return 0;
}
173974 How to add MFC support to an ATL project
HRESULT InPlaceActivate(LONG iVerb, const RECT* prcPosRect=NULL)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CWnd parent;
HRESULT hr;
hr = CComControlBase::InPlaceActivate(iVerb, prcPosRect);
if (m_wndToolTip.m_hWnd == NULL)
{
if (m_bWndLess)
{
HDC hDC;
// Get the HDC from the client
m_spInPlaceSite->GetDC(NULL, OLEDC_NODRAW, &hDC);
m_hTheWnd = WindowFromDC(hDC);
m_spInPlaceSite->ReleaseDC(hDC);
}
else
m_hTheWnd = m_hWnd;
::InitCommonControls();
parent.Attach(m_hTheWnd);
RECT rect = {0,0,0,0};
if (!m_wndToolTip.Create(&parent))
TRACE("Unable to create tip window.\n");
else if (!m_wndToolTip.AddTool(&parent, LPCTSTR("TTip2 Control"),&rect, 1))
TRACE("Unable to add tip for the control window.\n");
else
m_wndToolTip.Activate(TRUE);
parent.Detach();
}
return hr;
}
void RelayEvent(UINT message, WPARAM wParam, LPARAM lParam)
{
if (NULL != m_wndToolTip.m_hWnd)
{
MSG msg;
msg.hwnd= m_hTheWnd;
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);
}
}
LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam,BOOL& bHandled)
{
if (m_wndToolTip.m_hWnd)
{
POINT pt;
static uId;
pt.x = LOWORD(lParam);
pt.y = HIWORD(lParam);
TOOLINFO ti;
ti.cbSize = sizeof(TOOLINFO);
ti.hwnd = m_hTheWnd;
uId = 1;
ti.uId = uId;
ti.rect.left = pt.x;
ti.rect.right = pt.x+1;
ti.rect.top = pt.y;
ti.rect.bottom = pt.y+1;
m_ttip.SendMessage(TTM_NEWTOOLRECT, 0, (LPARAM)&ti);
}
RelayEvent(uMsg, wParam, lParam);
return 0;
}
LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam,BOOL bHandled)
{
bHandled = FALSE;
RelayEvent(uMsg, (WPARAM)wParam,MAKELPARAM(LOWORD(lParam), HIWORD(lParam)));
return 0L;
}
134209 How to use the ToolTip common control
173974 How to add MFC support to an ATL project
223439 How to using class wrappers to access Windows common controls in ATL
141871 How to add tooltips to ActiveX controls
Additional query words: ATL ActiveX tooltip
Keywords: kbhowto kbtooltip kbctrlcreate KB201540