Exemple #1
0
        public MonitorInformation GetMonitorInformation(IntPtr hMonitor)
        {
            if (_monitorInfoCache.ContainsKey(hMonitor))
            {
                return(_monitorInfoCache[hMonitor]);
            }

            if (hMonitor == IntPtr.Zero)
            {
                // Get handle to the default monitor
                const int MONITOR_DEFAULTTOPRIMARY = 0x00000001;
                hMonitor = NativeMethods.MonitorFromWindow(IntPtr.Zero, MONITOR_DEFAULTTOPRIMARY);
                if (_monitorInfoCache.ContainsKey(hMonitor))
                {
                    _monitorInfoCache[IntPtr.Zero] = _monitorInfoCache[hMonitor];
                    return(_monitorInfoCache[hMonitor]);
                }
            }

            var monitorInfo = NativeMethods.MONITORINFOEX.New();

            if (!NativeMethods.GetMonitorInfoEx(hMonitor, ref monitorInfo))
            {
                _monitorInfoCache[hMonitor] = null;
                return(null);
            }

            System.Diagnostics.Trace.WriteLine("Monitor:\"" + monitorInfo.deviceName + "\" Handle:" + hMonitor
                                               + " Left:" + monitorInfo.rcMonitor.left + " Top:" + monitorInfo.rcMonitor.top
                                               + " Right:" + monitorInfo.rcMonitor.right + " Bottom:" + monitorInfo.rcMonitor.bottom);

            UInt32 effectiveDPIx, effectiveDPIy;

            //GetDpiForMonitor(hMonitor, MONITOR_DPI_TYPE.MDT_Effective_DPI, out effectiveDPIx, out effectiveDPIy);
            DpiUtilities.GetMonitorEffectiveDpi(hMonitor, out effectiveDPIx, out effectiveDPIy);
            System.Diagnostics.Trace.WriteLine("Effective DPI:" + effectiveDPIx + " " + effectiveDPIy);

            //UInt32 rawDPIx, rawDPIy;
            //GetDpiForMonitor(hMonitor, MONITOR_DPI_TYPE.MDT_Raw_DPI, out rawDPIx, out rawDPIy);
            //System.Diagnostics.Trace.WriteLine("Raw DPI:" + rawDPIx + " " + rawDPIy);

            var monitorInformation = new MonitorInformation()
            {
                deviceName    = monitorInfo.deviceName,
                isPrimary     = (monitorInfo.dwFlags & NativeMethods.MONITORINFOF_PRIMARY) != 0,
                rcMonitor     = monitorInfo.rcMonitor,
                rcWork        = monitorInfo.rcWork,
                scalingFactor = DpiUtilities.GetScreenScalingFactor(monitorInfo.deviceName),
                dpiX          = effectiveDPIx,
                dpiY          = effectiveDPIy,
            };

            _monitorInfoCache[hMonitor] = monitorInformation;
            if (monitorInformation.isPrimary && !_monitorInfoCache.ContainsKey(IntPtr.Zero))
            {
                _monitorInfoCache[IntPtr.Zero] = monitorInformation;
            }
            return(monitorInformation);
        }
Exemple #2
0
        public void Setup()
        {
            websiteTester = new WebsiteTester(new HashSet <string>());
            ipMonitor     = new IPMonitor(websiteTester);
            ipMonitor.UpdateWebsitesAction += (websites) => { };
            string temp;

            ipMonitor.UpdateIPFieldAction += (temp) => { };
            ipMonitor.SetWebsites(new HashSet <string>());
            vpnMonitor = new VPN_Stability_Monitor(ipMonitor);
            mi         = new MonitorInformation("47.144.17.23", "192.168.0.112", "192.168.0.812");
            vpnMonitor.UpdateStabilityAction += (websites) => { };
            vpnMonitor.active = true;
        }
