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
) smalloc((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,
81 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
);
82 InvalidateRect(hWnd
, NULL
, FALSE
);
89 return DefWindowProc(hWnd
, nMsg
, wParam
, lParam
);
92 static HWND tip_wnd
= NULL
;
93 static int tip_enabled
= 0;
95 void UpdateSizeTip(HWND src
, int cx
, int cy
)
103 NONCLIENTMETRICS nci
;
105 /* First make sure the window class is registered */
109 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
110 wc
.lpfnWndProc
= SizeTipWndProc
;
113 wc
.hInstance
= hinst
;
116 wc
.hbrBackground
= NULL
;
117 wc
.lpszMenuName
= NULL
;
118 wc
.lpszClassName
= "SizeTipClass";
120 tip_class
= RegisterClass(&wc
);
123 /* Default values based on Windows Standard color scheme */
125 tip_font
= GetStockObject(SYSTEM_FONT
);
126 tip_bg
= RGB(255, 255, 225);
127 tip_text
= RGB(0, 0, 0);
130 /* Prepare other GDI objects and drawing info */
132 tip_bg
= GetSysColor(COLOR_INFOBK
);
133 tip_text
= GetSysColor(COLOR_INFOTEXT
);
135 memset(&nci
, 0, sizeof(NONCLIENTMETRICS
));
136 nci
.cbSize
= sizeof(NONCLIENTMETRICS
);
137 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
,
138 sizeof(NONCLIENTMETRICS
), &nci
, 0);
139 tip_font
= CreateFontIndirect(&nci
.lfStatusFont
);
142 /* Generate the tip text */
144 sprintf(str
, "%dx%d", cx
, cy
);
152 /* calculate the tip's size */
154 hdc
= CreateCompatibleDC(NULL
);
155 GetTextExtentPoint32(hdc
, str
, _tcslen(str
), &sz
);
158 GetWindowRect(src
, &wr
);
168 /* Create the tip window */
171 CreateWindowEx(WS_EX_TOOLWINDOW
| WS_EX_TOPMOST
,
172 MAKEINTRESOURCE(tip_class
), str
, WS_POPUP
, ix
,
173 iy
, sz
.cx
, sz
.cy
, NULL
, NULL
, hinst
, NULL
);
175 ShowWindow(tip_wnd
, SW_SHOWNOACTIVATE
);
179 /* Tip already exists, just set the text */
181 SetWindowText(tip_wnd
, str
);
185 void EnableSizeTip(int bEnable
)
187 if (tip_wnd
&& !bEnable
) {
188 DestroyWindow(tip_wnd
);
192 tip_enabled
= bEnable
;