Voici un code qui permet d'afficher dans un " DirectoryListBox " que les disques valide, c'est une solution parmis d'autre.
Le .cpp
Le .h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; int NoDrive0 = 0; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::DirectoryListBox1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { Label1->Caption = DirectoryListBox1->Directory; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { // on elimine de DriveComboBox les lecteurs sans disques // on supprime les messages d'erreur sur les disques UINT oldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS); int a = DriveComboBox1->Items->Count; // nb de disques // on commence par la fin sinon on a un probleme // le lecteur 1 devient 0 apres une suppression for(a; a >= 0;a--) { if (DiskSize(a) > -1) { if(NoDrive0 == 0) { DriveComboBox1->Items->Delete(a); // pas de disque on elimine } } } // on retablit les messages d'erreur sur les disques SetErrorMode(oldErrorMode); // on restitue l'ancienne valeur NoDrive0 = 1; } //---------------------------------------------------------------------------
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 //--------------------------------------------------------------------------- #ifndef Unit1H #define Unit1H //--------------------------------------------------------------------------- #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> #include <Dialogs.hpp> #include <FileCtrl.hpp> //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TDirectoryListBox *DirectoryListBox1; TDriveComboBox *DriveComboBox1; TLabel *Label1; TButton *Button2; void __fastcall DirectoryListBox1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y); void __fastcall Button2Click(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif
Partager