#include "stdafx.h" #include "ToolTipDialog.h" IMPLEMENT_DYNAMIC(CToolTipDialog, CAcUiDialog) CToolTipDialog::CToolTipDialog(UINT id, CWnd* pParent /*=NULL*/) : CAcUiDialog(id, pParent) { } BEGIN_MESSAGE_MAP(CToolTipDialog, CAcUiDialog) //{{AFX_MSG_MAP(CObjPreviewDlg) ON_WM_DESTROY() ON_WM_CTLCOLOR() //}}AFX_MSG_MAP END_MESSAGE_MAP() BOOL CToolTipDialog::OnInitDialog() { CAcUiDialog::OnInitDialog(); m_wndToolTip.Create(this); m_wndToolTip.Activate(true); m_wndToolTip.SetMaxTipWidth(250); m_wndToolTip.SetDelayTime(TTDT_AUTOPOP, 4*m_wndToolTip.GetDelayTime(TTDT_AUTOPOP)); return TRUE; } void CToolTipDialog::OnDestroy() { m_wndToolTip.DestroyWindow(); CAcUiDialog::OnDestroy(); } BOOL CToolTipDialog::PreTranslateMessage(MSG* pMsg) { if (pMsg->message >= WM_MOUSEFIRST && pMsg->message <= WM_MOUSELAST) { MSG msg; ::CopyMemory(&msg, pMsg, sizeof(MSG)); HWND hWndParent = ::GetParent(msg.hwnd); while (hWndParent && hWndParent != m_hWnd) { msg.hwnd = hWndParent; hWndParent = ::GetParent(hWndParent); } if (msg.hwnd) { m_wndToolTip.RelayEvent(&msg); } } return CAcUiDialog::PreTranslateMessage(pMsg); } BOOL CToolTipDialog::AddTip(UINT idControl) { HINSTANCE hInstance=NULL; CWnd *pWnd = GetDlgItem(idControl); if (!pWnd) return FALSE; int nRet; CString strTip; if (!hInstance) { nRet=strTip.LoadString(idControl); } else { TCHAR szTemp[1024]=_T(""); nRet=::LoadString(hInstance, idControl, szTemp, 1023); if (nRet) strTip=szTemp; } if (nRet) nRet=m_wndToolTip.AddTool(pWnd,strTip); return (nRet!=0); } BOOL CToolTipDialog::AddTip(UINT idControl, const TCHAR *str) { CWnd *pWnd = GetDlgItem(idControl); if (!pWnd) return FALSE; return m_wndToolTip.AddTool(pWnd,str); } HBRUSH CToolTipDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CAcUiDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (pWnd->IsWindowEnabled()) { CToolInfo toolInfo; if (m_wndToolTip.GetToolInfo(toolInfo, pWnd)) { pDC->SetTextColor(RGB(0,0,255)); } } return hbr; }