-
Notifications
You must be signed in to change notification settings - Fork 711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace format floppy disk with standard format drive dialog #108
Changes from 3 commits
d9f6744
cb8767b
4f953ea
737a608
f2dd108
d793d5f
59c7b29
064ef57
dcc01e3
a52df7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,12 @@ | |
#include "winfile.h" | ||
#include "lfn.h" | ||
#include "wfcopy.h" | ||
#include <shlobj.h> | ||
|
||
#define LABEL_NTFS_MAX 32 | ||
#define LABEL_FAT_MAX 11 | ||
#define CCH_VERSION 40 | ||
#define CCH_DRIVE 3 | ||
|
||
VOID FormatDrive( IN PVOID ThreadParameter ); | ||
VOID CopyDiskette( IN PVOID ThreadParameter ); | ||
|
@@ -727,6 +729,90 @@ FormatDlgProc(register HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam) | |
return TRUE; | ||
} | ||
|
||
/*----------------------------------------------------------------------------*/ | ||
/* */ | ||
/* FormatSelectDlgProc() - DialogProc callback function for FORMATSELECTDLG */ | ||
/* */ | ||
/*----------------------------------------------------------------------------*/ | ||
|
||
INT_PTR | ||
FormatSelectDlgProc(register HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam) | ||
{ | ||
HWND hwndSelectDrive; | ||
INT driveIndex; | ||
INT comboxIndex; | ||
DRIVE drive; | ||
DWORD dwFormatResult; | ||
TCHAR szDrive[CCH_DRIVE] = { 0 }; | ||
|
||
switch (wMsg) | ||
{ | ||
case WM_INITDIALOG: | ||
{ | ||
// Build the list of drives that can be selected for formatting. | ||
// Do not include remote drives or CD/DVD drives. | ||
szDrive[1] = ':'; | ||
hwndSelectDrive = GetDlgItem(hDlg, IDD_SELECTDRIVE); | ||
if (hwndSelectDrive) | ||
{ | ||
for (driveIndex = 0; driveIndex < cDrives; driveIndex++) | ||
{ | ||
drive = rgiDrive[driveIndex]; | ||
if (!IsRemoteDrive(drive) && !IsCDRomDrive(drive)) | ||
{ | ||
// Set the drive letter as the string and the drive index as the data. | ||
DRIVESET(szDrive, drive); | ||
comboxIndex = SendMessage(hwndSelectDrive, CB_ADDSTRING, 0, (LPARAM)szDrive); | ||
SendMessage(hwndSelectDrive, CB_SETITEMDATA, comboxIndex, (LPARAM)drive); | ||
} | ||
} | ||
|
||
SendMessage(hwndSelectDrive, CB_SETCURSEL, 0, 0); | ||
} | ||
|
||
return TRUE; | ||
} | ||
case WM_COMMAND: | ||
switch (GET_WM_COMMAND_ID(wParam, lParam)) | ||
{ | ||
case IDOK: | ||
{ | ||
// Hide this dialog window while the SHFormatDrive dialog is displayed. | ||
// SHFormatDrive needs a parent window, and this dialog will serve as | ||
// that parent, even if it is hidden. | ||
ShowWindow(hDlg, SW_HIDE); | ||
|
||
// Retrieve the selected drive index and call SHFormatDrive with it. | ||
comboxIndex = (INT)SendDlgItemMessage(hDlg, IDD_SELECTDRIVE, CB_GETCURSEL, 0, 0); | ||
drive = (DRIVE)SendDlgItemMessage(hDlg, IDD_SELECTDRIVE, CB_GETITEMDATA, comboxIndex, 0); | ||
dwFormatResult = SHFormatDrive(hDlg, drive, SHFMT_ID_DEFAULT, 0); | ||
|
||
// If the format results in an error, show FORMATSELECTDLG again so | ||
// the user can select a different drive if needed, or cancel. | ||
// Otherwise, if the format was successful, just close FORMATSELECTDLG. | ||
if (dwFormatResult == SHFMT_ERROR || dwFormatResult == SHFMT_CANCEL || dwFormatResult == SHFMT_NOFORMAT) | ||
{ | ||
// SHFormatDrive sometimes sets the parent window title when it encounters an error. | ||
// We don't want this; set the title back before we show the dialog. | ||
// Future improvement: title text and initial title should load from the same resource string. | ||
SetWindowText(hDlg, TEXT("Format Drive")); | ||
ShowWindow(hDlg, SW_SHOW); | ||
} | ||
else | ||
{ | ||
EndDialog(hDlg, IDOK); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the documentation (referenced at https://stackoverflow.com/questions/13788680/enddialog-vs-destroywindow), this needs to be DestroyWindow(). Also see the function DestroyCancelWindow() in wfdlgs3.c. |
||
} | ||
|
||
return TRUE; | ||
} | ||
case IDCANCEL: | ||
EndDialog(hDlg, IDCANCEL); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
return TRUE; | ||
} | ||
} | ||
return FALSE; | ||
} | ||
|
||
/*--------------------------------------------------------------------------*/ | ||
/* */ | ||
/* AboutDlgProc() - DialogProc callback function for ABOUTDLG */ | ||
|
@@ -1674,22 +1760,19 @@ LockFormatDisk(DRIVE drive1, DRIVE drive2, | |
DWORD dwMessage, DWORD dwCommand, BOOL bLock) | ||
{ | ||
HMENU hMenu; | ||
static DWORD adwCommands[] = { | ||
IDM_DISKCOPY, | ||
IDM_FORMAT, | ||
0 | ||
}; | ||
|
||
INT i=0; | ||
|
||
// Gray out disk:{format,copy} | ||
// Gray out menu item dwCommand | ||
hMenu = GetMenu(hwndFrame); | ||
|
||
while (adwCommands[i]) { | ||
if (dwCommand != adwCommands[i]) | ||
EnableMenuItem( hMenu, dwCommand , | ||
bLock ? MF_BYCOMMAND | MF_GRAYED : MF_BYCOMMAND | MF_ENABLED ); | ||
i++; | ||
// Special case for IDM_FORMAT, as it no longer invokes FormatDiskette, | ||
// it can be safely left enabled even when copying diskettes. | ||
// This change is made here rather than removing the calls to | ||
// LockFormatDisk with IDM_FORMAT since LockFormatDisk also | ||
// changes the state of aDriveInfo. | ||
if (dwCommand != IDM_FORMAT) | ||
{ | ||
EnableMenuItem(hMenu, dwCommand, | ||
bLock ? MF_BYCOMMAND | MF_GRAYED : MF_BYCOMMAND | MF_ENABLED); | ||
} | ||
|
||
// | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order for the dialog to be positioned like the others, we need to pass hwndFrame as the third parameter to DialogBox.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@craigwi Good point, and I actually originally wrote the code that way. I later changed the parameter to NULL to avoid making this dialog modal. Really, I was more concerned about the dialog created by SHFormatDrive being modal, because formatting can be a long-running operation. SHFormatDrive requires a parent HWND (says MSDN), so I used the first dialog (the one you commented on) as its parent. Therefore, to prevent a situation where both dialogs were modal, I used NULL in the line you mentioned.
I see a few options:
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest making the FORMATSELECTDLG modeless by calling CreateDialog instead of DialogBox. You can also save the hwnd returned to activate it so there is only one. I tried this out and the basic cases seem to work.
There are several other examples of modeless dialogs (e.g., CancelDlg) that you can use as a pattern.
I would like to see the FileCopy dialog becomes modelsss in this way. It has always annoyed me that it was modal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion; thanks! I had forgotten about CreateDialog. It has been a while since I've written C/Win32 code! I'll look into making that change.