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