10 static ATOM tip_class
= 0;
12 static HFONT tip_font
;
13 static COLORREF tip_bg
;
14 static COLORREF tip_text
;
16 static LRESULT CALLBACK
SizeTipWndProc(HWND hWnd
, UINT nMsg
,
17 WPARAM wParam
, LPARAM lParam
)
34 hdc
= BeginPaint(hWnd
, &ps
);
36 SelectObject(hdc
, tip_font
);
37 SelectObject(hdc
, GetStockObject(BLACK_PEN
));
39 hbr
= CreateSolidBrush(tip_bg
);
40 holdbr
= SelectObject(hdc
, hbr
);
42 GetClientRect(hWnd
, &cr
);
43 Rectangle(hdc
, cr
.left
, cr
.top
, cr
.right
, cr
.bottom
);
45 wtlen
= GetWindowTextLength(hWnd
);
46 wt
= (LPTSTR
)malloc((wtlen
+1)*sizeof(TCHAR
));
47 GetWindowText(hWnd
, wt
, wtlen
+1);
49 SetTextColor(hdc
, tip_text
);
50 SetBkColor(hdc
, tip_bg
);
52 TextOut(hdc
, cr
.left
+3, cr
.top
+3, wt
, wtlen
);
56 SelectObject(hdc
, holdbr
);
67 DeleteObject(tip_font
);
73 LPCTSTR str
= (LPCTSTR
)lParam
;
75 HDC hdc
= CreateCompatibleDC(NULL
);
77 SelectObject(hdc
, tip_font
);
78 GetTextExtentPoint32(hdc
, str
, _tcslen(str
), &sz
);
80 SetWindowPos(hWnd
, NULL
, 0, 0, sz
.cx
+6, sz
.cy
+6, SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOACTIVATE
);
81 InvalidateRect(hWnd
, NULL
, FALSE
);
88 return DefWindowProc(hWnd
, nMsg
, wParam
, lParam
);
91 static HWND tip_wnd
= NULL
;
92 static int tip_enabled
= 0;
94 void UpdateSizeTip(HWND src
, int cx
, int cy
)
98 if (!tip_enabled
) return;
101 NONCLIENTMETRICS nci
;
103 /* First make sure the window class is registered */
107 wc
.style
= CS_HREDRAW
|CS_VREDRAW
;
108 wc
.lpfnWndProc
= SizeTipWndProc
;
111 wc
.hInstance
= hinst
;
114 wc
.hbrBackground
= NULL
;
115 wc
.lpszMenuName
= NULL
;
116 wc
.lpszClassName
= "SizeTipClass";
118 tip_class
= RegisterClass(&wc
);
122 /* Default values based on Windows Standard color scheme */
124 tip_font
= GetStockObject(SYSTEM_FONT
);
125 tip_bg
= RGB(255, 255, 225);
126 tip_text
= RGB(0, 0, 0);
129 /* Prepare other GDI objects and drawing info */
131 tip_bg
= GetSysColor(COLOR_INFOBK
);
132 tip_text
= GetSysColor(COLOR_INFOTEXT
);
134 memset(&nci
, 0, sizeof(NONCLIENTMETRICS
));
135 nci
.cbSize
= sizeof(NONCLIENTMETRICS
);
136 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(NONCLIENTMETRICS
), &nci
, 0);
137 tip_font
= CreateFontIndirect(&nci
.lfStatusFont
);
140 /* Generate the tip text */
142 sprintf(str
, "%dx%d", cx
, cy
);
150 /* calculate the tip's size */
152 hdc
= CreateCompatibleDC(NULL
);
153 GetTextExtentPoint32(hdc
, str
, _tcslen(str
), &sz
);
156 GetWindowRect(src
, &wr
);
164 /* Create the tip window */
166 tip_wnd
= CreateWindowEx(WS_EX_TOOLWINDOW
|WS_EX_TOPMOST
, MAKEINTRESOURCE(tip_class
), str
, WS_POPUP
,
167 ix
, iy
, sz
.cx
, sz
.cy
,
168 NULL
, NULL
, hinst
, NULL
);
170 ShowWindow(tip_wnd
, SW_SHOWNOACTIVATE
);
174 /* Tip already exists, just set the text */
176 SetWindowText(tip_wnd
, str
);
180 void EnableSizeTip(int bEnable
)
182 if (tip_wnd
&& !bEnable
) {
183 DestroyWindow(tip_wnd
);
187 tip_enabled
= bEnable
;