Microsoft KB Archive/173688: Difference between revisions
m (1 revision imported: importing part 2) |
m (Text replacement - "&" to "&") |
||
(2 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
---- | |||
The information in this article applies to:<br /> | The information in this article applies to:<br /> | ||
Line 15: | Line 15: | ||
---- | |||
<br /> | <br /> | ||
Line 34: | Line 34: | ||
#if defined (__cplusplus) | #if defined (__cplusplus) | ||
extern | extern "C" { | ||
#endif | #endif | ||
Line 45: | Line 45: | ||
hwnd = The window handle of the window that will own the | hwnd = The window handle of the window that will own the | ||
dialog. NOTE that hwnd == NULL does not cause this | dialog. NOTE that hwnd == NULL does not cause this | ||
dialog to come up as a | dialog to come up as a "top level application" | ||
window. This parameter should always be non-null, | window. This parameter should always be non-null, | ||
this dialog box is only designed to be the child of | this dialog box is only designed to be the child of | ||
Line 60: | Line 60: | ||
SHFMT_OPT_SYSONLY | SHFMT_OPT_SYSONLY | ||
SHFMT_OPT_FULL specifies that the | SHFMT_OPT_FULL specifies that the "Quick Format" | ||
setting should be cleared by default. If the user | setting should be cleared by default. If the user | ||
leaves the | leaves the "Quick Format" setting cleared, then a | ||
full format will be applied (this is useful for | full format will be applied (this is useful for | ||
users that detect | users that detect "unformatted" disks and want | ||
to bring up the format dialog box). | to bring up the format dialog box). | ||
If options is set to zero (0), then the | If options is set to zero (0), then the "Quick Format" | ||
setting is set by default. In addition, if the user leaves | setting is set by default. In addition, if the user leaves | ||
it set, a quick format is performed. Under Windows NT 4.0, | it set, a quick format is performed. Under Windows NT 4.0, | ||
this flag is ignored and the | this flag is ignored and the "Quick Format" box is always | ||
checked when the dialog box first appears. The user can | checked when the dialog box first appears. The user can | ||
still change it. This is by design. | still change it. This is by design. | ||
Line 89: | Line 89: | ||
last successful format. The LOWORD of this value can be | last successful format. The LOWORD of this value can be | ||
passed on subsequent calls as the fmtID parameter to | passed on subsequent calls as the fmtID parameter to | ||
"format the same type you did last time". | |||
*****************************************************************/ | *****************************************************************/ | ||
Line 98: | Line 98: | ||
// | // | ||
// Special value of fmtID which means | // Special value of fmtID which means "use the defaultformat" | ||
// | // | ||
Line 123: | Line 123: | ||
#endif | #endif | ||
#endif </pre> | #endif </pre> | ||
Here is an example call to SHFormatDrive that will format a diskette in drive | Here is an example call to SHFormatDrive that will format a diskette in drive "A:". | ||
<pre class="CODESAMP"> SHFormatDrive (hMainWnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0); </pre> | <pre class="CODESAMP"> SHFormatDrive (hMainWnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0); </pre> | ||
Line 129: | Line 129: | ||
<pre class="CODESAMP"> UINT OldMode = SetErrorMode(0); // Get the current Error Mode settings. | <pre class="CODESAMP"> UINT OldMode = SetErrorMode(0); // Get the current Error Mode settings. | ||
SetErrorMode(OldMode & | SetErrorMode(OldMode & !SEM_FAILCRITICALERRORS); // Force O/S to handle | ||
//critical errors. | //critical errors. | ||
// Call SHFormatDrive here. | // Call SHFormatDrive here. |
Latest revision as of 12:29, 21 July 2020
HOWTO: Call SHFormatDrive in Windows 95 and Windows NT |
Q173688
The information in this article applies to:
- Microsoft Win32 Application Programming Interface (API)
SUMMARY
Although most Win32 applications do not need to be able to format disks, some do. Windows 95 and Windows NT provide an API function called SHFormatDrive, which presents the same dialog box as the Windows 95 and Windows NT shells, formats the specified diskette. This article describes how to call SHFormatDrive.
MORE INFORMATION
Currently, SHFormatDrive is not in the Platform SDK documentation or SHELLAPI.H. However, it is in SHELL32.LIB. Until the documentation and SHELLAPI.H are updated, use the following declarations and function description:
#if !defined(SHFMT_OPT_FULL) #if defined (__cplusplus) extern "C" { #endif /***************************************************************** The SHFormatDrive API provides access to the Shell's format dialog box. This allows applications that want to format disks to bring up the same dialog box that the Shell uses for disk formatting. PARAMETERS hwnd = The window handle of the window that will own the dialog. NOTE that hwnd == NULL does not cause this dialog to come up as a "top level application" window. This parameter should always be non-null, this dialog box is only designed to be the child of another window, not a stand-alone application. drive = The 0 based (A: == 0) drive number of the drive to format. fmtID = Currently must be set to SHFMT_ID_DEFAULT. options = There are currently only two option bits defined. SHFMT_OPT_FULL SHFMT_OPT_SYSONLY SHFMT_OPT_FULL specifies that the "Quick Format" setting should be cleared by default. If the user leaves the "Quick Format" setting cleared, then a full format will be applied (this is useful for users that detect "unformatted" disks and want to bring up the format dialog box). If options is set to zero (0), then the "Quick Format" setting is set by default. In addition, if the user leaves it set, a quick format is performed. Under Windows NT 4.0, this flag is ignored and the "Quick Format" box is always checked when the dialog box first appears. The user can still change it. This is by design. The SHFMT_OPT_SYSONLY initializes the dialog to default to just sys the disk. All other bits are reserved for future expansion and must be 0. Please note that this is a bit field and not a value, treat it accordingly. RETURN The return is either one of the SHFMT_* values, or if the returned DWORD value is not == to one of these values, then the return is the physical format ID of the last successful format. The LOWORD of this value can be passed on subsequent calls as the fmtID parameter to "format the same type you did last time". *****************************************************************/ DWORD WINAPI SHFormatDrive(HWND hwnd, UINT drive, UINT fmtID, UINT options); // // Special value of fmtID which means "use the defaultformat" // #define SHFMT_ID_DEFAULT 0xFFFF // // Option bits for options parameter // #define SHFMT_OPT_FULL 0x0001 #define SHFMT_OPT_SYSONLY 0x0002 // // Special return values. PLEASE NOTE that these are DWORD values. // #define SHFMT_ERROR 0xFFFFFFFFL // Error on last format, // drive may be formatable #define SHFMT_CANCEL 0xFFFFFFFEL // Last format wascanceled #define SHFMT_NOFORMAT 0xFFFFFFFDL // Drive is not formatable #if defined (__cplusplus) } #endif #endif
Here is an example call to SHFormatDrive that will format a diskette in drive "A:".
SHFormatDrive (hMainWnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
Normally, if a diskette is not in the drive when SHFormatDrive is called, the system displays a critical error dialog box that asks the user to Abort, Retry, or Ignore. You can prevent the system from displaying this dialog box by calling the SetErrorMode API with SEM_FAILCRITICALERRORS. If the application has already set this flag, the critical error dialog box will not appear. If you want this dialog box to appear, use the following code:
UINT OldMode = SetErrorMode(0); // Get the current Error Mode settings. SetErrorMode(OldMode & !SEM_FAILCRITICALERRORS); // Force O/S to handle //critical errors. // Call SHFormatDrive here. SetErrorMode(OldMode); // Put it back the way it was.
Additional query words: format disk diskette initialize create critical error
Keywords : kbAPI kbFileIO kbKernBase kbLib kbOSWinNT400 kbOSWin2000 kbGrpDSUser kbOSWin95 kbOSWin98 kbshell kbGrpDSShell
Issue type : kbhowto
Technology : kbAudDeveloper kbWin32sSearch kbWin32API
Last Reviewed: July 9, 2000 |