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 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


Comments

  • ERROR?

    Posted by biqi on 05/15/2005 11:03pm

    CFormatDriveDialog::~CFormatDriveDialog(void) { if (m_hHook != NULL) { UnhookWindowsHookEx(m_hHook); CFormatDriveDialog::m_hHook = NULL; } }

    Reply
  • About a problem

    Posted by Legacy on 06/15/2003 12:00am

    Originally posted by: LeonOrient

    I downloaded your demo, which worked well.
    But after I created a WFC-AppWard project and added to the
    project the files: formatdrive.h and formatdrive.cpp , I
    compile the poject,
    the compiling result is: fatal error C1019:
    unexpected #else

    The position is at "#else" below:
    #ifndef NOT_USE_PRECOMPILED_HEADER
    # include "StdAfx.h"
    #else
    # define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
    # include <afxwin.h> // MFC core and standard components
    #endif

    What is wrong?(I used VC6)

    Reply
  • As to the CD

    Posted by Legacy on 11/20/2002 12:00am

    Originally posted by: ZHEFU ZHANG

    Hi, Rino, Thanks for yr good sample.
    Do you have any idea to make CDFS on a CDR or even write data onto it? I have checked WinXP provide such interface. If you have any links to 3rd CDR SDK, pls tell me, thank you.
    With Regards,

    Reply
  • It looks like it, but it is not the same

    Posted by Legacy on 11/04/2002 12:00am

    Originally posted by: Rino

    I have checked both tools and both tools look the same, but they are different. This tool is compatible with many Windows versions and the other tool does not run anywhere...

    Even the functionality is different. One tool disables all the fields on the Format dialog and the other tool only fills the volumename.

    Basicly both examples use the same concept with the WindowsHookEx, but that is just standard code that can be found on the site of MSDN-site of Microsoft.

    • Floppy Formatter

      Posted by asinha on 03/16/2005 12:47am

      Good

      Reply
    Reply
  • Similar to an existing article published elsewhere

    Posted by Legacy on 10/25/2002 12:00am

    Originally posted by: Ravi Bhavnani

    Seems awfully similar to this article:
    http://www.codeproject.com/dialog/CFormatDriveDialog.asp.

    :)

    /ravi

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds