コード例 #1
0
ファイル: Form1.cs プロジェクト: beketata/sded5-prog
        // [System.Security.Permissions.PermissionSet( System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust" )]
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            int wParam = (int)m.WParam;

            // Обрабатываем событие при изменении статуса USB устройств.
            //
            if (m.Msg == Win32.WM_DEVICECHANGE)
            {
                if ((wParam == Win32.DBT_DEVICEARRIVAL) || (wParam == Win32.DBT_DEVICEREMOVECOMPLETE))
                {
                    // Read the dhdr.dbcc_devicetype
                    //
                    Win32.DEV_BROADCAST_HDR devPtr = (Win32.DEV_BROADCAST_HDR)Marshal.PtrToStructure(m.LParam, typeof(Win32.DEV_BROADCAST_HDR));
                    if (devPtr.dbcc_devicetype == Win32.DBT_DEVTYP_DEVICEINTERFACE)
                    {
                        Win32.DEV_BROADCAST_DEVICEINTERFACE dip = (Win32.DEV_BROADCAST_DEVICEINTERFACE)Marshal.PtrToStructure(m.LParam, typeof(Win32.DEV_BROADCAST_DEVICEINTERFACE));
                        string sDevName = dip.dbcc_name;
                        if (sDevName.ToUpper().StartsWith(_usbDeviceID))                            // Если это SuperPro 6100.
                        {
                            if (wParam == Win32.DBT_DEVICEARRIVAL)
                            {
                                USB_PortOpen_();
                            }
                            else if (wParam == Win32.DBT_DEVICEREMOVECOMPLETE)
                            {
                                USB_CloseFiles();
                                USB_InfoToggle(false);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: beketata/sded5-prog
        /// <summary>
        /// Override called when the window handle has been created.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnHandleCreated(EventArgs e)
        {
            // Подписываем наш обработчик оконных сообщений на получение сообщений
            // DBT_DEVICEARRIVAL и DBT_DEVICEREMOVECOMPLETE
            //
            Win32.DEV_BROADCAST_DEVICEINTERFACE oInterfaceIn = new Win32.DEV_BROADCAST_DEVICEINTERFACE();
            oInterfaceIn.dbcc_size       = Marshal.SizeOf(oInterfaceIn);
            oInterfaceIn.dbcc_classguid  = Win32.GUID_DEVINTERFACE_USB_DEVICE;
            oInterfaceIn.dbcc_devicetype = Win32.DBT_DEVTYP_DEVICEINTERFACE;
            Win32.RegisterDeviceNotification(this.Handle, oInterfaceIn, Win32.DEVICE_NOTIFY_WINDOW_HANDLE);

            base.OnHandleCreated(e);
        }