How to Format a (Floppy) Disk | CodeGuru

How to Format a (Floppy) Disk

Click here for a larger image. Environment: VC6 SP5; it is suitable for Windows 95/98/NT4/2000/XP This example shows how to call the Shell Format routine (SHFormatDrive from the Shell32.dll library). Normally, when you call this method, the dialog itself is not configured according to your preferred defaults. This demo shows how to call this routine […]

Written By
CodeGuru Staff
CodeGuru Staff
Nov 19, 2002
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More



Click here for a larger image.

Environment: VC6 SP5; it is suitable for Windows 95/98/NT4/2000/XP

This example shows how to call the Shell Format routine (SHFormatDrive from the Shell32.dll library).

Normally, when you call this method, the dialog itself is not configured according to your preferred defaults. This demo shows how to call this routine and how to configure it before the dialog is painted. It also disables certain fields so that the user cannot modify them. The difficulty in this sample is the support for many Windows versions. Each Windows version handles this routine differently; even the API and the dialog itself are different for the different Windows versions….

This sample can handle them all! (Windows 95OSR1, 95OSR2, 98, 98SE, NT4, 2000, and XP) The remaining Windows versions are excluded now by code, but in the near future this will be expanded for ALL English Windows versions released since Windows 95.

The code is entirely located in one Class, which is stored in the FormatDrive.h/cpp files. The remaining files are only used for building up this Demo. Below an example is given that shows how to call the routines in the Class.

// The following two lines are BOTH needed to initialise
// the Format Dialog
CFormatDriveDialog dlg;
Result = dlg.DoModal(AfxGetMainWnd()->m_hWnd,’A’,/*
         QuickFormat */ true, “VolumeLabel”);
// When formatting is finished, aborted, or cancelled,
// the function DoModal returns
switch (Result)
{
   case IDOK:
      MessageBox(“The main dialog has detected that Format was
                  completed successfully”);
      break;
   case IDCANCEL:
      MessageBox(“The main dialog has detected that Format was
                  Cancelled”);
      break;
   case IDABORT:
      MessageBox(“The main dialog has detected that Format has
                  failed to load the dependant libraries”);
      break;
   default:
      ASSERT(FALSE);
      break;
}

Downloads

Download demo project (Source included) – 21 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.