示例#1
0
        public ViewModel(Window mainWin)
        {
            _dispatchTimer = new DispatcherTimer(new TimeSpan(0, 0, 5), DispatcherPriority.Normal, OnDispatcherTimer,
                                                 mainWin.Dispatcher);
            _dispatchTimer.Stop();;

            try
            {
                _monitorManager = MonitorManagerFactory.GetInstance();

                _monitorManager.UpdateMonitors(null);

                _deviceDetector = DeviceDetector.GetInstance();

                _deviceDetector.DeviceAttached += this.OnDeviceNotify;
                _deviceDetector.DeviceRemoved += this.OnDeviceNotify;
            }
            catch (Win32Exception win32Exception)
            {
                MessageBox.Show(String.Format("{0} \n StackTrace: \n{1}", win32Exception.Message, win32Exception.StackTrace),
                                             win32Exception.ErrorCode.ToString());
            }
            catch (System.TypeLoadException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#2
0
 private void OnDeviceNotify(object sender, DeviceDetector.DeviceChangedEventArgs e)
 {
     try
     {
         var deviceInfo = e.DeviceInfo as Win32Wrapper.CTypes.DEV_BROADCAST_DEVICEINTERFACE;
         if (deviceInfo != null)
         {
             Guid deviceGuid = new Guid(deviceInfo.dbcc_classguid);
             Guid monitorInterfaceGuid = new Guid("E6F07B5F-EE97-4a90-B076-33F57BF4EAA7");
             if (deviceGuid.Equals(monitorInterfaceGuid))
                 _monitorManager.UpdateMonitors(null);
         }
     }
     catch (Win32Exception ex)
     {
         MessageBox.Show(ex.Message, ex.ErrorCode.ToString());
     }
 }
 public static DeviceDetector GetInstance(Window window = null)
 {
     if (_deviceDetector == null)
         _deviceDetector = new DeviceDetector();
     return _deviceDetector;
 }