16 static ATOM tip_class
= 0;
18 static HFONT tip_font
;
19 static COLORREF tip_bg
;
20 static COLORREF tip_text
;
22 static LRESULT CALLBACK
SizeTipWndProc(HWND hWnd
, UINT nMsg
,
23 WPARAM wParam
, LPARAM lParam
)
40 hdc
= BeginPaint(hWnd
, &ps
);
42 SelectObject(hdc
, tip_font
);
43 SelectObject(hdc
, GetStockObject(BLACK_PEN
));
45 hbr
= CreateSolidBrush(tip_bg
);
46 holdbr
= SelectObject(hdc
, hbr
);
48 GetClientRect(hWnd
, &cr
);
49 Rectangle(hdc
, cr
.left
, cr
.top
, cr
.right
, cr
.bottom
);
51 wtlen
= GetWindowTextLength(hWnd
);
52 wt
= (LPTSTR
)malloc((wtlen
+1)*sizeof(TCHAR
));
53 GetWindowText(hWnd
, wt
, wtlen
+1);
55 SetTextColor(hdc
, tip_text
);
56 SetBkColor(hdc
, tip_bg
);
58 TextOut(hdc
, cr
.left
+3, cr
.top
+3, wt
, wtlen
);
62 SelectObject(hdc
, holdbr
);
73 DeleteObject(tip_font
);
79 LPCTSTR str
= (LPCTSTR
)lParam
;
81 HDC hdc
= CreateCompatibleDC(NULL
);
83 SelectObject(hdc
, tip_font
);
84 GetTextExtentPoint32(hdc
, str
, _tcslen(str
), &sz
);
86 SetWindowPos(hWnd
, NULL
, 0, 0, sz
.cx
+6, sz
.cy
+6, SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOACTIVATE
);
87 InvalidateRect(hWnd
, NULL
, FALSE
);
94 return DefWindowProc(hWnd
, nMsg
, wParam
, lParam
);
97 static HWND tip_wnd
= NULL
;
98 static int tip_enabled
= 0;
100 void UpdateSizeTip(HWND src
, int cx
, int cy
)
104 if (!tip_enabled
) return;
107 NONCLIENTMETRICS nci
;
109 /* First make sure the window class is registered */
113 wc
.style
= CS_HREDRAW
|CS_VREDRAW
;
114 wc
.lpfnWndProc
= SizeTipWndProc
;
117 wc
.hInstance
= putty_inst
;
120 wc
.hbrBackground
= NULL
;
121 wc
.lpszMenuName
= NULL
;
122 wc
.lpszClassName
= "SizeTipClass";
124 tip_class
= RegisterClass(&wc
);
128 /* Default values based on Windows Standard color scheme */
130 tip_font
= GetStockObject(SYSTEM_FONT
);
131 tip_bg
= RGB(255, 255, 225);
132 tip_text
= RGB(0, 0, 0);
135 /* Prepare other GDI objects and drawing info */
137 tip_bg
= GetSysColor(COLOR_INFOBK
);
138 tip_text
= GetSysColor(COLOR_INFOTEXT
);
140 memset(&nci
, 0, sizeof(NONCLIENTMETRICS
));
141 nci
.cbSize
= sizeof(NONCLIENTMETRICS
);
142 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(NONCLIENTMETRICS
), &nci
, 0);
143 tip_font
= CreateFontIndirect(&nci
.lfStatusFont
);
146 /* Generate the tip text */
148 sprintf(str
, "%dx%d", cx
, cy
);
156 /* calculate the tip's size */
158 hdc
= CreateCompatibleDC(NULL
);
159 GetTextExtentPoint32(hdc
, str
, _tcslen(str
), &sz
);
162 GetWindowRect(src
, &wr
);
170 /* Create the tip window */
172 tip_wnd
= CreateWindowEx(WS_EX_TOOLWINDOW
|WS_EX_TOPMOST
, MAKEINTRESOURCE(tip_class
), str
, WS_POPUP
,
173 ix
, iy
, sz
.cx
, sz
.cy
,
174 NULL
, NULL
, putty_inst
, 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
;