国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

C#的usb通訊編程

2024-07-21 02:25:51
字體:
來源:轉載
供稿:網友


 當把u盤放插入,然后程序自動將u盤的內容復制到本地硬盤

using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.text;
using system.windows.forms;
using system.io;

namespace u盤更新
{
public partial class form1 : form
{
public const int wm_devicechange = 0x219;
public const int dbt_devicearrival = 0x8000;
public const int dbt_configchangecanceled = 0x0019;
public const int dbt_configchanged = 0x0018;
public const int dbt_customevent = 0x8006;
public const int dbt_devicequeryremove = 0x8001;
public const int dbt_devicequeryremovefailed = 0x8002;
public const int dbt_deviceremovecomplete = 0x8004;
public const int dbt_deviceremovepending = 0x8003;
public const int dbt_devicetypespecific = 0x8005;
public const int dbt_devnodes_changed = 0x0007;
public const int dbt_querychangeconfig = 0x0017;
public const int dbt_userdefined = 0xffff;

public form1()
{
initializecomponent();
}

private void form1_load(object sender, eventargs e)
{

}

protected override void wndproc(ref message m)
{
try
{
if (m.msg == wm_devicechange)
{
switch (m.wparam.toint32())
{
case wm_devicechange:
break;
case dbt_devicearrival://u盤插入
driveinfo[] s = driveinfo.getdrives();
foreach (driveinfo drive in s)
{
if (drive.drivetype == drivetype.removable)
{
listbox1.items.add("u盤已插入,盤符為:" + drive.name.tostring());
break;
}
}
break;
case dbt_configchangecanceled:
break;
case dbt_configchanged:
break;
case dbt_customevent:
break;
case dbt_devicequeryremove:
break;
case dbt_devicequeryremovefailed:
break;
case dbt_deviceremovecomplete: //u盤卸載
break;
case dbt_deviceremovepending:
break;
case dbt_devicetypespecific:
break;
case dbt_devnodes_changed:
break;
case dbt_querychangeconfig:
break;
case dbt_userdefined:
break;
default:
break;
}
}
}
catch (exception ex)
{
messagebox.show(ex.message);
}
base.wndproc(ref m);
}


 


在http://www.codeproject.com/useritems/usbeject.asp找的資料
volumedeviceclass volumedeviceclass = new volumedeviceclass();
foreach (volume device in volumedeviceclass.devices)
{
// is this volume on usb disks?
if (!device.isusb)
continue;

// is this volume a logical disk?
if ((device.logicaldrive == null) || (device.logicaldrive.length == 0))
continue;

device.eject(true); // allow windows to display any relevant ui
}

http://www.codeproject.com/useritems/usbeject.asp
 

 

最大的網站源碼資源下載站,

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高雄县| 万山特区| 湘阴县| 平塘县| 霍州市| 顺平县| 临江市| 玉屏| 南阳市| 肇东市| 驻马店市| 乌鲁木齐市| 鹤岗市| 鄄城县| 冷水江市| 扎赉特旗| 天门市| 西华县| 城口县| 绥阳县| 舒城县| 晴隆县| 济源市| 洪泽县| 成安县| 涟源市| 澄城县| 山东省| 金秀| 额济纳旗| 武宣县| 吉隆县| 奇台县| 嘉定区| 怀来县| 栾川县| 葫芦岛市| 元朗区| 团风县| 乐平市| 金昌市|