9 static ATOM tip_class = 0;
11 static HFONT tip_font;
12 static COLORREF tip_bg;
13 static COLORREF tip_text;
15 static LRESULT CALLBACK SizeTipWndProc(HWND hWnd, UINT nMsg,
16 WPARAM wParam, LPARAM lParam)
33 hdc = BeginPaint(hWnd, &ps);
35 SelectObject(hdc, tip_font);
36 SelectObject(hdc, GetStockObject(BLACK_PEN));
38 hbr = CreateSolidBrush(tip_bg);
39 holdbr = SelectObject(hdc, hbr);
41 GetClientRect(hWnd, &cr);
42 Rectangle(hdc, cr.left, cr.top, cr.right, cr.bottom);
44 wtlen = GetWindowTextLength(hWnd);
45 wt = (LPTSTR) snewn(wtlen + 1, TCHAR);
46 GetWindowText(hWnd, wt, wtlen + 1);
48 SetTextColor(hdc, tip_text);
49 SetBkColor(hdc, tip_bg);
51 TextOut(hdc, cr.left + 3, cr.top + 3, wt, wtlen);
55 SelectObject(hdc, holdbr);
66 DeleteObject(tip_font);
72 LPCTSTR str = (LPCTSTR) lParam;
74 HDC hdc = CreateCompatibleDC(NULL);
76 SelectObject(hdc, tip_font);
77 GetTextExtentPoint32(hdc, str, _tcslen(str), &sz);
79 SetWindowPos(hWnd, NULL, 0, 0, sz.cx + 6, sz.cy + 6,
80 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
81 InvalidateRect(hWnd, NULL, FALSE);
88 return DefWindowProc(hWnd, nMsg, wParam, lParam);
91 static HWND tip_wnd = NULL;
92 static int tip_enabled = 0;
94 void UpdateSizeTip(HWND src, int cx, int cy)
102 NONCLIENTMETRICS nci;
104 /* First make sure the window class is registered */
108 wc.style = CS_HREDRAW | CS_VREDRAW;
109 wc.lpfnWndProc = SizeTipWndProc;
112 wc.hInstance = hinst;
115 wc.hbrBackground = NULL;
116 wc.lpszMenuName = NULL;
117 wc.lpszClassName = "SizeTipClass";
119 tip_class = RegisterClass(&wc);
122 /* Default values based on Windows Standard color scheme */
124 tip_font = GetStockObject(SYSTEM_FONT);
125 tip_bg = RGB(255, 255, 225);
126 tip_text = RGB(0, 0, 0);
129 /* Prepare other GDI objects and drawing info */
131 tip_bg = GetSysColor(COLOR_INFOBK);
132 tip_text = GetSysColor(COLOR_INFOTEXT);
134 memset(&nci, 0, sizeof(NONCLIENTMETRICS));
135 nci.cbSize = sizeof(NONCLIENTMETRICS);
136 SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
137 sizeof(NONCLIENTMETRICS), &nci, 0);
138 tip_font = CreateFontIndirect(&nci.lfStatusFont);
141 /* Generate the tip text */
143 sprintf(str, "%dx%d", cx, cy);
151 /* calculate the tip's size */
153 hdc = CreateCompatibleDC(NULL);
154 GetTextExtentPoint32(hdc, str, _tcslen(str), &sz);
157 GetWindowRect(src, &wr);
167 /* Create the tip window */
170 CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
171 MAKEINTRESOURCE(tip_class), str, WS_POPUP, ix,
172 iy, sz.cx, sz.cy, NULL, NULL, hinst, NULL);
174 ShowWindow(tip_wnd, SW_SHOWNOACTIVATE);
178 /* Tip already exists, just set the text */
180 SetWindowText(tip_wnd, str);
184 void EnableSizeTip(int bEnable)
186 if (tip_wnd && !bEnable) {
187 DestroyWindow(tip_wnd);
191 tip_enabled = bEnable;