4 Virtual Floppy Drive for Windows
6 COM shell extension class property sheet functions
8 Copyright (c) 2003-2005 Ken Kato
11 #define WIN32_LEAN_AND_MEAN
24 #include "vfdmsg_lib.h"
31 // property sheet property ID
33 #define VFD_PROPERTY_ID "VFD"
39 static BOOL CALLBACK
VfdPageDlgProc(
41 static INT_PTR CALLBACK
VfdPageDlgProc(
48 static UINT CALLBACK
VfdPageCallback(
51 LPPROPSHEETPAGE ppsp
);
53 static void OnPropInit(HWND hDlg
);
54 static void OnControl(HWND hDlg
);
55 static void UpdateImageInfo(HWND hDlg
, ULONG nDevice
);
58 // property sheet callback function
60 UINT CALLBACK
VfdPageCallback(
65 UNREFERENCED_PARAMETER(hWnd
);
73 ((LPCVFDSHEXT
)(ppsp
->lParam
))->Release();
81 // property page dialog procedure
84 BOOL CALLBACK
VfdPageDlgProc(
86 INT_PTR CALLBACK
VfdPageDlgProc(
99 SetWindowLong(hDlg
, DWL_USER
, lParam
);
101 SetWindowLongPtr(hDlg
, DWLP_USER
, lParam
);
105 lpcs
= (LPCVFDSHEXT
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
108 UpdateImageInfo(hDlg
, lpcs
->GetDevice());
114 psp
= (LPPROPSHEETPAGE
)GetWindowLong(hDlg
, DWL_USER
);
116 psp
= (LPPROPSHEETPAGE
)GetWindowLongPtr(hDlg
, DWLP_USER
);
123 lpcs
= (LPCVFDSHEXT
)psp
->lParam
;
131 if (lpcs
->DoVfdOpen(hDlg
) == ERROR_SUCCESS
) {
132 SendMessage((HWND
)lParam
,
133 BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
135 UpdateImageInfo(hDlg
, lpcs
->GetDevice());
139 if (lpcs
->DoVfdSave(hDlg
) == ERROR_SUCCESS
) {
140 SendMessage((HWND
)lParam
,
141 BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
143 UpdateImageInfo(hDlg
, lpcs
->GetDevice());
147 if (lpcs
->DoVfdClose(hDlg
) == ERROR_SUCCESS
) {
148 SendMessage((HWND
)lParam
,
149 BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
151 UpdateImageInfo(hDlg
, lpcs
->GetDevice());
154 case IDC_WRITE_PROTECTED
:
155 lpcs
->DoVfdProtect(hDlg
);
159 VfdGuiFormat(hDlg
, lpcs
->GetDevice());
169 ShowContextMenu(hDlg
, (HWND
)wParam
, lParam
);
174 LPHELPINFO info
= (LPHELPINFO
)lParam
;
176 if (info
->iContextType
== HELPINFO_WINDOW
) {
177 ShowHelpWindow(hDlg
, info
->iCtrlId
);
183 if (uMessage
== g_nNotifyMsg
) {
185 psp
= (LPPROPSHEETPAGE
)GetWindowLong(hDlg
, DWL_USER
);
187 psp
= (LPPROPSHEETPAGE
)GetWindowLongPtr(hDlg
, DWLP_USER
);
194 lpcs
= (LPCVFDSHEXT
)psp
->lParam
;
200 UpdateImageInfo(hDlg
, lpcs
->GetDevice());
209 // initialize the property page
214 // set up control text
216 SetDlgItemText(hDlg
, IDC_PROPERTY_TITLE
, VFD_PRODUCT_DESC
);
217 SetDlgItemText(hDlg
, IDC_COPYRIGHT_STR
, VFD_COPYRIGHT_STR
);
219 SetControlText(hDlg
, IDC_IMAGEFILE_LABEL
, MSG_IMAGEFILE_LABEL
);
220 SetControlText(hDlg
, IDC_IMAGEDESC_LABEL
, MSG_DESCRIPTION_LABEL
);
221 SetControlText(hDlg
, IDC_DISKTYPE_LABEL
, MSG_DISKTYPE_LABEL
);
222 SetControlText(hDlg
, IDC_MEDIATYPE_LABEL
, MSG_MEDIATYPE_LABEL
);
223 SetControlText(hDlg
, IDC_WRITE_PROTECTED
, MSG_MENU_PROTECT
);
224 SetControlText(hDlg
, IDC_OPEN
, MSG_OPEN_BUTTON
);
225 SetControlText(hDlg
, IDC_SAVE
, MSG_SAVE_BUTTON
);
226 SetControlText(hDlg
, IDC_CLOSE
, MSG_CLOSE_BUTTON
);
227 SetControlText(hDlg
, IDC_FORMAT
, MSG_FORMAT_BUTTON
);
228 SetControlText(hDlg
, IDC_CONTROL
, MSG_CONTROL_BUTTON
);
232 // Control Panel button is clicked
237 CHAR module_path
[MAX_PATH
];
238 CHAR full_path
[MAX_PATH
];
246 ret
= GetModuleFileName(
247 g_hDllModule
, module_path
, sizeof(module_path
));
249 if (ret
== 0 || ret
>= sizeof(module_path
)) {
250 file_name
= full_path
;
253 ret
= GetFullPathName(
254 module_path
, sizeof(full_path
), full_path
, &file_name
);
256 if (ret
== 0 || ret
>= sizeof(full_path
)) {
257 file_name
= full_path
;
261 strcpy(file_name
, "vfdwin.exe");
263 VFDTRACE(0, ("Starting %s\n", full_path
));
266 ret
= (DWORD
)ShellExecute(
267 hDlg
, NULL
, full_path
, NULL
, NULL
, SW_SHOW
);
269 ret
= (DWORD_PTR
)ShellExecute(
270 hDlg
, NULL
, full_path
, NULL
, NULL
, SW_SHOW
);
274 PropSheet_PressButton(GetParent(hDlg
), PSBTN_CANCEL
);
277 MessageBox(hDlg
, SystemMessage(ret
),
278 VFD_MSGBOX_TITLE
, MB_ICONSTOP
);
283 // Update image information on the property page
285 void UpdateImageInfo(
291 VFD_DISKTYPE disk_type
;
292 VFD_MEDIA media_type
;
293 VFD_FLAGS media_flags
;
294 VFD_FILETYPE file_type
;
299 hDevice
= VfdOpenDevice(nDevice
);
301 if (hDevice
== INVALID_HANDLE_VALUE
) {
303 SystemMessage(GetLastError()),
304 VFD_MSGBOX_TITLE
, MB_ICONSTOP
);
308 // get current image information
310 ret
= VfdGetImageInfo(
319 CloseHandle(hDevice
);
321 if (ret
!= ERROR_SUCCESS
) {
324 VFD_MSGBOX_TITLE
, MB_ICONSTOP
);
328 if (media_type
== VFD_MEDIA_NONE
) {
332 SetDlgItemText(hDlg
, IDC_IMAGEFILE
, NULL
);
333 SetDlgItemText(hDlg
, IDC_IMAGEFILE_DESC
, NULL
);
334 SetDlgItemText(hDlg
, IDC_DISKTYPE
, NULL
);
335 SetDlgItemText(hDlg
, IDC_MEDIATYPE
, NULL
);
337 EnableWindow(GetDlgItem(hDlg
, IDC_WRITE_PROTECTED
), FALSE
);
338 EnableWindow(GetDlgItem(hDlg
, IDC_OPEN
), TRUE
);
339 EnableWindow(GetDlgItem(hDlg
, IDC_SAVE
), FALSE
);
340 EnableWindow(GetDlgItem(hDlg
, IDC_CLOSE
), FALSE
);
341 EnableWindow(GetDlgItem(hDlg
, IDC_FORMAT
), FALSE
);
343 SendMessage(GetDlgItem(hDlg
, IDC_OPEN
),
344 BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
346 SetFocus(GetDlgItem(hDlg
, IDC_OPEN
));
351 // display image file name
354 attrib
= GetFileAttributes(buf
);
356 if (attrib
== INVALID_FILE_ATTRIBUTES
) {
361 if (disk_type
!= VFD_DISKTYPE_FILE
) {
362 strcpy(buf
, "<RAM>");
367 SetDlgItemText(hDlg
, IDC_IMAGEFILE
, buf
);
369 // display image description
371 VfdMakeFileDesc(buf
, sizeof(buf
),
372 file_type
, image_size
, attrib
);
374 SetDlgItemText(hDlg
, IDC_IMAGEFILE_DESC
, buf
);
378 if (disk_type
== VFD_DISKTYPE_FILE
) {
379 SetDlgItemText(hDlg
, IDC_DISKTYPE
, "FILE");
382 SetDlgItemText(hDlg
, IDC_DISKTYPE
, "RAM");
385 // display media type
387 SetDlgItemText(hDlg
, IDC_MEDIATYPE
,
388 VfdMediaTypeName(media_type
));
390 // set write protect check box
392 if (media_flags
& VFD_FLAG_WRITE_PROTECTED
) {
393 CheckDlgButton(hDlg
, IDC_WRITE_PROTECTED
, BST_CHECKED
);
396 CheckDlgButton(hDlg
, IDC_WRITE_PROTECTED
, BST_UNCHECKED
);
399 EnableWindow(GetDlgItem(hDlg
, IDC_WRITE_PROTECTED
), TRUE
);
400 EnableWindow(GetDlgItem(hDlg
, IDC_OPEN
), FALSE
);
401 EnableWindow(GetDlgItem(hDlg
, IDC_SAVE
), TRUE
);
402 EnableWindow(GetDlgItem(hDlg
, IDC_CLOSE
), TRUE
);
403 EnableWindow(GetDlgItem(hDlg
, IDC_FORMAT
), TRUE
);
405 SendMessage(GetDlgItem(hDlg
, IDC_CLOSE
),
406 BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
408 SetFocus(GetDlgItem(hDlg
, IDC_CLOSE
));
412 // CVfdShExt class members inherited from IShellPropSheetExt
416 STDMETHODIMP
CVfdShExt::AddPages(
417 LPFNADDPROPSHEETPAGE lpfnAddPage
,
421 HPROPSHEETPAGE hpage
;
423 if (!m_pDataObj
|| m_nDevice
== (ULONG
)-1) {
425 VFDTRACE(0, ("PropPage: Not a VFD drive\n"));
430 psp
.dwSize
= sizeof(psp
); // no extra data.
431 psp
.dwFlags
= PSP_USEREFPARENT
| PSP_USETITLE
| PSP_USECALLBACK
;
432 psp
.hInstance
= g_hDllModule
;
433 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_PROPDIALOG
);
435 psp
.pszTitle
= "VFD";
436 psp
.pfnDlgProc
= VfdPageDlgProc
;
437 psp
.pcRefParent
= &g_cDllRefCnt
;
438 psp
.pfnCallback
= VfdPageCallback
;
439 psp
.lParam
= (LPARAM
)this;
442 hpage
= CreatePropertySheetPage(&psp
);
445 if (!lpfnAddPage(hpage
, lParam
)) {
446 DestroyPropertySheetPage(hpage
);
454 STDMETHODIMP
CVfdShExt::ReplacePage(
456 LPFNADDPROPSHEETPAGE lpfnReplaceWith
,
459 UNREFERENCED_PARAMETER(uPageID
);
460 UNREFERENCED_PARAMETER(lpfnReplaceWith
);
461 UNREFERENCED_PARAMETER(lParam
);