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: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • VMware vCloud® Government Service provided by Carpathia® is an enterprise-class hybrid cloud service that delivers the tried and tested VMware capabilities widely used by government organizations today, with the added security and compliance assurance of FedRAMP authorization. The hybrid cloud is becoming more and more prevalent – in fact, nearly three-fourths of large enterprises expect to have hybrid deployments by 2015, according to a recent Gartner analyst report. Learn about the benefits of …

Most Popular Programming Stories

More for Developers

RSS Feeds