如何使用WTL中的CToolTipCtrl类?

Semigod 2002-10-20 01:36:04
请问如何在ATL对话框中使用WTL中的CToolTipCtrl类?要使用它应该有哪些步骤
...全文
585 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Semigod 2002-10-24
  • 打赏
  • 举报
回复
呵呵,虽然楼上的说得不是很完整,而且在我的程序中无法使用,但是基本方法是正确的(这种方法只适合对一个自定义控件加tooltip)
问题我自己用另外的方法解决了,结贴
microran2000 2002-10-21
  • 打赏
  • 举报
回复
创建一个新类,定义如下:
#pragma once
class CMyTip : public CWindowImpl<CMyTip>
{
public:
DECLARE_WND_CLASS_EX(NULL, 0, COLOR_3DFACE)

LPCTSTR m_lpstrInfo;

enum { m_nToolTipID = 1313 };
CToolTipCtrl m_tooltip;


CMyTip() : 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;

// CClientDC dc(m_hWnd); // will not really paint
// HFONT hFontOld = dc.SelectFont(AtlGetStockFont(DEFAULT_GUI_FONT));

// RECT rcText = rect;
// dc.DrawText(m_lpstrInfo, -1, &rcText, DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_NOPREFIX | DT_CALCRECT);
// BOOL bTooLong = (rcText.right > rect.right);
// if(bTooLong)
m_tooltip.UpdateTipText(m_lpstrInfo, m_hWnd, m_nToolTipID);
m_tooltip.Activate(true);

// dc.SelectFont(hFontOld);

// Invalidate();
// UpdateWindow();
}

BEGIN_MSG_MAP(CMyTip)
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;
}


};

使用时包含上面的文件
#include "InfoTip.h"


在类代码中定义成员变量:
CMyTip m_InfoTipEdit;
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{

m_InfoTipEdit.Init( GetDlgItem( IDC_PASSWORD ), "输入密码" );
...
}
其中IDC_PASSWORD为对话框中的控件标识。
rivershan 2002-10-20
  • 打赏
  • 举报
回复
GZ~

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