CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

500分:高难度问题-如何得到USB设备插入或者拔出消息!

楼主ss(捧着诗集的程序员)2002-10-10 20:10:48 在 Delphi / VCL组件开发及应用 提问

假如以优盘为例,大家看看怎么做!  
   
  500分,决不食言! 问题点数:100、回复次数:10Top

1 楼blazingfire(烈焰)(对.net极度憎恨中....)回复于 2002-10-10 20:16:14 得分 0

哈哈,这问题和检测机器装没有装光驱一样费神!Top

2 楼smhpnuaa(天将降大任于斯人也!)回复于 2002-10-10 20:18:24 得分 0

好像系统自己能智能识别的,不然怎么叫“即插即用”,呵呵,猜测Top

3 楼Kingron(单身走我路……)回复于 2002-10-10 20:21:34 得分 20

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;  
  Top

4 楼cnsuyong(小可)回复于 2002-10-10 20:23:00 得分 0

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

5 楼zmcant(好人)回复于 2002-10-10 20:25:15 得分 0

upupTop

6 楼smhpnuaa(天将降大任于斯人也!)回复于 2002-10-10 20:30:35 得分 20

jedi组织有个hid设备控制组件,可以枚举所有的usb设备,我找到一些代码,供参考。  
   
  Declaration  
   
  TJvHidDeviceController   =   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.Top

7 楼ly_liuyang(Liu Yang LYSoft http://lysoft.7u7.net)回复于 2002-10-10 20:31:02 得分 20

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(下载)Top

8 楼cnsuyong(小可)回复于 2002-10-10 20:39:45 得分 20

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

9 楼ss(捧着诗集的程序员)回复于 2002-10-10 20:41:38 得分 0

楼上的同志:能详细点吗?钱不是问题,谢谢你,谢谢大家Top

10 楼smhpnuaa(天将降大任于斯人也!)回复于 2002-10-10 20:46:52 得分 20

嗯,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().    
  Top

相关问题

  • 高难度插入问题!
  • usb插入和拔出的判定
  • 还是那个高难度插入问题!!
  • 高难度问题:EHLIB的DBGRID中能否在某一列中在插入个dbgrid??
  • 高难度............................................
  • 高难度
  • 高难度
  • 高难度
  • 高难度问题。。。
  • 高难度的噢!!!!!

关键词

  • usb
  • component
  • 消息
  • hid
  • tjvhiddevice
  • device
  • windriver
  • 拔出
  • tjvhiddevicecontroller
  • usbscandevice

得分解答快速导航

  • 帖主:ss
  • Kingron
  • smhpnuaa
  • ly_liuyang
  • cnsuyong
  • smhpnuaa

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo