Недавно добавленные исходники

•  Animation Loaders  855

•  DeLiKaTeS Tetris (Тетрис)  5 804

•  TDictionary Custom Sort  7 762

•  Fast Watermark Sources  7 438

•  3D Designer  10 663

•  Sik Screen Capture  7 984

•  Patch Maker  8 193

•  Айболит (remote control)  8 245

•  ListBox Drag & Drop  7 053

•  Доска для игры Реверси  100 544

•  Графические эффекты  8 319

•  Рисование по маске  7 697

•  Перетаскивание изображений  6 299

•  Canvas Drawing  6 672

•  Рисование Луны  6 599

•  Поворот изображения  5 745

•  Рисование стержней  4 683

•  Paint on Shape  3 383

•  Генератор кроссвордов  4 359

•  Головоломка Paletto  3 508

•  Теорема Монжа об окружностях  4 323

•  Пазл Numbrix  2 794

•  Заборы и коммивояжеры  3 738

•  Игра HIP  2 515

•  Игра Go (Го)  2 513

•  Симулятор лифта  2 910

•  Программа укладки плитки  2 336

•  Генератор лабиринта  3 072

•  Проверка числового ввода  2 570

•  HEX View  2 975

 
скрыть

  Форум  

Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Обработать момент вставки и вытаскивания CD



Оформил: DeeCo

{ 
  Some applications need to know when the user inserts or 
  removes a compact disc or DVD from a CD-ROM drive without 
  polling for media changes. Windows provide a way to notify these 
  applications through the WM_DEVICECHANGE message. 
}

 type
   TForm1 = class(TForm)
   private
     procedure WMDeviceChange(var Msg: TMessage); message WM_DEVICECHANGE;
   public

   end;

 {...}

 implementation

 {$R *.DFM}

 procedure TForm1.WMDeviceChange(var Msg: TMessage);
 const
   DBT_DEVICEARRIVAL = $8000; // system detected a new device 
  DBT_DEVICEREMOVECOMPLETE = $8004;  // device is gone 
var
   myMsg: string;
 begin
   inherited;
   case Msg.wParam of
     DBT_DEVICEARRIVAL: myMsg  := 'CD inserted!';
     DBT_DEVICEREMOVECOMPLETE: myMsg := 'CD removed!';
   end;
   ShowMessage(myMsg);
 end;


 {*********************************************}

 // Advanced Code: 
// When the device is of type volume, then we can get some device specific 
// information, namely specific information about a logical volume. 
// by Juergen Kantz 

unit Unit1;

 interface

 uses
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
   Dialogs, StdCtrls;

 type
   TForm1 = class(TForm)
     Button1: TButton;
     label1: TLabel;
   private
     procedure WMDeviceChange(var Msg: TMessage); message WM_DeviceChange;
     { Private declarations }
   public
     { Public declarations }
   end;

 const
     DBT_DeviceArrival = $8000;
   DBT_DeviceRemoveComplete = $8004;
   DBTF_Media = $0001;
   DBT_DevTyp_Volume = $0002;

 type
   PDevBroadcastHdr = ^TDevBroadcastHdr;
   TDevBroadcastHdr = packed record
     dbcd_size: DWORD;
     dbcd_devicetype: DWORD;
     dbcd_reserved: DWORD;
   end;

 type
   PDevBroadcastVolume = ^TDevBroadcastVolume;
   TDevBroadcastVolume = packed record
     dbcv_size: DWORD;
     dbcv_devicetype: DWORD;
     dbcv_reserved: DWORD;
     dbcv_unitmask: DWORD;
     dbcv_flags: Word;
   end;

 var
   Form1: TForm1;


 implementation

 {$R *.dfm}


 function GetDrive(pDBVol: PDevBroadcastVolume): string;
 var
   i: Byte;
   Maske: DWORD;
 begin
   if (pDBVol^.dbcv_flags and DBTF_Media) = DBTF_Media then
   begin
     Maske := pDBVol^.dbcv_unitmask;
     for i := 0 to 25 do
     begin
       if (Maske and 1) = 1 then
         Result := Char(i + Ord('A')) + ':';
       Maske := Maske shr 1;
     end;
   end;
 end;

 procedure TForm1.WMDeviceChange(var Msg: TMessage);
 var
   Drive: string;
 begin
   case Msg.wParam of
     DBT_DeviceArrival:
       if PDevBroadcastHdr(Msg.lParam)^.dbcd_devicetype = DBT_DevTyp_Volume then
       begin
         Drive := GetDrive(PDevBroadcastVolume(Msg.lParam));
         label1.Caption := 'CD inserted in Drive ' + Drive;
       end;
     DBT_DeviceRemoveComplete:
       if PDevBroadcastHdr(Msg.lParam)^.dbcd_devicetype = DBT_DevTyp_Volume then
       begin
         Drive := GetDrive(PDevBroadcastVolume(Msg.lParam));
         label1.Caption := 'CD removed from Drive ' + Drive;
       end;
   end;
 end;


 end.







Copyright © 2004-2026 "Delphi Sources" by «SiteAnalyzer». Delphi World FAQ

Группа ВКонтакте