Bonjour à tous,

Je suis actuellement sur ma ComboBox qui liste seulement mes périphériques amovibles (clé USB). Or, lorsque que j'exécute mon programme, ma ComboBox ne se rafraîchit pas. J'ai utilisé ce code qui détecte la connexion ainsi que la déconnexion de ma clé USB :

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, FileCtrl;
 
type
 
 PDEV_BROADCAST_HDR = ^TDEV_BROADCAST_HDR;
 TDEV_BROADCAST_HDR = packed record
   dbch_size : DWORD;
   dbch_devicetype : DWORD;
   dbch_reserved : DWORD;
  end;
 
  PDEV_BROADCAST_VOLUME = ^TDEV_BROADCAST_VOLUME;
  TDEV_BROADCAST_VOLUME = packed record
   dbcv_size : DWORD;
   dbcv_devicetype : DWORD;
   dbcv_reserved : DWORD;
   dbcv_unitmask : DWORD;
   dbcv_flags : WORD;
  end;
 
type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
  //procedure FormCreate(Sender : TObject);
 
  private
    { Déclarations privées }
    procedure WMDeviceChange(var Msg: TMessage);     message WM_DEVICECHANGE;
  public
    { Déclarations publiques }
  end;
 
var
  Form1: TForm1;
  cI : Char;
  TypeLecteur : Integer ;
implementation
 
{$R *.dfm}
procedure TForm1.WMDeviceChange(var Msg: TMessage);
//procedure TForm1.FormCreate(Sender : TObject);
var
  iLetter: Integer;
  DrivePath: string;
begin
  if Msg.wParam =$8000 then
  begin
    if PDEV_BROADCAST_HDR( Msg.LParam )^.dbch_devicetype <>2 then exit;
    if PDEV_BROADCAST_VOLUME( Msg.LParam )^.dbcv_flags <>0 then exit;  for iLetter := Ord('A') to Ord('Z') do
    begin
      DrivePath := Chr(iLetter) + ':\';
      if GetDriveType(PChar(DrivePath)) = DRIVE_REMOVABLE then
      begin
        ComboBox1.Items.Add(DrivePath);
      end;
    end;
  end
  else
  if Msg.wParam =$8004 then
  begin
    if PDEV_BROADCAST_HDR( Msg.LParam )^.dbch_devicetype <>2 then exit;
    if PDEV_BROADCAST_VOLUME( Msg.LParam )^.dbcv_flags <>0 then exit;
    ComboBox1.Items.Clear;
  end;
end;
 
end.
Mais ce code est assez long... Y aurait-il une autre astuce pour mettre à jour ma ComboBox plus simplement ?

D'avance, merci