Exemple #3
0
        private static bool WmGetMinMaxInfo(IntPtr hwnd, IntPtr lparam, Window window)
        {
            MinMaxInformation mmi =
                (MinMaxInformation)Marshal.PtrToStructure(lparam, typeof(MinMaxInformation));
            IntPtr monitor = MonitorFromWindow(hwnd, 2);

            if (monitor == IntPtr.Zero)
            {
                return(false);
            }

            MonitorInformation monitorInformation = new MonitorInformation();

            if (!GetMonitorInfo(monitor, monitorInformation))
            {
                return(false);
            }

            Rectangle workArea    = monitorInformation.rcWork;
            Rectangle monitorArea = monitorInformation.rcMonitor;

            mmi.ptMaxPosition.X = Math.Abs(workArea.Left - monitorArea.Left);
            mmi.ptMaxPosition.Y = Math.Abs(workArea.Top - monitorArea.Top);
            mmi.ptMaxSize.X     = Math.Abs(workArea.Right - workArea.Left);
            mmi.ptMaxSize.Y     = Math.Abs(workArea.Bottom - workArea.Top);

            Point magnification = GetDeviceToLogicalCoefficient(window);

            if (!double.IsInfinity(window.MinWidth) && !double.IsNaN(window.MinWidth))
            {
                mmi.ptMinTrackSize.X = (int)(window.MinWidth * magnification.X);
            }
            if (!double.IsInfinity(window.MinHeight) && !double.IsNaN(window.MinHeight))
            {
                mmi.ptMinTrackSize.Y = (int)(window.MinHeight * magnification.Y);
            }
            if (!double.IsInfinity(window.MaxWidth) && !double.IsNaN(window.MaxWidth))
            {
                mmi.ptMaxTrackSize.X = (int)(window.MaxWidth * magnification.X);
            }
            if (!double.IsInfinity(window.MaxHeight) && !double.IsNaN(window.MaxHeight))
            {
                mmi.ptMaxTrackSize.Y = (int)(window.MaxHeight * magnification.Y);
            }

            Marshal.StructureToPtr(mmi, lparam, true);
            return(true);
        }
Exemple #4
0
        public MainWindow()
        {
            InitializeComponent();

            DockPosition.ItemsSource = new[]
            {
                AppBarDockMode.Left,
                AppBarDockMode.Right,
                AppBarDockMode.Top,
                AppBarDockMode.Bottom
            };
            DockMonitor.ItemsSource  = MonitorInformation.GetAllMonitors();
            DockMonitor.SelectedItem = MonitorInformation.GetAllMonitors().Where(m => m.IsPrimary).FirstOrDefault();

            AppMenu.Background  = SystemColors.ActiveBorderBrush;
            AppMenuName.Content = this.Title;
        }
 public static extern bool GetMonitorInfo(IntPtr hWnd, ref MonitorInformation info);
  /// <summary>
  /// 
  /// </summary>
  /// <param name="msg"></param>
  private void OnDisplayChange(ref Message msg)
  {
    Log.Debug("Main: WM_DISPLAYCHANGE");
    if (VMR9Util.g_vmr9 != null && GUIGraphicsContext.Vmr9Active && GUIGraphicsContext.IsEvr)
    {
      VMR9Util.g_vmr9.UpdateEVRDisplayFPS(); // Update FPS
    }
    Screen screen = Screen.FromControl(this);
    Rectangle currentBounds = GUIGraphicsContext.currentScreen.Bounds;
    Rectangle newBounds = screen.Bounds;
    if (Created && !Equals(screen, GUIGraphicsContext.currentScreen) || !Equals(currentBounds.Size, newBounds.Size))
    {
      Log.Info("Main: Screen MP OnDisplayChange is displayed on changed from {0} to {1}", GetCleanDisplayName(GUIGraphicsContext.currentScreen), GetCleanDisplayName(screen));
      if (screen.Bounds != GUIGraphicsContext.currentScreen.Bounds)
      {
        Log.Info("Main: OnDisplayChange Bounds of display changed from {0}x{1} to {2}x{3}", currentBounds.Width, currentBounds.Height, newBounds.Width, newBounds.Height);
      }
      if (!Equals(currentBounds.Size, newBounds.Size))
      {
        // Check if start screen is equal to device screen and check if current screen bond differ from current detected screen bond then recreate swap chain.
        Log.Debug("Main: Screen MP OnDisplayChange current screen detected                                {0}", GetCleanDisplayName(screen));
        Log.Debug("Main: Screen MP OnDisplayChange current screen                                         {0}", GetCleanDisplayName(GUIGraphicsContext.currentScreen));
        Log.Debug("Main: Screen MP OnDisplayChange start screen                                           {0}", GetCleanDisplayName(GUIGraphicsContext.currentStartScreen));
        Log.Debug("Main: Screen MP OnDisplayChange change current screen {0} with current detected screen {1}", GetCleanDisplayName(GUIGraphicsContext.currentScreen), GetCleanDisplayName(screen));
        GUIGraphicsContext.currentScreen = screen;
        Log.Debug("Main: Screen MP OnDisplayChange set current detected screen bounds : {0} to previous bounds values : {1}", GUIGraphicsContext.currentScreen.Bounds, Bounds);
        Bounds = screen.Bounds;
        Log.Debug("Main: Screen MP OnDisplayChange recreate swap chain");
        NeedRecreateSwapChain = true;
        RecreateSwapChain();
        _changeScreenDisplayChange = true;
      }
      // Restore original Start Screen in case of change from RDP Session
      if (!Equals(screen, GUIGraphicsContext.currentStartScreen))
      {
        foreach (GraphicsAdapterInfo adapterInfo in _enumerationSettings.AdapterInfoList)
        {
          var hMon = Manager.GetAdapterMonitor(adapterInfo.AdapterOrdinal);
          var info = new MonitorInformation();
          info.Size = (uint)Marshal.SizeOf(info);
          GetMonitorInfo(hMon, ref info);
          var rect = Screen.FromRectangle(info.MonitorRectangle).Bounds;
          if (Equals(Manager.Adapters[GUIGraphicsContext.DX9Device.DeviceCaps.AdapterOrdinal].Information.DeviceName, GetCleanDisplayName(GUIGraphicsContext.currentStartScreen)) && rect.Equals(screen.Bounds))
          {
            GUIGraphicsContext.currentScreen = GUIGraphicsContext.currentStartScreen;
            break;
          }
          GUIGraphicsContext.currentScreen = screen;
          Log.Debug("Main: Screen MP OnDisplayChange restore screen");
        }
      }
    }

    if (!Windowed)
    {
      SetBounds(GUIGraphicsContext.currentScreen.Bounds.X, GUIGraphicsContext.currentScreen.Bounds.Y, GUIGraphicsContext.currentScreen.Bounds.Width, GUIGraphicsContext.currentScreen.Bounds.Height);
    }

    // needed to avoid cursor show when MP windows change (for ex when refesh rate is working)
    _moveMouseCursorPositionRefresh = D3D._lastCursorPosition;

    msg.Result = (IntPtr)1;
  }
