SHFormatDrive function (shlobj_core.h)

[SHFormatDrive is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions.]

Opens the Shell's Format dialog box.


DWORD SHFormatDrive(
  [in] HWND hwnd,
       UINT drive,
       UINT fmtID,
       UINT options


[in] hwnd

Type: HWND

The handle of the parent window of the dialog box. The Format dialog box must have a parent window; therefore, this parameter cannot be NULL.


Type: UINT

The drive to format. The value of this parameter represents a letter drive starting at 0 for the A: drive. For example, a value of 2 stands for the C: drive.


Type: UINT

The ID of the physical format. Only the following flag is currently defined.


The default format ID.


Type: UINT

This value must be 0 or one of the following values that alter the default format options in the dialog box. This value is regarded as a bitfield and should be treated accordingly.


0x001. If this flag is set, then the Quick Format option is selected.

This function is included in Shlobj.h only in Windows XP with SP1 and later.

Windows XP:  Prior to Windows XP with SP1, this function is accessible through Shell32.lib.


0x002. Selects the Create an MS-DOS startup disk option, creating a system boot disk.

Return value


Returns the format ID of the last successful format or one of the following values. The LOWORD of this value can be passed on subsequent calls as the fmtID parameter to repeat the last format.

Return code Description
An error occurred during the last format. This does not indicate that the drive is unformattable.
The last format was canceled.
The drive cannot be formatted.


The format is controlled by the dialog box interface. That is, the user must click the OK button to actually begin the format—the format cannot be started programmatically.


This call to SHFormatDrive brings up the Shell's Format dialog box for a disk in drive A, with the default formatting options selected.

SHFormatDrive(hMainWnd, 0, SHFMT_ID_DEFAULT, 0);


Requirement Value
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header shlobj_core.h (include Shlobj.h)
Library Shell32.lib
DLL Shell32.dll (version 5.0 or later)