我创建了一个ActiveX控件,并在界面中实现了工具提示。在调试版本DEBUG,工具提示正常;但在发布版release,工具提示一直不显示,查了很久不知所因,求高人帮忙!
我的工具提示实现过程:
1、使能工具提示
void CCtrl::PreSubclassWindow() 
{
// TODO: Add your specialized code here and/or call the base class
EnableToolTips(TRUE); COleControl::PreSubclassWindow();
}2、重载OnToolHitTest
//{{AFX_VIRTUAL(CBOLPCtrl)
public:
……
virtual int OnToolHitTest(CPoint point, TOOLINFO *pTI) const;
……;
//}}AFX_VIRTUALint CBOLPCtrl::OnToolHitTest(CPoint point, TOOLINFO *pTI) const
{
CRect rect;
if (m_fFactor != 0)
{
point.x = (long)(point.x / (1 + m_fFactor));
point.y = (long)(point.y / (1 + m_fFactor));
}

if (m_DeviceManager.m_DeviceCardRect.PtInRect(point))
{
rect = m_DeviceManager.m_DeviceCardRect;
if (m_fFactor != 0)
{
rect.left = (long)(rect.left * (1 + m_fFactor));
rect.top = (long)(rect.top * (1 + m_fFactor));
rect.right = (long)(rect.right * (1 + m_fFactor));
rect.bottom = (long)(rect.bottom * (1 + m_fFactor));
}

pTI->hwnd = m_hWnd;
pTI->uId = (UINT)point.x;
pTI->lpszText = LPSTR_TEXTCALLBACK;
pTI->rect = rect;// CString str;
// str.Format("OnToolHitTest:%d; left:%d; right:%d; top:%d; bottom:%d", pTI->uId, 
// pTI->rect.left, pTI->rect.right, pTI->rect.top, pTI->rect.bottom);
// AfxMessageBox(str); return pTI->uId;
}
return -1;
}3、处理TTN_NEEDTEXT消息
//{{AFX_MSG(CBOLPCtrl)
……
afx_msg BOOL OnToolTipNotify(UINT id, NMHDR * pNMHDR, LRESULT * pResult);
……
//}}AFX_MSG //{{AFX_MSG_MAP(CBOLPCtrl)
……
ON_NOTIFY_EX(TTN_NEEDTEXTA, 0, OnToolTipNotify)
ON_NOTIFY_EX(TTN_NEEDTEXTW, 0, OnToolTipNotify)
        ……
//}}AFX_MSG_MAPBOOL CBOLPCtrl::OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult)
{
// AfxMessageBox("OnToolTipNotify"); TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
CString strTipText = "";
if (m_nLanguageType == 1)
{
strTipText = "远端信息: ";
}
else if (m_nLanguageType == 2)
{
strTipText = "Remote Info: ";
} UINT nID = pNMHDR->idFrom;
// Do not process the message from built in tooltip 
if( nID == (UINT)m_hWnd &&
(( pNMHDR->code == TTN_NEEDTEXTA && pTTTA->uFlags & TTF_IDISHWND ) ||
( pNMHDR->code == TTN_NEEDTEXTW && pTTTW->uFlags & TTF_IDISHWND ) ) )
return FALSE; // Get the mouse position
const MSG* pMessage;
CPoint pt;
pMessage = GetCurrentMessage(); // get mouse pos 
ASSERT ( pMessage );
pt = pMessage->pt;
ScreenToClient( &pt );

if(m_fFactor != 0)
{
pt.x = (long)(pt.x / (1 + m_fFactor));
pt.y = (long)(pt.y / (1 + m_fFactor));
}

if (m_DeviceManager.m_DeviceCardRect.PtInRect(pt))
{
CARD_REMOTEINFO CardRemoteInfo;
m_DeviceManager.GetDeviceRemoteInfo(CardRemoteInfo);
strTipText = strTipText + CardRemoteInfo.ucCardRemote;
}// AfxMessageBox(strTipText);

#ifndef _UNICODE
if (pNMHDR->code == TTN_NEEDTEXTA)
lstrcpyn(pTTTA->szText, strTipText, 80);
else
_mbstowcsz(pTTTW->szText, strTipText, 80);
#else
if (pNMHDR->code == TTN_NEEDTEXTA)
_wcstombsz(pTTTA->szText, strTipText, 80);
else
lstrcpyn(pTTTW->szText, strTipText, 80);
#endif
*pResult = 0;

return TRUE;    // message was handled
}