Exemple #7
0
    /// <summary>
    /// Finds the adapter that has the specified screen on its primary monitor
    /// </summary>
    /// <returns>The adapter that has the specified screen on its primary monitor</returns>
    private GraphicsAdapterInfo FindAdapterForScreen(Screen screen)
    {
      foreach (GraphicsAdapterInfo adapterInfo in _enumerationSettings.AdapterInfoList)
      {
        var hMon = Manager.GetAdapterMonitor(adapterInfo.AdapterOrdinal);

        var info = new MonitorInformation();
        info.Size = (uint)Marshal.SizeOf(info);
        GetMonitorInfo(hMon, ref info);
        var rect = Screen.FromRectangle(info.MonitorRectangle).Bounds;
        if (rect.Equals(screen.Bounds))
        {
          Log.Debug("D3D: FindAdapterForScreen Adapter #{0}: {1} - Driver: {2} ({3}) - DeviceName: {4}",
          adapterInfo.AdapterOrdinal, adapterInfo.AdapterDetails.Description, adapterInfo.AdapterDetails.DriverName, adapterInfo.AdapterDetails.DriverVersion, adapterInfo.AdapterDetails.DeviceName);
          GUIGraphicsContext.currentStartScreen = GUIGraphicsContext.currentScreen;
          return adapterInfo;
        }
      }
      return null;
    }
Exemple #8
0
    /// <summary>
    /// Finds the adapter that has the specified screen on its primary monitor
    /// </summary>
    /// <returns>The adapter that has the specified screen on its primary monitor</returns>
    private GraphicsAdapterInfo FindAdapterForScreen(Screen screen)
    {
      foreach (GraphicsAdapterInfo adapterInfo in _enumerationSettings.AdapterInfoList)
      {
        var hMon = Manager.GetAdapterMonitor(adapterInfo.AdapterOrdinal);

        var info = new MonitorInformation();
        info.Size = (uint)Marshal.SizeOf(info);
        GetMonitorInfo(hMon, ref info);
        var rect = Screen.FromRectangle(info.MonitorRectangle).Bounds;
        if (rect.Equals(screen.Bounds))
        {
          return adapterInfo;
        }
      }
      return null;
    }
