Пример #1
0
 private static extern bool EnumDisplayDevices(string lpDevice, uint ideviceIndex, ref DisplayDevice lpdevice, uint dwFlags);
Пример #2
0
        // List<string> logger = new List<string>();
        public bool Load()
        {
            if (State != MirrorState.Idle)
            {
                Debug.WriteLine("Invalid Operation Exception Thrown at Load");
                throw new InvalidOperationException("You may call Load only if the state is Idle");
            }

            var device     = new DisplayDevice();
            var deviceMode = new DeviceMode {
                dmDriverExtra = 0
            };

            device.CallBack         = Marshal.SizeOf(device);
            deviceMode.dmSize       = (short)Marshal.SizeOf(deviceMode);
            deviceMode.dmBitsPerPel = Screen.PrimaryScreen.BitsPerPixel;

            if (deviceMode.dmBitsPerPel == 24)
            {
                deviceMode.dmBitsPerPel = 32;
            }

            _bitmapBpp = deviceMode.dmBitsPerPel;

            deviceMode.dmDeviceName = string.Empty;
            deviceMode.dmFields     = (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_POSITION);
            _bitmapHeight           = deviceMode.dmPelsHeight = Screen.PrimaryScreen.Bounds.Height;
            _bitmapWidth            = deviceMode.dmPelsWidth = Screen.PrimaryScreen.Bounds.Width;


            Debug.WriteLine("Driver Resolution: " + Screen.PrimaryScreen.Bounds);


            bool deviceFound;
            uint deviceIndex = 0;

            while (deviceFound = EnumDisplayDevices(null, deviceIndex, ref device, 0))
            {
                if (device.DeviceString == driverName)
                {
                    break;
                }
                deviceIndex++;
            }

            //if (!deviceFound) return false;

            driverInstanceName = device.DeviceName;

            _registryKey = Registry.LocalMachine.OpenSubKey(driverRegistryPath, true);
            if (_registryKey != null)
            {
                _registryKey = _registryKey.CreateSubKey(driverMiniportName);
            }
            else
            {
                throw new Exception("Couldn't open registry key");
            }

            if (_registryKey != null)
            {
                _registryKey = _registryKey.CreateSubKey(driverDeviceNumber);
            }
            else
            {
                throw new Exception("Couldn't open registry key");
            }

            //			_registryKey.SetValue("Cap.DfbBackingMode", 0);
            //			_registryKey.SetValue("Order.BltCopyBits.Enabled", 1);
            _registryKey.SetValue("Attach.ToDesktop", 1);

            #region This was CommitDisplayChanges

            SafeChangeDisplaySettingsEx(device.DeviceName, ref deviceMode, IntPtr.Zero, CDS_UPDATEREGISTRY, IntPtr.Zero);
            SafeChangeDisplaySettingsEx(device.DeviceName, ref deviceMode, IntPtr.Zero, 0, IntPtr.Zero);

            #endregion

            State = MirrorState.Loaded;

            return(true);
        }