Autor Beitrag
FloSch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 129



BeitragVerfasst: Di 22.04.03 11:32 
Hallo!

Folgendes:
Ich möchte auf auf einen CD Wechsel reagieren, d.h. sobald eine CD ausgeworfen wird bzw. vom System intialisiert wird möchte ich mit meinem Programm agieren.

Ich habe bereits den Tipp aus dem SwissDelphiCenter.ch getestet - nur leider ohne Erfolg (ergab keinerlei Fehlermeldungen).

Grüße
Flo'auf Antworten wartend'rian :roll:

_________________
Windows 200 Prof. - Debian Sarge
D5 Prof & D6 PE - Kylix 3 Professional - Free Pascal
FloSch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 129



BeitragVerfasst: Di 22.04.03 11:41 
Hallo,

das soll mal nun einer verstehen: Computer neugestartet - genau das gleiche Programm aufgerufen und siehe da: es geht.

Naja, Sachen gibts... :?: :?: :?: :?: :?: :?:

Für Leute die den Tipp noch suchen:
ausblenden volle Höhe Quelltext
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:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
{ 
  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.

Grüße
Florian :roll:

_________________
Windows 200 Prof. - Debian Sarge
D5 Prof & D6 PE - Kylix 3 Professional - Free Pascal
Xanadu
Hält's aus hier
Beiträge: 2

Win2000, XP
D5
BeitragVerfasst: So 08.05.05 12:57 
Hi,

WMDeviceChange tut gut so, nur krieg ich danach dauernd den Explorer mit dem Titel "Disk(F:)" hoch und find keinen Weg das zu disablen. Hab in die Registry schon die unmöglichsten Werte beim "AutoRun/AutoPlay" eingetragen (91, 95, 5A, 5B...). Hilft alles nix.

Hat jemand einen Plan dazu wie ich das unterdrücken kann ohne mir das Hwnd zu besorgen und das Ding über PostMessage+WMClose abzuschiessen?

Thank´s a lot.