int CToolTipCtrlZ::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CToolTipCtrl::OnCreate(lpCreateStruct) == -1) return -1; // TODO: 在此添加您专用的创建代码 GetParent()->EnableToolTips(); Activate(TRUE); SetMaxTipWidth(SHRT_MAX); SetMargin(CRect(4, 4, 4, 4)); return 0; }
int CRichToolTipCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CToolTipCtrl::OnCreate(lpCreateStruct) == -1) return -1; // set the max width to half of the screen width, and // force the ability to use CRLFs to make multi-line tips SetMaxTipWidth(::GetSystemMetrics(SM_CXSCREEN) / 2); // create a child richedit control m_edit.Create(WS_CHILD | ES_LEFT | ES_MULTILINE | ES_READONLY, CRect(0, 0, 0, 0), this, 1); m_edit.ModifyStyleEx(0, WS_EX_TRANSPARENT); // make the background transparent, so we get the correct tool-tip background // set the edit control's ole callback handler VERIFY(m_edit.SetOLECallback(&m_xRichEditOleCallback)); return 0; }
BalloonMsg::BalloonMsg(CWnd* wnd, const TCHAR* title, const TCHAR* msg, MsgIcon icon, CPoint pos) { if (wnd == 0) { ASSERT(false); delete this; return; } ASSERT(msg && title); if (!wnd->IsWindowVisible()) // it only makes sense to display balloon for visible windows { MessageBox(msg, title); delete this; return; } closing_ = false; Create(0, WS_POPUP | TTS_NOPREFIX | TTS_BALLOON | TTS_ALWAYSTIP); if (m_hWnd == 0) return; msg_ = msg; title_ = title; const TCHAR* text= msg_; struct OLDTOOLINFO { UINT cbSize; UINT uFlags; HWND hwnd; UINT uId; RECT rect; HINSTANCE hinst; LPTSTR lpszText; } ti; // new TOOLINFO with extra reserved field changes the way balloons work rendering them useless... // TOOLINFO ti; ti.cbSize = sizeof ti; ti.uFlags = TTF_TRACK | TTF_IDISHWND; ti.hwnd = wnd->m_hWnd; ti.uId = 1; ti.hinst = NULL; ti.lpszText = const_cast<TCHAR*>(text); //LPSTR_TEXTCALLBACK; ti.rect.left = 0; ti.rect.top = 0; ti.rect.right = 0; ti.rect.bottom = 0; // ti.lParam = 0; SendMessage(TTM_ADDTOOL, 0, LPARAM(&ti)); SetMaxTipWidth(300); // SetTitle(icon, title_); const TCHAR* ttl= title_; SendMessage(TTM_SETTITLE, icon, LPARAM(ttl)); if (pos.x == 0 && pos.y == 0) { CRect rect; wnd->GetWindowRect(rect); pos = rect.CenterPoint(); } SendMessage(TTM_TRACKPOSITION, 0, MAKELONG(pos.x, pos.y)); SendMessage(TTM_TRACKACTIVATE, true, LPARAM(&ti)); ::MessageBeep(MB_OK); SetTimer(TIMER_ID, 10000, 0); wnd->SetFocus(); SubclassWnd(*wnd); InstallMouseHook(); }