4 Virtual Floppy Drive for Windows
6 tooltip information GUI utility functions
8 Copyright (c) 2003-2005 Ken Kato
12 #pragma message(__FILE__": Compiled as C++ for testing purpose.")
15 #define WIN32_LEAN_AND_MEAN
24 #include "vfdmsg_lib.h"
28 // tooltip window class name
30 #define VFD_INFOTIP_WNDCLASS "VfdInfoTip"
33 // the window procedure
35 static LRESULT CALLBACK
ToolTipProc(
44 SetWindowLongPtr(hWnd
, GWLP_USERDATA
,
45 (LONG_PTR
)((LPCREATESTRUCT
)lParam
)->lpCreateParams
);
51 HDC hDC
= BeginPaint(hWnd
, &paint
);
59 SelectObject(hDC
, (HFONT
)GetWindowLongPtr(hWnd
, GWLP_USERDATA
));
61 SetTextColor(hDC
, GetSysColor(COLOR_INFOTEXT
));
62 SetBkMode(hDC
, TRANSPARENT
);
64 len
= GetWindowText(hWnd
, text
, sizeof(text
));
68 rc
.right
= paint
.rcPaint
.right
;
69 rc
.bottom
= paint
.rcPaint
.bottom
;
71 DrawText(hDC
, text
, len
, &rc
, DT_LEFT
| DT_TOP
);
73 EndPaint(hWnd
, &paint
);
79 if (!(GetWindowLong(hWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
)) {
80 // Stick tool tip - Closed on kill focus
86 if (GetWindowLong(hWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) {
87 // Non-stick tool tip - Closed when cursor leaves
88 TRACKMOUSEEVENT track
;
90 track
.cbSize
= sizeof(track
);
91 track
.dwFlags
= TME_LEAVE
;
92 track
.hwndTrack
= hWnd
;
93 track
.dwHoverTime
= 0;
95 TrackMouseEvent(&track
);
100 // Non-stick tool tip - Closed when cursor leaves
107 // Both stick and non-stick tool tip
108 // Closed when clicked
115 // Both stick and non-stick tool tip
116 // Closed when clicked
117 if (GetCapture() == hWnd
) {
124 DeleteObject((HFONT
)GetWindowLongPtr(hWnd
, GWLP_USERDATA
));
128 return DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
132 // Create and show tooltip window
134 void WINAPI
VfdToolTip(
155 // Register Window Class
158 wc
.lpfnWndProc
= ToolTipProc
;
159 wc
.hInstance
= g_hDllModule
;
160 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
161 wc
.hbrBackground
= (HBRUSH
)(COLOR_INFOBK
+ 1);
162 wc
.lpszClassName
= VFD_INFOTIP_WNDCLASS
;
167 // Create Tool Tip Font (== Icon title font)
170 SystemParametersInfo(
171 SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
173 font
= CreateFontIndirect(&lf
);
176 // Calculate Tool Tip Window size
181 SelectObject(dc
, font
);
185 GetTextExtentPoint32(dc
, sText
, len
, &sz
);
192 DrawText(dc
, sText
, len
, &rc
, DT_CALCRECT
| DT_LEFT
| DT_TOP
);
194 ReleaseDC(hParent
, dc
);
196 sz
.cx
= rc
.right
- rc
.left
+ 16;
197 sz
.cy
= rc
.bottom
- rc
.top
+ 16;
200 // Decide the window position
202 if (pos_x
== -1 || pos_y
== -1) {
204 // Use current cursor position
210 pos_x
= pt
.x
- (sz
.cx
/ 2);
211 pos_y
= pt
.y
- (sz
.cy
/ 2);
214 pos_x
= pos_x
- (sz
.cx
/ 2);
218 // make sure the tip window fits in visible area
220 scr_x
= GetSystemMetrics(SM_CXSCREEN
);
221 scr_y
= GetSystemMetrics(SM_CYSCREEN
);
226 if (pos_x
+ sz
.cx
> scr_x
) {
227 pos_x
= scr_x
- sz
.cx
;
232 if (pos_y
+ sz
.cy
> scr_y
) {
233 pos_y
= scr_y
- sz
.cy
;
237 // Create the tool tip window
240 hWnd
= CreateWindowEx(
244 stick
? 0 : WS_EX_TOPMOST
,
245 VFD_INFOTIP_WNDCLASS
,
247 WS_BORDER
| WS_POPUP
| WS_VISIBLE
,
256 // Give focus if it is not a stick tool-tip
264 // Show an image information tooltip
266 void WINAPI
VfdImageTip(
271 PSTR info_str
= NULL
;
272 PSTR type_str
= NULL
;
273 PSTR prot_str
= NULL
;
274 PCSTR media_str
= NULL
;
277 VFD_DISKTYPE disk_type
;
278 VFD_MEDIA media_type
;
279 VFD_FLAGS media_flags
;
280 VFD_FILETYPE file_type
;
285 hDevice
= VfdOpenDevice(nDevice
);
287 if (hDevice
== INVALID_HANDLE_VALUE
) {
289 SystemMessage(GetLastError()), -1, -1, FALSE
);
293 ret
= VfdGetImageInfo(
302 CloseHandle(hDevice
);
304 if (ret
!= ERROR_SUCCESS
) {
305 VfdToolTip(hParent
, SystemMessage(ret
), -1, -1, FALSE
);
310 file_attr
= GetFileAttributes(path
);
313 if (disk_type
!= VFD_DISKTYPE_FILE
) {
314 strcpy(path
, "<RAM>");
319 VfdMakeFileDesc(desc
, sizeof(desc
),
320 file_type
, image_size
, file_attr
);
322 if (disk_type
== VFD_DISKTYPE_FILE
) {
329 media_str
= VfdMediaTypeName(media_type
);
331 if (media_flags
& VFD_FLAG_WRITE_PROTECTED
) {
332 prot_str
= ModuleMessage(MSG_WRITE_PROTECTED
);
335 prot_str
= ModuleMessage(MSG_WRITE_ALLOWED
);
338 info_str
= ModuleMessage(
342 type_str
? type_str
: "",
343 media_str
? media_str
: "",
344 prot_str
? prot_str
: "");
347 VfdToolTip(hParent
, info_str
, -1, -1, FALSE
);