94407ae52a0cba7309c2c9a74562c401dd4853a5
9 static ATOM tip_class
= 0;
11 static HFONT tip_font
;
12 static COLORREF tip_bg
;
13 static COLORREF tip_text
;
15 static LRESULT CALLBACK
SizeTipWndProc(HWND hWnd
, UINT nMsg
,
16 WPARAM wParam
, LPARAM lParam
)
33 hdc
= BeginPaint(hWnd
, &ps
);
35 SelectObject(hdc
, tip_font
);
36 SelectObject(hdc
, GetStockObject(BLACK_PEN
));
38 hbr
= CreateSolidBrush(tip_bg
);
39 holdbr
= SelectObject(hdc
, hbr
);
41 GetClientRect(hWnd
, &cr
);
42 Rectangle(hdc
, cr
.left
, cr
.top
, cr
.right
, cr
.bottom
);
44 wtlen
= GetWindowTextLength(hWnd
);
45 wt
= (LPTSTR
)malloc((wtlen
+1)*sizeof(TCHAR
));
46 GetWindowText(hWnd
, wt
, wtlen
+1);
48 SetTextColor(hdc
, tip_text
);
49 SetBkColor(hdc
, tip_bg
);
51 TextOut(hdc
, cr
.left
+3, cr
.top
+3, wt
, wtlen
);
55 SelectObject(hdc
, holdbr
);
66 DeleteObject(tip_font
);
72 LPCTSTR str
= (LPCTSTR
)lParam
;
74 HDC hdc
= CreateCompatibleDC(NULL
);
76 SelectObject(hdc
, tip_font
);
77 GetTextExtentPoint32(hdc
, str
, _tcslen(str
), &sz
);
79 SetWindowPos(hWnd
, NULL
, 0, 0, sz
.cx
+6, sz
.cy
+6, SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOACTIVATE
);
80 InvalidateRect(hWnd
, NULL
, FALSE
);
87 return DefWindowProc(hWnd
, nMsg
, wParam
, lParam
);
90 static HWND tip_wnd
= NULL
;
91 static int tip_enabled
= 0;
93 void UpdateSizeTip(HWND src
, int cx
, int cy
)
97 if (!tip_enabled
) return;
100 NONCLIENTMETRICS nci
;
102 /* First make sure the window class is registered */
106 wc
.style
= CS_HREDRAW
|CS_VREDRAW
;
107 wc
.lpfnWndProc
= SizeTipWndProc
;
110 wc
.hInstance
= putty_inst
;
113 wc
.hbrBackground
= NULL
;
114 wc
.lpszMenuName
= NULL
;
115 wc
.lpszClassName
= "SizeTipClass";
117 tip_class
= RegisterClass(&wc
);
121 /* Default values based on Windows Standard color scheme */
123 tip_font
= GetStockObject(SYSTEM_FONT
);
124 tip_bg
= RGB(255, 255, 225);
125 tip_text
= RGB(0, 0, 0);
128 /* Prepare other GDI objects and drawing info */
130 tip_bg
= GetSysColor(COLOR_INFOBK
);
131 tip_text
= GetSysColor(COLOR_INFOTEXT
);
133 memset(&nci
, 0, sizeof(NONCLIENTMETRICS
));
134 nci
.cbSize
= sizeof(NONCLIENTMETRICS
);
135 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(NONCLIENTMETRICS
), &nci
, 0);
136 tip_font
= CreateFontIndirect(&nci
.lfStatusFont
);
139 /* Generate the tip text */
141 sprintf(str
, "%dx%d", cx
, cy
);
149 /* calculate the tip's size */
151 hdc
= CreateCompatibleDC(NULL
);
152 GetTextExtentPoint32(hdc
, str
, _tcslen(str
), &sz
);
155 GetWindowRect(src
, &wr
);
163 /* Create the tip window */
165 tip_wnd
= CreateWindowEx(WS_EX_TOOLWINDOW
|WS_EX_TOPMOST
, MAKEINTRESOURCE(tip_class
), str
, WS_POPUP
,
166 ix
, iy
, sz
.cx
, sz
.cy
,
167 NULL
, NULL
, putty_inst
, NULL
);
169 ShowWindow(tip_wnd
, SW_SHOWNOACTIVATE
);
173 /* Tip already exists, just set the text */
175 SetWindowText(tip_wnd
, str
);
179 void EnableSizeTip(int bEnable
)
181 if (tip_wnd
&& !bEnable
) {
182 DestroyWindow(tip_wnd
);
186 tip_enabled
= bEnable
;