假如以优盘为例,大家看看怎么做!500分,决不食言!

解决方案 »

  1.   

    private
        { Private declarations }
        procedure wmdevicechange(var msg:TMessage);message WM_DEVICECHANGE;
    procedure TForm1.wmdevicechange(var msg: TMessage);
    begin
      if (Msg.WParam=7) and (Msg.LPARAM=0) then
        ShowMessage('有了优盘!');
    end;
      

  2.   

    DRV_LOAD 和 DRV_REMOVE你可以参阅Delphi附带的:
      Win32 SDK
        Multimedia Programmer's Reference
          Installable Drivers
    那里讲得非常详尽了。
    GOOD LUCK!
      

  3.   

    jedi组织有个hid设备控制组件,可以枚举所有的usb设备,我找到一些代码,供参考。DeclarationTJvHidDeviceController = class(TComponent)The main purpose of a TJvHidDeviceController object is to handle TJvHidDevice objects. For each plugged HID device the controller creates a TJvHidDevice object to represent the device. The controller monitors device plugs and unplugs. On device plug a new TJvHidDevice object is created. On unplug the object is not destroyed but is signalled and goes to an unplugged state.
    The methods of TJvHidDeviceController are mainly for handing out TJvHidDevice objects by various criteria.
    There is no need to instantiate more than one TJVHidDeviceController per program.TJvHidDevice = class(TObject)A TJvHidDevice object represents a physical HID device. All static informations of the device have been read into properties of the object. The object is created at runtime by a TJvHidDeviceController which reigns all TJVHidDevice object.The HID component gives you complete access to all HID devices of Windows 98, Windows 98 SE and Windows 2000. A HID device is a USB device which you can interact with. Most of the USB devices are HID. Keyboard, mice or scanners are definitely HID. A USB Hub is not HID. There is no need to touch it to make it work. Some non USB devices are added to HID by a legacy driver.
    The main feature of USB is the hotplugging of the devices. Consequently the HID component is a controller component which handles all the HID device plugs and unplugs. You will therefore only need a single instance of the HID component in your program. Each individual HID device is represented by an instance of a HID device object. The HID controller holds a list of all HID device objects. When a HID device is plugged Windows sends a WM_DEVICECHANGE event. The HID component catches this event and adds a new instance of a HID device object to its list of  HID devices.Now you can ask the HID component to hand out one of its HID device objects. With this HID device object you can then access the individual device. When you are finished with the device hand back the HID device object to the HID component.
      

  4.   

    USB设备插入或者拔出消息可不一定是U盘,还有DC,USB Printer,USB CDRW,USB Mouse/keyboard,USB CableModem等的,只是WM_DEVICECHANGE消息是不够的。http://www.jungo.com/support/tech_docs/td86.html(方案)
    不过这东西要¥的
    http://www.jungo.com/dnload.html(下载)
      

  5.   

    好象“Kingron(单身走我路……)”提供的代码不管是俺的U盘插入和拔出它都说“有了U盘”耶???
      

  6.   

    嗯,ly_liuyang(Liu Yang) 同志确实提供了很好的方案,抄过来研究研究!How do I detect that a USB device has been plugged in or disconnected? If you are using version 5.2 or later of WinDriver, you can use the special WinDriver Plug and Play (PnP) and power management API to listen to specific PnP notifications from the OS, including notifications of device insertion/removal, and implement a relevant call-back in your application to handle such situations. Please refer to the WinDriver User's Manual for a detailed description of WinDriver's PnP API.In earlier versions of WinDriver (until version 5.05) this API is not available.
    WD_UsbScanDevice() detects the devices which are connected to the computer at the time of the function call. If another device is later connected to the computer, or a device is disconnected, these changes will not automatically be detected. WD_UsbScanDevice() must be called again in order to detect the changes.
    However, since WinDriver USB drivers are user mode WIN32 applications, they can get a notification of insertion/removal. Windows sends all applications a WM_DEVICECHANGE message. Once the application receives this message it should call WD_UsbScanDevice() to check if the device was inserted/removed (this is only good for Windows). You should therefore be able to implement PnP device insertion/removal support with earlier versions of WinDriver as well, using the Win32 API.
    You can also send a GET_DESCRIPTOR request to the device (using WD_UsbTransfer() to verify if the device is connected.Please note that in order to handle the device after it has been disconnected, you must first call WD_UsbDeviceUnregister() to free the previous handle to the device, then re-scan the USB bus to locate the device (using WD_UsbDeviceScan()), get the device's configuration information (by calling WD_UsbGetConfiguration() and re-register the device by calling WD_UsbDeviceRegister().