//file:InfoTip.h
#pragma once
#include <atlwin.h>
class CInfoTip :
public ATL::CWindowImpl<CInfoTip>
{
public:
DECLARE_WND_CLASS_EX(NULL, 0, COLOR_3DFACE)
LPCTSTR m_lpstrInfo;
enum { m_nToolTipID = 1313 };
WTL::CToolTipCtrl m_tooltip;
CInfoTip():m_lpstrInfo(NULL)
{ }
void Init(HWND hWnd, LPCTSTR lpstrName)
{
ATLASSERT(::IsWindow(hWnd));
SubclassWindow(hWnd);
// Set tooltip
m_tooltip.Create(m_hWnd);
ATLASSERT(m_tooltip.IsWindow());
RECT rect;
GetClientRect(&rect);
CToolInfo ti(0, m_hWnd, m_nToolTipID, &rect, NULL);
m_tooltip.AddTool(&ti);
// set text
m_lpstrInfo = lpstrName;
if(m_lpstrInfo == NULL)
return;
m_tooltip.UpdateTipText(m_lpstrInfo, m_hWnd, m_nToolTipID);
m_tooltip.Activate(true);
}
BEGIN_MSG_MAP(CInfoTip)
MESSAGE_RANGE_HANDLER(WM_MOUSEFIRST, WM_MOUSELAST,OnMouseMessage)
END_MSG_MAP()
LRESULT OnMouseMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if(m_tooltip.IsWindow())
{
MSG msg = { m_hWnd, uMsg, wParam, lParam };
m_tooltip.RelayEvent(&msg);
}
bHandled = FALSE;
return 1;
}
};
//使用:
CInfoTip m_InfoTipEdit;
m_InfoTipEdit.Init( GetDlgItem( IDOK ), "输入密码 " );