示例#1
0
        private void Init(Window window)
        {
            // Adds the windows message processing hook and registers USB device add/removal notification.
            HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(window).Handle);

            if (source != null)
            {
                var windowHandle = source.Handle;
                source.AddHook(HwndHandler);
                DeviceNotification.RegisterDeviceNotification(windowHandle);
            }
        }
示例#2
0
 /// <summary>
 /// Method that receives window messages.
 /// </summary>
 private IntPtr HwndHandler(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled)
 {
     if (msg == DeviceNotification.c_WmDevicechange)
     {
         DeviceNotification.DbtEventType eventType = (DeviceNotification.DbtEventType)wparam;
         DeviceData device = DeviceNotification.GetDevice(lparam);
         if (!m_FilterByType || device.DeviceType == m_DeviceType)
         {
             if (eventType == DeviceNotification.DbtEventType.Arrival)
             {
                 OnDeviceArrival(device);
             }
             else if (eventType == DeviceNotification.DbtEventType.RemoveComplete)
             {
                 OnDeviceRemoval(device);
             }
         }
     }
     handled = false;
     return(IntPtr.Zero);
 }
示例#3
0
 private void Close()
 {
     DeviceNotification.UnregisterDeviceNotification();
 }