Exemple #9
0
 internal static extern bool GetMonitorInfo(IntPtr hMonitor, MonitorInformation lpmi);
Exemple #10
0
  /// <summary>
  /// 
  /// </summary>
  /// <param name="msg"></param>
  private void OnDeviceChange(ref Message msg)
  {
    Log.Debug("Main: WM_DEVICECHANGE (Event: {0})", Enum.GetName(typeof(DBT_EVENT), msg.WParam.ToInt32()));
    RemovableDriveHelper.HandleDeviceChangedMessage(msg);

    // process additional data if available
    if (msg.LParam.ToInt32() != 0)
    {
      var hdr = (DEV_BROADCAST_HDR)Marshal.PtrToStructure(msg.LParam, typeof(DEV_BROADCAST_HDR));
      if (hdr.dbcc_devicetype != DBT_DEVTYP_DEVICEINTERFACE)
      {
        Log.Debug("Main: Device type is {0}", Enum.GetName(typeof(DBT_DEV_TYPE), hdr.dbcc_devicetype));        
      }
      else
      {
        var deviceInterface = (DEV_BROADCAST_DEVICEINTERFACE)Marshal.PtrToStructure(msg.LParam, typeof(DEV_BROADCAST_DEVICEINTERFACE));

        // get friendly device name
        string deviceName = String.Empty;
        string[] values = deviceInterface.dbcc_name.Split('#');
        if (values.Length >= 3)
        {
          string deviceType = values[0].Substring(values[0].IndexOf(@"?\", StringComparison.Ordinal) + 2);
          string deviceInstanceID = values[1];
          string deviceUniqueID = values[2];
          string regPath = @"SYSTEM\CurrentControlSet\Enum\" + deviceType + "\\" + deviceInstanceID + "\\" + deviceUniqueID;
          RegistryKey regKey = Registry.LocalMachine.OpenSubKey(regPath);
          if (regKey != null)
          {
            // use the friendly name if it exists
            object result = regKey.GetValue("FriendlyName");
            if (result != null)
            {
              deviceName = result.ToString();
            }
              // if not use the device description's last part
            else
            {
              result = regKey.GetValue("DeviceDesc");
              if (result != null)
              {
                deviceName = result.ToString().Contains(@"%;") ? result.ToString().Substring(result.ToString().IndexOf(@"%;", StringComparison.Ordinal) + 2) : result.ToString();
              }
            }
          }
        }
        Log.Debug("Main: Device type is {0} - Name: {1}", Enum.GetName(typeof(DBT_DEV_TYPE), hdr.dbcc_devicetype), deviceName);

        // special chanding for audio renderer
        if (deviceInterface.dbcc_classguid == KSCATEGORY_VIDEO || deviceInterface.dbcc_classguid == KSCATEGORY_SCREEN)
        {
          switch (msg.WParam.ToInt32())
          {
            case DBT_DEVICEREMOVECOMPLETE:
              Log.Info("Main: Video Device or Screen {0} removed", deviceName);
              try
              {
                GUIGraphicsContext.DeviceVideoConnected--;
              }
              catch (Exception exception)
              {
                Log.Warn("Main: Exception on removal Video Device or Screen {0} exception: {1} ", deviceName, exception.Message);
              }
              break;

            case DBT_DEVICEARRIVAL:
              Log.Info("Main: Video Device or Screen {0} connected", deviceName);
              try
              {
                GUIGraphicsContext.DeviceVideoConnected++;
                if (!_keepstartfullscreen)
                {
                  OnDisplayChange(ref msg);
                }
                else
                {
                  // Restore original Start Screen in case of change from RDP Session
                  Screen screen = Screen.FromControl(this);
                  if (!Equals(screen, GUIGraphicsContext.currentStartScreen))
                  {
                    foreach (GraphicsAdapterInfo adapterInfo in _enumerationSettings.AdapterInfoList)
                    {
                      var hMon = Manager.GetAdapterMonitor(adapterInfo.AdapterOrdinal);
                      var info = new MonitorInformation();
                      info.Size = (uint) Marshal.SizeOf(info);
                      GetMonitorInfo(hMon, ref info);
                      var rect = Screen.FromRectangle(info.MonitorRectangle).Bounds;
                      if (
                        Equals(
                          Manager.Adapters[GUIGraphicsContext.DX9Device.DeviceCaps.AdapterOrdinal].Information
                            .DeviceName,
                          GetCleanDisplayName(GUIGraphicsContext.currentStartScreen)) && rect.Equals(screen.Bounds))
                      {
                        GUIGraphicsContext.currentScreen = GUIGraphicsContext.currentStartScreen;
                        Log.Debug("Main: Video Device or Screen restore screen : {0}", GUIGraphicsContext.currentScreen);
                        break;
                      }
                      GUIGraphicsContext.currentScreen = screen;
                      Log.Debug("Main: Video Device or Screen restore screen");
                    }
                  }
                  if (!Windowed)
                  {
                    SetBounds(GUIGraphicsContext.currentStartScreen.Bounds.X, GUIGraphicsContext.currentStartScreen.Bounds.Y,
                      GUIGraphicsContext.currentStartScreen.Bounds.Width, GUIGraphicsContext.currentStartScreen.Bounds.Height);
                    Log.Debug(
                      "Main: Video Device or Screen restore screen bounds of display changed to {0}x{1}",
                      GUIGraphicsContext.currentStartScreen.Bounds.Width, GUIGraphicsContext.currentStartScreen.Bounds.Height);
                  }
                }
              }
              catch (Exception exception)
              {
                Log.Warn("Main: Exception on arrival Video Device {0} exception: {1} ", deviceName, exception.Message);
              }
              break;
          }
        }

        // special chanding for audio renderer
        if (deviceInterface.dbcc_classguid == KSCATEGORY_RENDER || deviceInterface.dbcc_classguid == RDP_REMOTE_AUDIO || deviceInterface.dbcc_classguid == KSCATEGORY_AUDIO)
        {
          switch (msg.WParam.ToInt32())
          {
            case DBT_DEVICEREMOVECOMPLETE:
              Log.Info("Main: Audio Renderer {0} removed", deviceName);
              try
              {
                GUIGraphicsContext.DeviceAudioConnected--;
                if (_stopOnLostAudioRenderer)
                {
                  g_Player.Stop();
                  while (GUIGraphicsContext.IsPlaying)
                  {
                    Thread.Sleep(100);
                  }
                }
              }
              catch (Exception exception)
              {
                Log.Warn("Main: Exception on removal Audio Renderer {0} exception: {1} ",deviceName, exception.Message);
              }
              break;

            case DBT_DEVICEARRIVAL:
              Log.Info("Main: Audio Renderer {0} connected", deviceName);
              try
              {
                GUIGraphicsContext.DeviceAudioConnected++;
                if (_stopOnLostAudioRenderer)
                {
                  g_Player.Stop();
                  while (GUIGraphicsContext.IsPlaying)
                  {
                    Thread.Sleep(100);
                  }
                }
                // Asynchronously pre-initialize the music engine if we're using the BassMusicPlayer
                if (BassMusicPlayer.IsDefaultMusicPlayer)
                {
                  BassMusicPlayer.FreeBass();
                  BassMusicPlayer.CreatePlayerAsync();
                }
              }
              catch (Exception exception)
              {
                Log.Warn("Main: Exception on arrival Audio Renderer {0} exception: {1} ", deviceName, exception.Message);
              }
              break;
          }
        }
      }
    }
    msg.Result = (IntPtr)1;
  }
 public static extern bool GetMonitorInfo(IntPtr hWnd, ref MonitorInformation info);
  /// <summary>
  /// 
  /// </summary>
  /// <param name="msg"></param>
  private void OnDisplayChange(ref Message msg)
  {
    if (_suspended)
    {
      return;
    }

    Log.Debug("Main: WM_DISPLAYCHANGE");

    // Workaround HDMI hot-plug problems by not adjusting the form size if the screen is not its actual size.
    Screen screen = Screen.FromControl(this);
    if (!Windowed && Equals(screen.Bounds.Size, WINDOWS_NATIVE_RESOLUTION) && !Equals(screen.Bounds.Size, _backupBounds.Size))
    {
      Log.Debug("Main: Ignore spurious WM_DISPLAYCHANGE for Windows native resolution");
      return;
    }

    // disable event handlers
    if (GUIGraphicsContext.DX9Device != null)
    {
      GUIGraphicsContext.DX9Device.DeviceLost -= OnDeviceLost;
    }

    if (VMR9Util.g_vmr9 != null && GUIGraphicsContext.Vmr9Active &&
        GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.EVR)
    {
      VMR9Util.g_vmr9.UpdateEVRDisplayFPS(); // Update FPS
    }
    Rectangle currentBounds = GUIGraphicsContext.currentScreen.Bounds;
    Rectangle newBounds = screen.Bounds;
    if (Created && !Equals(screen, GUIGraphicsContext.currentScreen) || !Equals(currentBounds.Size, newBounds.Size) || !Equals(screen, GUIGraphicsContext.currentStartScreen))
    {
      Log.Info("Main: Screen MP OnDisplayChange is displayed on changed from {0} to {1}", GetCleanDisplayName(GUIGraphicsContext.currentScreen), GetCleanDisplayName(screen));
      if (screen.Bounds != GUIGraphicsContext.currentScreen.Bounds)
      {
        Log.Info("Main: OnDisplayChange Bounds of display changed from {0}x{1} to {2}x{3}", currentBounds.Width, currentBounds.Height, newBounds.Width, newBounds.Height);
      }
      if (!Equals(currentBounds.Size, newBounds.Size))
      {
        // Check if start screen is equal to device screen and check if current screen bond differ from current detected screen bond then recreate swap chain.
        Log.Debug("Main: Screen MP OnDisplayChange current screen detected                                {0}", GetCleanDisplayName(screen));
        Log.Debug("Main: Screen MP OnDisplayChange current screen                                         {0}", GetCleanDisplayName(GUIGraphicsContext.currentScreen));
        Log.Debug("Main: Screen MP OnDisplayChange start screen                                           {0}", GetCleanDisplayName(GUIGraphicsContext.currentStartScreen));
        Log.Debug("Main: Screen MP OnDisplayChange change current screen {0} with current detected screen {1}", GetCleanDisplayName(GUIGraphicsContext.currentScreen), GetCleanDisplayName(screen));
        GUIGraphicsContext.currentScreen = screen;
        Log.Debug("Main: Screen MP OnDisplayChange set current detected screen bounds : {0} to previous bounds values : {1}", GUIGraphicsContext.currentScreen.Bounds, Bounds);
        Bounds = screen.Bounds;
        Log.Debug("Main: Screen MP OnDisplayChange recreate swap chain");
        NeedRecreateSwapChain = true;
        RecreateSwapChain(false);
        _changeScreenDisplayChange = true;
      }
      // Restore original Start Screen in case of change from RDP Session
      if (!Equals(screen, GUIGraphicsContext.currentStartScreen))
      {
        foreach (GraphicsAdapterInfo adapterInfo in _enumerationSettings.AdapterInfoList)
        {
          var hMon = Manager.GetAdapterMonitor(adapterInfo.AdapterOrdinal);
          var info = new MonitorInformation();
          info.Size = (uint)Marshal.SizeOf(info);
          GetMonitorInfo(hMon, ref info);
          var rect = Screen.FromRectangle(info.MonitorRectangle).Bounds;
          if (Equals(Manager.Adapters[GUIGraphicsContext.DX9Device.DeviceCaps.AdapterOrdinal].Information.DeviceName, GetCleanDisplayName(GUIGraphicsContext.currentStartScreen)) && rect.Equals(screen.Bounds))
          {
            GUIGraphicsContext.currentScreen = GUIGraphicsContext.currentStartScreen;
            break;
          }
          GUIGraphicsContext.currentScreen = screen;
          Log.Debug("Main: Screen MP OnDisplayChange restore screen");
        }
      }
    }

    if (!Windowed)
    {
      SetBounds(GUIGraphicsContext.currentScreen.Bounds.X, GUIGraphicsContext.currentScreen.Bounds.Y, GUIGraphicsContext.currentScreen.Bounds.Width, GUIGraphicsContext.currentScreen.Bounds.Height);
    }

    // needed to avoid cursor show when MP windows change (for ex when refesh rate is working)
    _moveMouseCursorPositionRefresh = D3D._lastCursorPosition;

    msg.Result = (IntPtr)1;

    // enable event handlers
    if (GUIGraphicsContext.DX9Device != null)
    {
      GUIGraphicsContext.DX9Device.DeviceLost += OnDeviceLost;
    }
  }