2 * sizetip.c - resize tips for PuTTY(tel) terminal window.
11 static ATOM tip_class = 0;
13 static HFONT tip_font;
14 static COLORREF tip_bg;
15 static COLORREF tip_text;
17 static LRESULT CALLBACK SizeTipWndProc(HWND hWnd, UINT nMsg,
18 WPARAM wParam, LPARAM lParam)
35 hdc = BeginPaint(hWnd, &ps);
37 SelectObject(hdc, tip_font);
38 SelectObject(hdc, GetStockObject(BLACK_PEN));
40 hbr = CreateSolidBrush(tip_bg);
41 holdbr = SelectObject(hdc, hbr);
43 GetClientRect(hWnd, &cr);
44 Rectangle(hdc, cr.left, cr.top, cr.right, cr.bottom);
46 wtlen = GetWindowTextLength(hWnd);
47 wt = (LPTSTR) snewn(wtlen + 1, TCHAR);
48 GetWindowText(hWnd, wt, wtlen + 1);
50 SetTextColor(hdc, tip_text);
51 SetBkColor(hdc, tip_bg);
53 TextOut(hdc, cr.left + 3, cr.top + 3, wt, wtlen);
57 SelectObject(hdc, holdbr);
68 DeleteObject(tip_font);
74 LPCTSTR str = (LPCTSTR) lParam;
76 HDC hdc = CreateCompatibleDC(NULL);
78 SelectObject(hdc, tip_font);
79 GetTextExtentPoint32(hdc, str, _tcslen(str), &sz);
81 SetWindowPos(hWnd, NULL, 0, 0, sz.cx + 6, sz.cy + 6,
82 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
83 InvalidateRect(hWnd, NULL, FALSE);
90 return DefWindowProc(hWnd, nMsg, wParam, lParam);
93 static HWND tip_wnd = NULL;
94 static int tip_enabled = 0;
96 void UpdateSizeTip(HWND src, int cx, int cy)
104 NONCLIENTMETRICS nci;
106 /* First make sure the window class is registered */
110 wc.style = CS_HREDRAW | CS_VREDRAW;
111 wc.lpfnWndProc = SizeTipWndProc;
114 wc.hInstance = hinst;
117 wc.hbrBackground = NULL;
118 wc.lpszMenuName = NULL;
119 wc.lpszClassName = "SizeTipClass";
121 tip_class = RegisterClass(&wc);
124 /* Default values based on Windows Standard color scheme */
126 tip_font = GetStockObject(SYSTEM_FONT);
127 tip_bg = RGB(255, 255, 225);
128 tip_text = RGB(0, 0, 0);
131 /* Prepare other GDI objects and drawing info */
133 tip_bg = GetSysColor(COLOR_INFOBK);
134 tip_text = GetSysColor(COLOR_INFOTEXT);
136 memset(&nci, 0, sizeof(NONCLIENTMETRICS));
137 nci.cbSize = sizeof(NONCLIENTMETRICS);
138 SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
139 sizeof(NONCLIENTMETRICS), &nci, 0);
140 tip_font = CreateFontIndirect(&nci.lfStatusFont);
143 /* Generate the tip text */
145 sprintf(str, "%dx%d", cx, cy);
153 /* calculate the tip's size */
155 hdc = CreateCompatibleDC(NULL);
156 GetTextExtentPoint32(hdc, str, _tcslen(str), &sz);
159 GetWindowRect(src, &wr);
169 /* Create the tip window */
172 CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
173 MAKEINTRESOURCE(tip_class), str, WS_POPUP, ix,
174 iy, sz.cx, sz.cy, NULL, NULL, hinst, NULL);
176 ShowWindow(tip_wnd, SW_SHOWNOACTIVATE);
180 /* Tip already exists, just set the text */
182 SetWindowText(tip_wnd, str);
186 void EnableSizeTip(int bEnable)
188 if (tip_wnd && !bEnable) {
189 DestroyWindow(tip_wnd);
193 tip_enabled = bEnable;