17 static ATOM tip_class
= 0;
19 static HFONT tip_font
;
20 static COLORREF tip_bg
;
21 static COLORREF tip_text
;
23 static LRESULT CALLBACK
SizeTipWndProc(HWND hWnd
, UINT nMsg
,
24 WPARAM wParam
, LPARAM lParam
)
41 hdc
= BeginPaint(hWnd
, &ps
);
43 SelectObject(hdc
, tip_font
);
44 SelectObject(hdc
, GetStockObject(BLACK_PEN
));
46 hbr
= CreateSolidBrush(tip_bg
);
47 holdbr
= SelectObject(hdc
, hbr
);
49 GetClientRect(hWnd
, &cr
);
50 Rectangle(hdc
, cr
.left
, cr
.top
, cr
.right
, cr
.bottom
);
52 wtlen
= GetWindowTextLength(hWnd
);
53 wt
= (LPTSTR
)malloc((wtlen
+1)*sizeof(TCHAR
));
54 GetWindowText(hWnd
, wt
, wtlen
+1);
56 SetTextColor(hdc
, tip_text
);
57 SetBkColor(hdc
, tip_bg
);
59 TextOut(hdc
, cr
.left
+3, cr
.top
+3, wt
, wtlen
);
63 SelectObject(hdc
, holdbr
);
74 DeleteObject(tip_font
);
80 LPCTSTR str
= (LPCTSTR
)lParam
;
82 HDC hdc
= CreateCompatibleDC(NULL
);
84 SelectObject(hdc
, tip_font
);
85 GetTextExtentPoint32(hdc
, str
, _tcslen(str
), &sz
);
87 SetWindowPos(hWnd
, NULL
, 0, 0, sz
.cx
+6, sz
.cy
+6, SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOACTIVATE
);
88 InvalidateRect(hWnd
, NULL
, FALSE
);
95 return DefWindowProc(hWnd
, nMsg
, wParam
, lParam
);
98 static HWND tip_wnd
= NULL
;
99 static int tip_enabled
= 0;
101 void UpdateSizeTip(HWND src
, int cx
, int cy
)
105 if (!tip_enabled
) return;
108 NONCLIENTMETRICS nci
;
110 /* First make sure the window class is registered */
114 wc
.style
= CS_HREDRAW
|CS_VREDRAW
;
115 wc
.lpfnWndProc
= SizeTipWndProc
;
118 wc
.hInstance
= hinst
;
121 wc
.hbrBackground
= NULL
;
122 wc
.lpszMenuName
= NULL
;
123 wc
.lpszClassName
= "SizeTipClass";
125 tip_class
= RegisterClass(&wc
);
129 /* Default values based on Windows Standard color scheme */
131 tip_font
= GetStockObject(SYSTEM_FONT
);
132 tip_bg
= RGB(255, 255, 225);
133 tip_text
= RGB(0, 0, 0);
136 /* Prepare other GDI objects and drawing info */
138 tip_bg
= GetSysColor(COLOR_INFOBK
);
139 tip_text
= GetSysColor(COLOR_INFOTEXT
);
141 memset(&nci
, 0, sizeof(NONCLIENTMETRICS
));
142 nci
.cbSize
= sizeof(NONCLIENTMETRICS
);
143 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(NONCLIENTMETRICS
), &nci
, 0);
144 tip_font
= CreateFontIndirect(&nci
.lfStatusFont
);
147 /* Generate the tip text */
149 sprintf(str
, "%dx%d", cx
, cy
);
157 /* calculate the tip's size */
159 hdc
= CreateCompatibleDC(NULL
);
160 GetTextExtentPoint32(hdc
, str
, _tcslen(str
), &sz
);
163 GetWindowRect(src
, &wr
);
171 /* Create the tip window */
173 tip_wnd
= CreateWindowEx(WS_EX_TOOLWINDOW
|WS_EX_TOPMOST
, MAKEINTRESOURCE(tip_class
), str
, WS_POPUP
,
174 ix
, iy
, sz
.cx
, sz
.cy
,
175 NULL
, NULL
, hinst
, NULL
);
177 ShowWindow(tip_wnd
, SW_SHOWNOACTIVATE
);
181 /* Tip already exists, just set the text */
183 SetWindowText(tip_wnd
, str
);
187 void EnableSizeTip(int bEnable
)
189 if (tip_wnd
&& !bEnable
) {
190 DestroyWindow(tip_wnd
);
194 tip_enabled
= bEnable
;