﻿{"id":36224,"date":"2012-04-04T15:08:05","date_gmt":"2012-04-04T07:08:05","guid":{"rendered":"http:\/\/www.lanmaowang.com\/?p=36224"},"modified":"2015-04-01T23:05:51","modified_gmt":"2015-04-01T15:05:51","slug":"delphi-automatically-detects-usb-flash-drive-inserted-unplug-and-get-a-usb-memory-stick-drive-letter","status":"publish","type":"post","link":"http:\/\/www.lanmaowang.com\/?p=36224","title":{"rendered":"Delphi\u81ea\u52a8\u68c0\u6d4bU\u76d8\u63d2\u5165\u3001\u62d4\u51fa\u53ca\u83b7\u53d6U\u76d8\u76d8\u7b26"},"content":{"rendered":"<p>\n\tDelphi\u81ea\u52a8\u68c0\u6d4bU\u76d8\u63d2\u5165\u3001\u62d4\u51fa\u53ca\u83b7\u53d6U\u76d8\u76d8\u7b26<br \/>\n\t\/\/\u68c0\u6d4bU\u76d8\u63d2\u5165\u3001\u62d4\u51fa<br \/>\n\t\u6d4b\u8bd5\u901a\u8fc7<br \/>\n\t1\u3001\u65b0\u5efa\u5de5\u7a0b\uff1b<br \/>\n\t2\u3001\u5b9a\u4e49\u4e00\u4e2a\u79c1\u6709\u8fc7\u7a0b<br \/>\n\tprocedure WMDeviceChange(var Msg: TMessage); message WM_DEVICECHANGE;<\/p>\n<p>\n\t\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush:delphi;toolbar:false\">unit&nbsp;Unit1;\r\ninterface\r\nuses\r\n&nbsp;&nbsp;&nbsp;Windows,&nbsp;Messages,&nbsp;SysUtils,&nbsp;Variants,&nbsp;Classes,&nbsp;Graphics,&nbsp;Controls,&nbsp;Forms,\r\n&nbsp;&nbsp;&nbsp;Dialogs,&nbsp;AppEvnts,&nbsp;ExtCtrls,&nbsp;StdCtrls;\r\ntype\r\n&nbsp;&nbsp;&nbsp;&nbsp;TForm1&nbsp;=&nbsp;class(TForm)\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;Button1Click(Sender:&nbsp;TObject);\r\n&nbsp;&nbsp;\r\n&nbsp;&nbsp;&nbsp;private\r\n{&nbsp;Private&nbsp;declarations&nbsp;}\r\n&nbsp;&nbsp;&nbsp;procedure&nbsp;WMDeviceChange(var&nbsp;Msg:&nbsp;TMessage);&nbsp;message&nbsp;WM_DEVICECHANGE;\r\n&nbsp;&nbsp;&nbsp;public\r\n{&nbsp;Public&nbsp;declarations&nbsp;}\r\n&nbsp;&nbsp;&nbsp;end;\r\nvar\r\n&nbsp;&nbsp;&nbsp;Form1:&nbsp;TForm1;\r\nimplementation\r\n{$R&nbsp;*.dfm}\r\nprocedure&nbsp;TForm1.WMDeviceChange&nbsp;(var&nbsp;Msg:&nbsp;TMessage);\r\nvar\r\n&nbsp;&nbsp;&nbsp;myMsg&nbsp;:&nbsp;String;\r\nbegin\r\n&nbsp;&nbsp;&nbsp;Case&nbsp;Msg.WParam&nbsp;of\r\n&nbsp;&nbsp;&nbsp;32768:\r\nbegin\r\n&nbsp;&nbsp;&nbsp;myMsg&nbsp;:=&#39;U\u76d8\u63d2\u5165&#39;;\r\n&nbsp;&nbsp;&nbsp;MessageBox(0,&#39;\u6ce8\u610f!U\u76d8\u5df2\u63d2\u5165!!!&#39;,&#39;AutoCopy&nbsp;Information&#39;,MB_ICONASTERISK&nbsp;and&nbsp;MB_ICONINFORMATION);\r\n&nbsp;&nbsp;&nbsp;end;\r\n&nbsp;&nbsp;&nbsp;32772:\r\nbegin\r\n&nbsp;&nbsp;&nbsp;myMsg&nbsp;:=&#39;U\u76d8\u62d4\u51fa&#39;;\r\n&nbsp;&nbsp;&nbsp;MessageBox(0,&#39;\u6ce8\u610f!U\u76d8\u5df2\u53d6\u8d70!!!&#39;,&#39;AutoCopy&nbsp;Information&#39;,MB_ICONASTERISK&nbsp;and&nbsp;MB_ICONINFORMATION);\r\nend;\r\n&nbsp;&nbsp;&nbsp;end;\r\nend;<\/pre>\n<p>\n\t===========================================<\/p>\n<p>\n\t\/\/ \u53d6U\u76d8\u76d8\u7b26\u4ee3\u7801<\/p>\n<p>\n\t\u4f7f\u7528delphi\u7a0b\u5e8f\u5b9e\u73b0U\u76d8\u76d8\u7b26\u7684\u83b7\u53d6\u5176\u5b9e\u4e0d\u662f\u5f88\u96be\uff0c\u4e0d\u8fc7\u5bf9\u4e8e\u65b0\u624b\u6765\u8bf4\u53ef\u80fd\u6709\u70b9\u56f0\u96be\uff0c\u628a\u4ee3\u7801\u8d34\u51fa\u6765\uff0c\u4f9b\u5927\u5bb6\u5b66\u4e60<\/p>\n<p>\n\t============================================<\/p>\n<pre class=\"brush:delphi;toolbar:false\">procedure&nbsp;TForm1.Button1Click(Sender:&nbsp;TObject);\r\nvar\r\n&nbsp;&nbsp;buf:array&nbsp;[0..MAX_PATH-1]&nbsp;of&nbsp;char;\r\n&nbsp;&nbsp;m_Result:Integer;\r\n&nbsp;&nbsp;i:Integer;\r\n&nbsp;&nbsp;str_temp:string;\r\nbegin\r\nm_Result:=GetLogicalDriveStrings(MAX_PATH,buf);\r\nfor&nbsp;i:=0&nbsp;to&nbsp;(m_Result&nbsp;div&nbsp;4)&nbsp;do\r\nbegin\r\n&nbsp;&nbsp;str_temp:=string(buf[i*4]+buf[i*4+1]+buf[i*4+2]);\r\n&nbsp;&nbsp;if&nbsp;GetDriveType(pchar(str_temp))&nbsp;=&nbsp;DRIVE_REMOVABLE&nbsp;then\r\n&nbsp;&nbsp;begin\r\n&nbsp;&nbsp;&nbsp;&nbsp;ShowMessage(str_temp+&#39;\u76d8\u4e3aU\u76d8&#39;);\r\n&nbsp;&nbsp;&nbsp;&nbsp;ListBox1.Items.Add(str_temp);\r\n&nbsp;&nbsp;end;\r\nend;\r\nend;<\/pre>\n<p>\n\t=========================================\/\/\u78c1\u76d8\u7c7b\u578b\u5e38\u91cf\u53c2\u8003<\/p>\n<p>\n\tDRIVE_UNKNOWN = 0;<br \/>\n\t{$EXTERNALSYM DRIVE_UNKNOWN}<br \/>\n\tDRIVE_NO_ROOT_DIR = 1;<br \/>\n\t{$EXTERNALSYM DRIVE_NO_ROOT_DIR}<br \/>\n\tDRIVE_REMOVABLE = 2;<br \/>\n\t{$EXTERNALSYM DRIVE_REMOVABLE}<br \/>\n\tDRIVE_FIXED = 3;<br \/>\n\t{$EXTERNALSYM DRIVE_FIXED}<br \/>\n\tDRIVE_REMOTE = 4;<br \/>\n\t{$EXTERNALSYM DRIVE_REMOTE}<br \/>\n\tDRIVE_CDROM = 5;<br \/>\n\t{$EXTERNALSYM DRIVE_CDROM}<br \/>\n\tDRIVE_RAMDISK = 6;<br \/>\n\t&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Delphi\u81ea\u52a8\u68c0\u6d4bU\u76d8\u63d2\u5165\u3001\u62d4\u51fa\u53ca\u83b7\u53d6U\u76d8\u76d8\u7b26 \/\/\u68c0\u6d4bU\u76d8\u63d2\u5165\u3001\u62d4\u51fa \u6d4b\u8bd5\u901a\u8fc7 1\u3001\u65b0\u5efa\u5de5\u7a0b\uff1b 2\u3001\u5b9a\u4e49\u4e00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":36149,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[193],"tags":[198,219],"_links":{"self":[{"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/posts\/36224"}],"collection":[{"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=36224"}],"version-history":[{"count":1,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/posts\/36224\/revisions"}],"predecessor-version":[{"id":36225,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/posts\/36224\/revisions\/36225"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/media\/36149"}],"wp:attachment":[{"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=36224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=36224"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=36224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}