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

  • Download the Information Governance Survey Benchmark Report to gain insights that can help you further establish business value in your Records and Information Management (RIM) program and across your entire organization. Discover how your peers in the industry are dealing with this evolving information lifecycle management environment and uncover key insights such as: 87% of organizations surveyed have a RIM program in place 8% measure compliance 64% cannot get employees to "let go" of information for …

  • You probably have several goals for your patient portal of choice. Is "community" one of them? With a bevy of vendors offering portal solutions, it can be challenging for a hospital to know where to start. Fortunately, YourCareCommunity helps ease the decision-making process. Read this white paper to learn more. "3 Ways Clinicians can Leverage a Patient Portal to Craft a Healthcare Community" is a published document owned by www.medhost.com

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds