MFC dll无法显示tooltip问题

需要在APP 代码中添加hock

class CTestApp : public CWinApp
{
public:
	CTestApp();
	HHOOK m_hHook;
// 重写
public:
	static LRESULT CALLBACK GetMessageProc(int nCode, WPARAM wParam, LPARAM lParam);
	virtual BOOL InitInstance();

	DECLARE_MESSAGE_MAP()
	virtual int ExitInstance();
};

```cpp
#include "stdafx.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


BEGIN_MESSAGE_MAP(CTestApp, CWinApp)
END_MESSAGE_MAP()


// CTestApp 构造

CTestApp::CTestApp()
{
	// TODO:  在此处添加构造代码,
	// 将所有重要的初始化放置在 InitInstance 中
}


// 唯一的一个 CTestApp 对象

CTestApp theApp;


// CTestApp 初始化

LRESULT CALLBACK CTestApp::GetMessageProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	LPMSG lpMsg = (LPMSG)lParam;

	if (AfxGetApp()->PreTranslateMessage(lpMsg))
	{
		lpMsg->message = WM_NULL;
		lpMsg->lParam = 0L;
		lpMsg->wParam = 0;
	}
	// Passes the hook information to the next hook procedure in
	// the current hook chain.
	return ::CallNextHookEx(theApp.m_hHook, nCode, wParam, lParam);
}

BOOL CTestApp::InitInstance()
{
	CWinApp::InitInstance();

	AfxEnableControlContainer();
	BOOL bol = AfxOleInit();
	//初始化控件环境 AfxEnableControlContainer(); 
	HRESULT rs = CoInitialize(NULL);
	m_hHook = ::SetWindowsHookEx(
		WH_GETMESSAGE,
		GetMessageProc,
		AfxGetInstanceHandle(),
		GetCurrentThreadId());

	return TRUE;
}

int CTestApp::ExitInstance()
{
	// TODO:  在此添加专用代码和/或调用基类
	UnhookWindowsHookEx((HHOOK)m_hHook);
	return CWinApp::ExitInstance();
}

在实际对话框代码中先定义:

CToolTipCtrl m_ToolTip;

在适当的地方初始化

if (m_ToolTip.m_hWnd == NULL)
{
		m_ToolTip.Create(this);
		m_ToolTip.Activate(TRUE);
		m_ToolTip.SetTipBkColor(RGB(255, 255, 255));
		m_ToolTip.AddTool(GetDlgItem(IDC_ALG_TOOL_COMBO), _T(""));
		m_ToolTip.AddTool(GetDlgItem(IDC_COMBO_IMAGE), _T(""));
}

重写PreTranslateMessage

BOOL CTestDialog::PreTranslateMessage(MSG* pMsg)
{
	// TODO:  在此添加专用代码和/或调用基类

	switch (pMsg->message)
	{
	case WM_MOUSEMOVE:
		m_ToolTip.RelayEvent(pMsg);
		break;
	default:
		break;
	}

	// 不要对消息拦截,按实际情况处理
	return FALSE;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WJsuperrunner

你的鼓励是我最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值