Problem mit CD/DVD Notification
20. Feb 2010, 21:26
Hat jemand eine Idee warum das unter Vista & Delphi 2006
nicht funktioniert.
Erst wenn ich das Program schließe kommt
die Message WM_DEVICECHANGE!
type
TOnDeviceArrived = procedure(Sender: TObject; Drive: Char) of object;
TOnDeviceQueryRemove = procedure(Sender: TObject; Drive: Char; var CanRemove: Boolean) of object;
TJvDeviceChanged = class(TJvComponent)
private
FHandle: THandle;
FOnDeviceArrived: TOnDeviceArrived;
FOnDeviceRemoveCompleted: TOnDeviceArrived;
function GetFirstDriveLetter(UnitMask: Longint): Char;
procedure WndProc(var Msg: TMessage);
public
procedure WMDeviceChange(var Msg: TWMDeviceChange);
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property OnDeviceArrived: TOnDeviceArrived read FOnDeviceArrived write FOnDeviceArrived;
property OnDeviceRemoveCompleted: TOnDeviceArrived read FOnDeviceRemoveCompleted write FOnDeviceRemoveCompleted;
end;
procedure Register;
implementation
uses
JvJVCLUtils;
// (rom) change to RegisterWndProcHook mechanism?
constructor TJvDeviceChanged.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FHandle := AllocateHWndEx(WndProc);
end;
destructor TJvDeviceChanged.Destroy;
begin
DeallocateHWndEx(FHandle);
inherited Destroy;
end;
procedure TJvDeviceChanged.WndProc(var Msg: TMessage);
begin
sendMessage(HWND_BROADCAST,WM_USER + 7,0,0);
if Msg.Msg = WM_DEVICECHANGE then
WMDeviceChange(TWMDeviceChange(Msg))
else
Msg.Result := DefWindowProc(FHandle, Msg.Msg, Msg.wParam, Msg.lParam);
end;
Martin MIchael
|