IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants VCL Delphi Discussion :

ComboBox --> Rafraichissement / Mise à jour / Actualisation


Sujet :

Composants VCL Delphi

  1. #1
    Membre du Club
    Inscrit en
    Novembre 2009
    Messages
    67
    Détails du profil
    Informations forums :
    Inscription : Novembre 2009
    Messages : 67
    Points : 68
    Points
    68
    Par défaut ComboBox --> Rafraichissement / Mise à jour / Actualisation
    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

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2010
    Messages
    71
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2010
    Messages : 71
    Points : 102
    Points
    102
    Par défaut
    Salut,
    on peut simplifier très légèrement (pas testé)
    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
    procedure TForm1.WMDeviceChange(var Msg: TMessage);
    var
      iLetter: Integer;
      DrivePath: string;
    begin
      if (Msg.wParam = $8000) or (Msg.wParam = $8004) then
        if PDEV_BROADCAST_HDR( Msg.LParam )^.dbch_devicetype = 2 then 
          if PDEV_BROADCAST_VOLUME( Msg.LParam )^.dbcv_flags = 0 then 
          begin
            ComboBox1.clear;
            for iLetter := Ord('A') to Ord('Z') do
            begin
              DrivePath := Chr(iLetter) + ':\';
              if GetDriveType(PChar(DrivePath)) = DRIVE_REMOVABLE then
                ComboBox1.Items.Add(DrivePath);
            end;
          end;  
    end;
    @+

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. mise à jour d'un combobox
    Par stefane26 dans le forum Excel
    Réponses: 12
    Dernier message: 11/07/2007, 10h27
  2. Mise à jour d'une comboBox dans Visual Studio
    Par lilimilou29 dans le forum VB.NET
    Réponses: 7
    Dernier message: 31/05/2007, 17h04
  3. Mise à jour et actualisation httpd
    Par vacknov dans le forum Apache
    Réponses: 3
    Dernier message: 17/04/2007, 16h48
  4. Réponses: 7
    Dernier message: 30/08/2006, 15h38
  5. Réponses: 6
    Dernier message: 20/07/2006, 16h15

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo