14 LRESULT CALLBACK
SizeTipWndProc(HWND hWnd
, UINT nMsg
, 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
)malloc((wtlen
+1)*sizeof(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, SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOACTIVATE
);
78 InvalidateRect(hWnd
, NULL
, FALSE
);
85 return DefWindowProc(hWnd
, nMsg
, wParam
, lParam
);
91 void UpdateSizeTip(HWND src
, int cx
, int cy
)
95 if (!tip_enabled
) return;
100 /* First make sure the window class is registered */
104 wc
.style
= CS_HREDRAW
|CS_VREDRAW
;
105 wc
.lpfnWndProc
= SizeTipWndProc
;
108 wc
.hInstance
= putty_inst
;
111 wc
.hbrBackground
= NULL
;
112 wc
.lpszMenuName
= NULL
;
113 wc
.lpszClassName
= "SizeTipClass";
115 tip_class
= RegisterClass(&wc
);
119 /* Default values based on Windows Standard color scheme */
121 tip_font
= GetStockObject(SYSTEM_FONT
);
122 tip_bg
= RGB(255, 255, 225);
123 tip_text
= RGB(0, 0, 0);
126 /* Prepare other GDI objects and drawing info */
128 tip_bg
= GetSysColor(COLOR_INFOBK
);
129 tip_text
= GetSysColor(COLOR_INFOTEXT
);
131 memset(&nci
, 0, sizeof(NONCLIENTMETRICS
));
132 nci
.cbSize
= sizeof(NONCLIENTMETRICS
);
133 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(NONCLIENTMETRICS
), &nci
, 0);
134 tip_font
= CreateFontIndirect(&nci
.lfStatusFont
);
137 /* Generate the tip text */
139 _sntprintf(str
, 16, "%dx%d", cx
, cy
);
148 /* calculate the tip's size */
150 hdc
= CreateCompatibleDC(NULL
);
151 GetTextExtentPoint32(hdc
, str
, _tcslen(str
), &sz
);
154 GetWindowRect(src
, &wr
);
162 /* Create the tip window */
164 tip_wnd
= CreateWindowEx(WS_EX_TOOLWINDOW
|WS_EX_TOPMOST
, MAKEINTRESOURCE(tip_class
), str
, WS_POPUP
,
165 ix
, iy
, sz
.cx
, sz
.cy
,
166 NULL
, NULL
, putty_inst
, NULL
);
168 ShowWindow(tip_wnd
, SW_SHOWNOACTIVATE
);
172 /* Tip already exists, just set the text */
174 SetWindowText(tip_wnd
, str
);
178 void EnableSizeTip(int bEnable
)
180 if (tip_wnd
&& !bEnable
) {
181 DestroyWindow(tip_wnd
);
185 tip_enabled
= bEnable
;