2#include "helper/SToolTip.h"
4#define COMPILE_MULTIMON_STUBS
21 m_id.dwHi = m_id.dwLow = 0;
33 HWND hWnd =
SNativeWnd::CreateNative(_T(
"soui tooltip"), WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, WS_EX_TOOLWINDOW | WS_EX_TOPMOST | WS_EX_NOACTIVATE, 0, 0, 0, 0, NULL, 0, NULL);
38 GetObject(GetStockObject(DEFAULT_GUI_FONT),
sizeof(lf), &lf);
40 _tcscpy(lf.lfFaceName, _T(
"宋体"));
41 m_font = CreateFontIndirect(&lf);
50 switch (pMsg->message)
59 case WM_NCLBUTTONDOWN:
61 case WM_NCRBUTTONDOWN:
64 case WM_NCMBUTTONDOWN:
69 CPoint pt(GET_X_LPARAM(pMsg->lParam), GET_Y_LPARAM(pMsg->lParam));
70 if (m_id.bNcTip || !m_rcTarget.PtInRect(pt))
79 SetWindowPos(0, pt.x, pt.y + 24, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOSENDCHANGING | SWP_NOACTIVATE);
85 CPoint pt(GET_X_LPARAM(pMsg->lParam), GET_Y_LPARAM(pMsg->lParam));
89 pt2 -= rcWnd.TopLeft();
90 if (!m_id.bNcTip || !m_rcTarget.PtInRect(pt2))
98 SetWindowPos(0, pt.x, pt.y + 24, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOSENDCHANGING | SWP_NOACTIVATE);
108 if (m_nScale != nScale)
111 DeleteObject(m_font);
113 GetObject(GetStockObject(DEFAULT_GUI_FONT),
sizeof(lf), &lf);
114 lf.lfHeight = -12 * nScale / 100;
115 _tcscpy(lf.lfFaceName, _T(
"宋体"));
116 m_font = CreateFontIndirect(&lf);
125 SSLOGI() <<
"SetToolTip," << pszTip;
128 m_strTip.Replace(_T(
"\\n"), _T(
"\n"));
130 m_tipAlign = tipAlign;
151 if (m_id.dwHi == id->
dwHi && m_id.dwLow == id->
dwLow)
157 m_strTip.Replace(_T(
"\\n"), _T(
"\n"));
170 m_id.dwHi = m_id.dwLow = 0;
179 m_rcTarget.SetRect(0, 0, 0, 0);
182 else if (!m_strTip.IsEmpty())
185 CRect rcText(0, 0, 500, 1000);
186 HFONT oldFont = (HFONT)SelectObject(hdc, m_font);
187 DrawText(hdc, m_strTip, -1, &rcText, DT_CALCRECT | DT_LEFT | DT_WORDBREAK);
188 SelectObject(hdc, oldFont);
198 hMonitor = MonitorFromRect(&rcWnd, MONITOR_DEFAULTTONEAREST);
199 mi.cbSize =
sizeof(mi);
200 GetMonitorInfo(hMonitor, &mi);
201 int cx = mi.rcMonitor.right;
202 int cy = mi.rcMonitor.bottom;
205 rcWnd.right = rcWnd.left + rcText.right + 2 * MARGIN_TIP;
206 rcWnd.bottom = rcWnd.top + rcText.bottom + 2 * MARGIN_TIP;
208 if (rcWnd.right > cx)
209 rcWnd.OffsetRect(cx - rcWnd.right, 0);
210 if (rcWnd.bottom > cy)
211 rcWnd.OffsetRect(0, cy - rcWnd.bottom);
216 rcWnd.InflateRect(MARGIN_TIP, MARGIN_TIP);
218 CPoint pt = m_rcTarget.CenterPoint();
222 pt.x = m_rcTarget.left - rcWnd.Width();
225 pt.x = m_rcTarget.right;
228 pt.x -= rcWnd.Width() / 2;
234 pt.y = m_rcTarget.top - rcWnd.Height();
237 pt.y = m_rcTarget.bottom;
240 pt.y -= rcWnd.Height() / 2;
245 SetWindowPos(HWND_TOPMOST, rcWnd.left, rcWnd.top, rcWnd.Width(), rcWnd.Height(), SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
256 SetTimer(TIMERID_SPAN, m_nShowSpan);
268 dc = ::BeginPaint(
m_hWnd, &ps);
272 HBRUSH br = CreateSolidBrush(GetSysColor(COLOR_INFOBK));
273 HGDIOBJ hOld = SelectObject(dc, br);
274 Rectangle(dc, rc.left, rc.top, rc.right, rc.bottom);
275 SelectObject(dc, hOld);
278 rc.DeflateRect(MARGIN_TIP, MARGIN_TIP);
279 SetBkMode(dc, TRANSPARENT);
280 HGDIOBJ hOldFont = SelectObject(dc, m_font);
281 ::DrawText(dc, m_strTip, -1, &rc, DT_WORDBREAK);
282 SelectObject(dc, hOldFont);
HDC GetDC() OVERRIDE
Retrieves a device context for the window.
BOOL GetWindowRect(LPRECT lpRect) SCONST OVERRIDE
Retrieves the window rectangle.
BOOL IsWindowVisible() SCONST OVERRIDE
Checks if the window is visible.
BOOL IsWindow() SCONST OVERRIDE
Checks if the handle is a valid window handle.
UINT_PTR SetTimer(UINT_PTR nIDEvent, UINT nElapse, void(CALLBACK *lpfnTimer)(HWND, UINT, UINT_PTR, DWORD)=NULL) OVERRIDE
Sets a timer for the window.
BOOL ClientToScreen(LPPOINT lpPoint) SCONST OVERRIDE
Converts client coordinates to screen coordinates.
BOOL ShowWindow(int nCmdShow) OVERRIDE
Sets the show state of the window.
BOOL KillTimer(UINT_PTR nIDEvent) OVERRIDE
Kills a timer for the window.
HWND m_hWnd
Handle to the window.
BOOL GetClientRect(LPRECT lpRect) SCONST OVERRIDE
Retrieves the client rectangle.
HWND CreateNative(LPCTSTR lpWindowName, DWORD dwStyle, DWORD dwExStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, int nID=0, LPVOID lpParam=0) OVERRIDE
Creates a native window.
BOOL SetWindowPos(HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags) OVERRIDE
Sets the window position.
virtual void OnFinalMessage(HWND hWnd)
Handles the final message for the window.
int ReleaseDC(HDC hDC) OVERRIDE
Releases a device context.
BOOL InvalidateRect(LPCRECT lpRect, BOOL bErase=TRUE) OVERRIDE
Invalidates a specified rectangle of the window.
void SetToolTip(LPCRECT rc, UINT tipAlign, LPCTSTR pszTip, int nScale) OVERRIDE
设置提示信息
virtual ~STipCtrl(void)
析构函数
void RelayEvent(const MSG *pMsg) OVERRIDE
传递事件
void ShowTip(BOOL bShow)
显示或隐藏提示
void OnPaint(HDC dc)
处理绘制消息
void UpdateFont(int nScale)
更新字体
void UpdateTip(const TIPID *id, RECT rc, LPCTSTR pszTip, int nScale) OVERRIDE
更新提示信息
BOOL PreTranslateMessage(MSG *pMsg) OVERRIDE
预翻译消息
virtual void OnFinalMessage(HWND hWnd)
处理最终消息
void OnTimer(UINT_PTR idEvent)
处理定时器消息
void ClearTip() OVERRIDE
清除提示信息
Identifier for a tooltip.
DWORD dwLow
ID2, used to save additional data.
DWORD dwHi
ID1, used to save a SWND.