Newsgroup: it.comp.lang.visual-basic
Titolo: Formattazione dischetto.





Salve a tutti,
sono di nuovo alle 
prese con l'annoso problema della formattazione di un
supporto fisico. 
Cercando nella documentazione KB di Microsoft ho trovato il
file 
che riporto qui sotto
. Il problema sta nel primo parametro 
della funzione che
non ho la più pallida idea di cosa sia... qualcuno 
ha un suggerimento da
darmi?
Grazie anticipatamente...
Bye 
Attilio.










HOWTO: Call 
            SHFormatDrive in Windows 95 and Windows NT
Last reviewed: September 
            11, 1997
Article ID: Q173688 




The 
            information in this article applies to: 




Microsoft Win32 Application Programming 
                Interface (API) included with: 


    - Microsoft Windows 95
    - Microsoft Windows NT 4.0






SUMMARY


Although most Win32 applications do not need to be 
            able to format disks, some do. Windows 95 and Windows NT provide an 
            API function called SHFormatDrive, which presents the same dialog 
            box as the Windows 95 and Windows NT shells, formats the specified 
            diskette. This article describes how to call SHFormatDrive. 






MORE INFORMATION


Currently, SHFormatDrive is not in the Platform SDK 
            documentation or SHELLAPI.H. However, it is in SHELL32.LIB. Until 
            the documentation and SHELLAPI.H are updated, use the following 
            declarations and function description: 


   #if !defined(SHFMT_OPT_FULL)

   #if defined (__cplusplus)
   extern "C" {
   #endif

   /*****************************************************************
   The SHFormatDrive API provides access to the Shell's format
   dialog box. This allows applications that want to format disks to bring
   up the same dialog box that the Shell uses for disk formatting.

   PARAMETERS
      hwnd    = The window handle of the window that will own the
                dialog. NOTE that hwnd == NULL does not cause this
                dialog to come up as a "top level application"
                window. This parameter should always be non-null,
                this dialog box is only designed to be the child of
                another window, not a stand-alone application.

      drive   = The 0 based (A: == 0) drive number of the drive
                to format.

      fmtID   = Currently must be set to SHFMT_ID_DEFAULT.

      options = There are currently only two option bits defined.

                   SHFMT_OPT_FULL
                   SHFMT_OPT_SYSONLY

                SHFMT_OPT_FULL specifies that the "Quick Format"
                setting should be cleared by default. If the user
                leaves the "Quick Format" setting cleared, then a
                full format will be applied (this is useful for
                users that detect "unformatted" disks and want
                to bring up the format dialog box).

                If options is set to zero (0), then the "Quick
                Format" setting will be set by default. In addition,
                if the user leaves it set, a quick format will be
                performed.

                The SHFMT_OPT_SYSONLY initializes the dialog to
                default to just sys the disk.

                All other bits are reserved for future expansion
                and must be 0.

                Please note that this is a bit field and not a
                value, treat it accordingly.

      RETURN
         The return is either one of the SHFMT_* values, or if
         the returned DWORD value is not == to one of these
         values, then the return is the physical format ID of the
         last successful format. The LOWORD of this value can be
         passed on subsequent calls as the fmtID parameter to
         "format the same type you did last time".

   *****************************************************************/
   DWORD WINAPI SHFormatDrive(HWND hwnd,
                              UINT drive,
                              UINT fmtID,
                              UINT options);

   //
   // Special value of fmtID which means "use the defaultformat"
   //

   #define SHFMT_ID_DEFAULT   0xFFFF

   //
   // Option bits for options parameter
   //

   #define SHFMT_OPT_FULL     0x0001
   #define SHFMT_OPT_SYSONLY  0x0002

   //
   // Special return values. PLEASE NOTE that these are DWORD values.
   //

   #define SHFMT_ERROR     0xFFFFFFFFL    // Error on last format,
                                          // drive may be formatable
   #define SHFMT_CANCEL    0xFFFFFFFEL    // Last format wascanceled
   #define SHFMT_NOFORMAT  0xFFFFFFFDL    // Drive is not formatable

   #if defined (__cplusplus)
   }
   #endif
   #endif

Here is an example call to SHFormatDrive 
            that will format a diskette in drive "A:". 


   SHFormatDrive (hMainWnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
If a diskette is not currently in the drive when 
            SHFormatDrive is called, the system will display a critical error 
            dialog box asking the user to Abort, Retry or Ignore. You can 
            prevent the system from displaying this dialog box by calling the 
            SetErrorMode API with SEM_FAILCRITICALERRORS. 



Bye Attilio.
Il primo parametro è l'handle (=Maniglia) della finestra chiamante.
Viene utilizzato da Windows per Utilizzare un metodo ad una specifica
funzione;
Sotto Visual Basic e' una proprietà di sola lettura
Prova a chiamarla così
    ...
    Call SHFormatDrive (Form1.hWnd, 0, SHFMT_ID_DEFAULT, 0)
    ...

...








Il primo parametro (hwnd) è 
l'handle di una finestra presente nel tuo programma,la puoi ottenre dalla 
proprietà hwnd di uno
 


dei 
forms presenti nel tuo programma (meglio se quello principale o quello che poi 
chiama la funzione)


E' un parametro utilizzato di frequente dalle API 
che mostrano finestre di dialogo
 


Ciao
 


Corrado
 


 


esempio:


Option Explicit
Private Declare 
Function SHFormatDrive Lib "Shell32" (ByVal hwnd As Long, ByVal Drive 
As Long, ByVal fmtID As Long, ByVal Options As Long) As Long
 


Private Sub 
Command1_Click()
Print SHFormatDrive(form1.hwnd, 0, 0, 0)
End 
Sub
 
