Ejemplo n.º 1
0
        protected override void WndProc(ref Message message)
        {
            try
            {
                base.WndProc(ref message);
                switch (message.Msg)
                {
                case 0x007e:     //监测显示器链接状态
                    RefreshActualScreens();
                    break;

                case 0x219:
                    switch (message.WParam.ToInt32())
                    {
                    case WM_DEVICECHANGE:
                        break;

                    case DBT_DEVICEARRIVAL:        //U盘插入\

                        UsbInformationClass u = new UsbInformationClass();

                        DriveInfo[] s = DriveInfo.GetDrives();
                        foreach (DriveInfo dri in s)
                        {
                            if (dri.DriveType == DriveType.Removable)
                            {
                                drive   = dri.Name.ToString();
                                u.drive = drive;
                            }
                        }


                        GetSerialPortArray();

                        //产品名称
                        u.USBName = mobj.Properties["Caption"].Value.ToString();

                        //总容量
                        u.Size = mobj.Properties["Size"].Value.ToString();


                        string[] info = mobj.Properties["PNPDeviceID"].Value.ToString().Split('&');
                        string[] xx   = info[3].Split('\\');
                        //序列号
                        u.PNPDeviceID = xx[1];
                        xx            = xx[0].Split('_');

                        //版本号
                        u.REV = xx[1];

                        //制造商ID
                        xx    = info[1].Split('_');
                        u.VID = xx[1];

                        USBInformation usb = new USBInformation(u);
                        usb.ShowDialog();
                        usb.Dispose();
                        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盘卸载
                        MessageBox.Show("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;
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex);
            }
        }
Ejemplo n.º 2
0
 public USBInformation(UsbInformationClass u)
 {
     usb = u;
     InitializeComponent();
 }