7 static ATOM tip_class = 0;
10 static COLORREF tip_bg;
11 static COLORREF tip_text;
13 static LRESULT CALLBACK SizeTipWndProc(HWND hWnd, UINT nMsg,
14 WPARAM wParam, LPARAM lParam)
31 hdc = BeginPaint(hWnd, &ps);
33 SelectObject(hdc, tip_font);
34 SelectObject(hdc, GetStockObject(BLACK_PEN));
36 hbr = CreateSolidBrush(tip_bg);
37 holdbr = SelectObject(hdc, hbr);
39 GetClientRect(hWnd, &cr);
40 Rectangle(hdc, cr.left, cr.top, cr.right, cr.bottom);
42 wtlen = GetWindowTextLength(hWnd);
43 wt = (LPTSTR) snewn(wtlen + 1, TCHAR);
44 GetWindowText(hWnd, wt, wtlen + 1);
46 SetTextColor(hdc, tip_text);
47 SetBkColor(hdc, tip_bg);
49 TextOut(hdc, cr.left + 3, cr.top + 3, wt, wtlen);
53 SelectObject(hdc, holdbr);
64 DeleteObject(tip_font);
70 LPCTSTR str = (LPCTSTR) lParam;
72 HDC hdc = CreateCompatibleDC(NULL);
74 SelectObject(hdc, tip_font);
75 GetTextExtentPoint32(hdc, str, _tcslen(str), &sz);
77 SetWindowPos(hWnd, NULL, 0, 0, sz.cx + 6, sz.cy + 6,
78 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
79 InvalidateRect(hWnd, NULL, FALSE);
86 return DefWindowProc(hWnd, nMsg, wParam, lParam);
89 static HWND tip_wnd = NULL;
90 static int tip_enabled = 0;
92 void UpdateSizeTip(HWND src, int cx, int cy)
100 NONCLIENTMETRICS nci;
102 /* First make sure the window class is registered */
106 wc.style = CS_HREDRAW | CS_VREDRAW;
107 wc.lpfnWndProc = SizeTipWndProc;
110 wc.hInstance = hinst;
113 wc.hbrBackground = NULL;
114 wc.lpszMenuName = NULL;
115 wc.lpszClassName = "SizeTipClass";
117 tip_class = RegisterClass(&wc);
120 /* Default values based on Windows Standard color scheme */
122 tip_font = GetStockObject(SYSTEM_FONT);
123 tip_bg = RGB(255, 255, 225);
124 tip_text = RGB(0, 0, 0);
127 /* Prepare other GDI objects and drawing info */
129 tip_bg = GetSysColor(COLOR_INFOBK);
130 tip_text = GetSysColor(COLOR_INFOTEXT);
132 memset(&nci, 0, sizeof(NONCLIENTMETRICS));
133 nci.cbSize = sizeof(NONCLIENTMETRICS);
134 SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
135 sizeof(NONCLIENTMETRICS), &nci, 0);
136 tip_font = CreateFontIndirect(&nci.lfStatusFont);
139 /* Generate the tip text */
141 sprintf(str, "%dx%d", cx, cy);
149 /* calculate the tip's size */
151 hdc = CreateCompatibleDC(NULL);
152 GetTextExtentPoint32(hdc, str, _tcslen(str), &sz);
155 GetWindowRect(src, &wr);
165 /* Create the tip window */
168 CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
169 MAKEINTRESOURCE(tip_class), str, WS_POPUP, ix,
170 iy, sz.cx, sz.cy, NULL, NULL, hinst, NULL);
172 ShowWindow(tip_wnd, SW_SHOWNOACTIVATE);
176 /* Tip already exists, just set the text */
178 SetWindowText(tip_wnd, str);
182 void EnableSizeTip(int bEnable)
184 if (tip_wnd && !bEnable) {
185 DestroyWindow(tip_wnd);
189 tip_enabled = bEnable;