15 LRESULT CALLBACK
SizeTipWndProc(HWND hWnd
, UINT nMsg
, WPARAM wParam
, LPARAM lParam
)
32 hdc
= BeginPaint(hWnd
, &ps
);
34 SelectObject(hdc
, tip_font
);
35 SelectObject(hdc
, GetStockObject(BLACK_PEN
));
37 hbr
= CreateSolidBrush(tip_bg
);
38 holdbr
= SelectObject(hdc
, hbr
);
40 GetClientRect(hWnd
, &cr
);
41 Rectangle(hdc
, cr
.left
, cr
.top
, cr
.right
, cr
.bottom
);
43 wtlen
= GetWindowTextLength(hWnd
);
44 wt
= (LPTSTR
)malloc((wtlen
+1)*sizeof(TCHAR
));
45 GetWindowText(hWnd
, wt
, wtlen
+1);
47 SetTextColor(hdc
, tip_text
);
48 SetBkColor(hdc
, tip_bg
);
50 TextOut(hdc
, cr
.left
+3, cr
.top
+3, wt
, wtlen
);
54 SelectObject(hdc
, holdbr
);
65 DeleteObject(tip_font
);
71 LPCTSTR str
= (LPCTSTR
)lParam
;
73 HDC hdc
= CreateCompatibleDC(NULL
);
75 SelectObject(hdc
, tip_font
);
76 GetTextExtentPoint32(hdc
, str
, _tcslen(str
), &sz
);
78 SetWindowPos(hWnd
, NULL
, 0, 0, sz
.cx
+6, sz
.cy
+6, SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOACTIVATE
);
79 InvalidateRect(hWnd
, NULL
, FALSE
);
86 return DefWindowProc(hWnd
, nMsg
, wParam
, lParam
);
92 void UpdateSizeTip(HWND src
, int cx
, int cy
)
96 if (!tip_enabled
) return;
101 /* First make sure the window class is registered */
105 wc
.style
= CS_HREDRAW
|CS_VREDRAW
;
106 wc
.lpfnWndProc
= SizeTipWndProc
;
109 wc
.hInstance
= putty_inst
;
112 wc
.hbrBackground
= NULL
;
113 wc
.lpszMenuName
= NULL
;
114 wc
.lpszClassName
= "SizeTipClass";
116 tip_class
= RegisterClass(&wc
);
120 /* Default values based on Windows Standard color scheme */
122 tip_font
= GetStockObject(SYSTEM_FONT
);
123 tip_bg
= RGB(255, 255, 225);
124 tip_text
= RGB(0, 0, 0);
127 /* Prepare other GDI objects and drawing info */
129 tip_bg
= GetSysColor(COLOR_INFOBK
);
130 tip_text
= GetSysColor(COLOR_INFOTEXT
);
132 memset(&nci
, 0, sizeof(NONCLIENTMETRICS
));
133 nci
.cbSize
= sizeof(NONCLIENTMETRICS
);
134 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(NONCLIENTMETRICS
), &nci
, 0);
135 tip_font
= CreateFontIndirect(&nci
.lfStatusFont
);
138 /* Generate the tip text */
140 sprintf(str
, "%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
;