Пример #1
0
 void _Detector_DeviceChanged(object sender, DeviceDetectorEventArgs e)
 {
     ControlsHelper.BeginInvoke(() =>
     {
         InfoLabel.Text = e.ChangeType.ToString();
     });
 }
Пример #2
0
 private void detector_DeviceChanged(object sender, DeviceDetectorEventArgs e)
 {
     if (e.ChangeType == Win32.DBT.DBT_DEVNODES_CHANGED)
     {
         RefreshHardwareList();
     }
 }
Пример #3
0
 void _Detector_DeviceChanged(object sender, DeviceDetectorEventArgs e)
 {
     BeginInvoke((MethodInvoker)delegate ()
     {
         InfoLabel.Text = e.ChangeType.ToString();
     });
 }
Пример #4
0
 void _Detector_DeviceChanged(object sender, DeviceDetectorEventArgs e)
 {
     BeginInvoke((MethodInvoker) delegate()
     {
         InfoLabel.Text = e.ChangeType.ToString();
     });
 }
Пример #5
0
 private void Detector_DeviceChanged(object sender, DeviceDetectorEventArgs e)
 {
     RefreshHardwareList();
     if (MainTabControl.SelectedTab != LogsTabPage)
     {
         return;
     }
     AddLogLine("{0}: {1} {2}", e.ChangeType, e.DeviceType, e.DeviceInfo);
 }
Пример #6
0
        void RaiseDeviceChanged(object sender, DeviceDetectorEventArgs e)
        {
            var ev = DeviceChanged;

            if (ev != null)
            {
                var eventListeners = ev.GetInvocationList();
                for (int i = 0; i < eventListeners.Count(); i++)
                {
                    var methodToInvoke = (DeviceDetectorEventHandler)eventListeners[i];
                    methodToInvoke.BeginInvoke(sender, e, EndAsyncEvent, null);
                }
            }
        }
Пример #7
0
        private void RaiseDeviceChanged(object sender, DeviceDetectorEventArgs e)
        {
            var ev = DeviceChanged;

            if (ev == null)
            {
                return;
            }
            var eventListeners = ev.GetInvocationList();

            for (var i = 0; i < eventListeners.Length; i++)
            {
                var methodToInvoke = (DeviceDetectorEventHandler)eventListeners[i];
                methodToInvoke.BeginInvoke(sender, e, EndAsyncEvent, null);
            }
        }
Пример #8
0
        /// <summary>
        /// Message handler which must be called from client form. Processes Windows messages and calls event handlers. 
        /// </summary>
        /// <param name="m"></param>
        public void WndProc(ref Message m)
        {
            if (m.Msg == WM_DEVICECHANGE)
            {
                var changeType = (DBT)m.WParam.ToInt32();
                object deviceInfo = null;
                DBCH_DEVICETYPE? deviceType = null;
                if (m.LParam != IntPtr.Zero)
                {
                    var hdr = (DEV_BROADCAST_HDR)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_HDR));
                    deviceType = hdr.dbch_devicetype;
                    switch (deviceType)
                    {
                        case DBCH_DEVICETYPE.DBT_DEVTYP_DEVICEINTERFACE:
                            var di = (DEV_BROADCAST_DEVICEINTERFACE)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_DEVICEINTERFACE));
                            IntPtr dName = new IntPtr(m.LParam.ToInt64() + Marshal.OffsetOf(typeof(DEV_BROADCAST_DEVICEINTERFACE), "dbcc_name").ToInt64());
                            di.dbcc_name = Marshal.PtrToStringAuto(dName).ToCharArray();
                            deviceInfo = di;
                            break;
                        case DBCH_DEVICETYPE.DBT_DEVTYP_HANDLE:
                            deviceInfo = (DEV_BROADCAST_HANDLE)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_HANDLE));
                            break;
                        case DBCH_DEVICETYPE.DBT_DEVTYP_OEM:
                            deviceInfo = (DEV_BROADCAST_OEM)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_OEM));
                            break;
                        case DBCH_DEVICETYPE.DBT_DEVTYP_PORT:
                            var pi = (DEV_BROADCAST_PORT)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_PORT));
                            IntPtr pName = new IntPtr(m.LParam.ToInt64() + Marshal.OffsetOf(typeof(DEV_BROADCAST_PORT), "dbcc_name").ToInt64());
                            pi.dbcc_name = Marshal.PtrToStringAuto(pName).ToCharArray();
                            deviceInfo = pi;
                            break;
                        case DBCH_DEVICETYPE.DBT_DEVTYP_VOLUME:
                            deviceInfo = (DEV_BROADCAST_VOLUME)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_VOLUME));
                            break;
                        default:
                            break;
                    }
                }
                var e = new DeviceDetectorEventArgs(changeType, deviceType, deviceInfo);
                if (DeviceChanged != null) DeviceChanged(this, e);
                switch (changeType)
                {
                    // Device is about to be removed. Any application can cancel the removal.
                    case DBT.DBT_DEVICEQUERYREMOVE:
                        if (deviceType == DBCH_DEVICETYPE.DBT_DEVTYP_HANDLE)
                        {
                            // If the client wants to cancel, let Windows know.
                            if (e.Cancel) m.Result = (IntPtr)BROADCAST_QUERY_DENY;
                        }
                        break;
                }

            }
        }
