asp.net識別u盤執行個體代碼

來源:互聯網
上載者:User

asp教程.net識別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 usb
{
  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)
  {
  richtextbox1.appendtext("u盤已插入,盤符為:" + drive.name.tostring() + "rn");
  break;
  }
  }
  break;
  case dbt_configchangecanceled:
  messagebox.show("2");
  break;
  case dbt_configchanged:
  messagebox.show("3");
  break;
  case dbt_customevent:
  messagebox.show("4");
  break;
  case dbt_devicequeryremove:
  messagebox.show("5");
  break;
  case dbt_devicequeryremovefailed:
  messagebox.show("6");
  break;
  case dbt_deviceremovecomplete: //u盤卸載
  richtextbox1.appendtext("u盤已卸載,盤符為:");
  break;
  case dbt_deviceremovepending:
  messagebox.show("7");
  break;
  case dbt_devicetypespecific:
  messagebox.show("8");
  break;
  case dbt_devnodes_changed://可用,裝置變化時
  messagebox.show("9");
  break;
  case dbt_querychangeconfig:
  messagebox.show("10");
  break;
  case dbt_userdefined:
  messagebox.show("11");
  break;
  default:
  break;
  }
  }
  }
  catch (exception ex)
  {
  messagebox.show(ex.message);
  }
  base.wndproc(ref m);
  }

  private void button1_click(object sender, eventargs e)
  {
   
  }

  }
}%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.