Пример #9
0
		void _Detector_DeviceChanged(object sender, DeviceDetectorEventArgs e)
		{
			InfoLabel.Text = e.ChangeType.ToString();
		}
Пример #10
0
        /// <summary>
        /// Message handler which must be called from client form. Processes Windows messages and calls event handlers.
        /// </summary>
        /// <param name="m"></param>
        public void WndProc(ref Message m)
        {
            if (m.Msg == WM_DEVICECHANGE)
            {
                var             changeType = (DBT)m.WParam.ToInt32();
                object          deviceInfo = null;
                DBCH_DEVICETYPE?deviceType = null;
                if (m.LParam != IntPtr.Zero)
                {
                    var hdr = (DEV_BROADCAST_HDR)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_HDR));
                    deviceType = hdr.dbch_devicetype;
                    switch (deviceType)
                    {
                    case DBCH_DEVICETYPE.DBT_DEVTYP_DEVICEINTERFACE:
                        var    di    = (DEV_BROADCAST_DEVICEINTERFACE)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_DEVICEINTERFACE));
                        IntPtr dName = new IntPtr(m.LParam.ToInt64() + Marshal.OffsetOf(typeof(DEV_BROADCAST_DEVICEINTERFACE), "dbcc_name").ToInt64());
                        di.dbcc_name = Marshal.PtrToStringAuto(dName).ToCharArray();
                        deviceInfo   = di;
                        break;

                    case DBCH_DEVICETYPE.DBT_DEVTYP_HANDLE:
                        deviceInfo = (DEV_BROADCAST_HANDLE)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_HANDLE));
                        break;

                    case DBCH_DEVICETYPE.DBT_DEVTYP_OEM:
                        deviceInfo = (DEV_BROADCAST_OEM)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_OEM));
                        break;

                    case DBCH_DEVICETYPE.DBT_DEVTYP_PORT:
                        var    pi    = (DEV_BROADCAST_PORT)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_PORT));
                        IntPtr pName = new IntPtr(m.LParam.ToInt64() + Marshal.OffsetOf(typeof(DEV_BROADCAST_PORT), "dbcc_name").ToInt64());
                        pi.dbcc_name = Marshal.PtrToStringAuto(pName).ToCharArray();
                        deviceInfo   = pi;
                        break;

                    case DBCH_DEVICETYPE.DBT_DEVTYP_VOLUME:
                        deviceInfo = (DEV_BROADCAST_VOLUME)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_VOLUME));
                        break;

                    default:
                        break;
                    }
                }
                var e = new DeviceDetectorEventArgs(changeType, deviceType, deviceInfo);
                if (DeviceChanged != null)
                {
                    DeviceChanged(this, e);
                }
                switch (changeType)
                {
                // Device is about to be removed. Any application can cancel the removal.
                case DBT.DBT_DEVICEQUERYREMOVE:
                    if (deviceType == DBCH_DEVICETYPE.DBT_DEVTYP_HANDLE)
                    {
                        // If the client wants to cancel, let Windows know.
                        if (e.Cancel)
                        {
                            m.Result = (IntPtr)BROADCAST_QUERY_DENY;
                        }
                    }
                    break;
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Message handler which must be called from client form. Processes Windows messages and calls event handlers.
        /// </summary>
        /// <param name="m"></param>
        public void WndProc(ref Message m)
        {
            // Please note that only top-level window of the form will receive a set of default WM_DEVICECHANGE messages
            // when new devices added, become available or removed.
            // You do not need to register to receive these default messages.
            if (m.Msg == WM_DEVICECHANGE)
            {
                object          deviceInfo = null;
                DBCH_DEVICETYPE?deviceType = null;
                if (m.LParam != IntPtr.Zero)
                {
                    var hdr = (DEV_BROADCAST_HDR)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_HDR));
                    deviceType = hdr.dbch_devicetype;
                    switch (deviceType)
                    {
                    case DBCH_DEVICETYPE.DBT_DEVTYP_DEVICEINTERFACE:
                        var    di    = (DEV_BROADCAST_DEVICEINTERFACE)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_DEVICEINTERFACE));
                        IntPtr dName = new IntPtr(m.LParam.ToInt64() + Marshal.OffsetOf(typeof(DEV_BROADCAST_DEVICEINTERFACE), "dbcc_name").ToInt64());
                        di.dbcc_name = Marshal.PtrToStringAuto(dName).ToCharArray();
                        deviceInfo   = di;
                        break;

                    case DBCH_DEVICETYPE.DBT_DEVTYP_HANDLE:
                        deviceInfo = (DEV_BROADCAST_HANDLE)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_HANDLE));
                        break;

                    case DBCH_DEVICETYPE.DBT_DEVTYP_OEM:
                        deviceInfo = (DEV_BROADCAST_OEM)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_OEM));
                        break;

                    case DBCH_DEVICETYPE.DBT_DEVTYP_PORT:
                        var    pi    = (DEV_BROADCAST_PORT)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_PORT));
                        IntPtr pName = new IntPtr(m.LParam.ToInt64() + Marshal.OffsetOf(typeof(DEV_BROADCAST_PORT), "dbcc_name").ToInt64());
                        pi.dbcc_name = Marshal.PtrToStringAuto(pName).ToCharArray();
                        deviceInfo   = pi;
                        break;

                    case DBCH_DEVICETYPE.DBT_DEVTYP_VOLUME:
                        deviceInfo = (DEV_BROADCAST_VOLUME)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_VOLUME));
                        break;

                    default:
                        break;
                    }
                }
                var changeType = (DBT)m.WParam.ToInt32();
                var e          = new DeviceDetectorEventArgs(changeType, deviceType, deviceInfo);
                RaiseDeviceChanged(this, e);
                switch (changeType)
                {
                // Device is about to be removed. Any application can cancel the removal.
                case DBT.DBT_DEVICEQUERYREMOVE:
                    if (deviceType == DBCH_DEVICETYPE.DBT_DEVTYP_HANDLE)
                    {
                        // If the client wants to cancel, let Windows know.
                        if (e.Cancel)
                        {
                            m.Result = (IntPtr)BROADCAST_QUERY_DENY;
                        }
                    }
                    break;
                }
            }
        }
 void _Detector_DeviceChanged(object sender, DeviceDetectorEventArgs e)
 {
     InfoLabel.Text = e.ChangeType.ToString();
 }
Пример #13
0
 void detector_DeviceChanged(object sender, DeviceDetectorEventArgs e)
 {
     if (e.ChangeType == Win32.DBT.DBT_DEVNODES_CHANGED)
     {
         RefreshHardwareList();
     }
 }