public static extern bool EnumDisplayDevices(string lpDevice, uint ideviceIndex, ref DisplayDevice lpdevice, uint dwFlags);
/// <summary> /// /// </summary> private static void UnloadDriver() { unmapSharedBuffers(); var deviceMode = new DeviceMode(); deviceMode.dmSize = (short)Marshal.SizeOf(typeof(DeviceMode)); deviceMode.dmDriverExtra = 0; deviceMode.dmFields = (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_POSITION); var device = new DisplayDevice(); device.CallBack = Marshal.SizeOf(device); deviceMode.dmDeviceName = string.Empty; uint deviceIndex = 0; while (NativeMethods.EnumDisplayDevices(null, deviceIndex, ref device, 0)) { if (device.DeviceString.Equals(driverName)) break; deviceIndex++; } Debug.Assert(_registryKey != null); _registryKey.SetValue("Attach.ToDesktop", 0); _registryKey.Close(); deviceMode.dmDeviceName = driverMiniportName; if (deviceMode.dmBitsPerPel == 24) deviceMode.dmBitsPerPel = 32; try { SafeChangeDisplaySettingsEx(device.DeviceName, ref deviceMode, IntPtr.Zero, CDS_UPDATEREGISTRY, IntPtr.Zero); SafeChangeDisplaySettingsEx(device.DeviceName, ref deviceMode, IntPtr.Zero, 0, IntPtr.Zero); } catch { } }
/// <summary> /// /// </summary> private static void LoadDriver() { 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; if ((_bitmapBpp = deviceMode.dmBitsPerPel) != 32) throw new Exception("Unsupported bitmap format"); 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; bool deviceFound; uint deviceIndex = 0; String drivers = ""; while (deviceFound = NativeMethods.EnumDisplayDevices(null, deviceIndex, ref device, 0)) { // Trace.WriteLine("DEBUG: Found display driver: " + device.DeviceString + " " + device.DeviceName); if (device.DeviceString == driverName) break; drivers = drivers + " " + device.DeviceString; deviceIndex++; } if (!deviceFound) { // MessageBox.Show("The appropriate mirror driver is not loaded. Only found " + drivers, "FATAL"); throw new Exception("Mirror driver not loaded"); } driverInstanceName = device.DeviceName; const string driverRegistryPath = "SYSTEM\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services"; _registryKey = Registry.LocalMachine.OpenSubKey(driverRegistryPath, true); if (_registryKey != null) { _registryKey = _registryKey.CreateSubKey(driverMiniportName); if (_registryKey != null) _registryKey = _registryKey.CreateSubKey(driverDeviceNumber); else throw new Exception("Couldn't open registry key"); } else throw new Exception("Couldn't open registry key"); // _registryKey.SetValue("Cap.DfbBackingMode", 0); // _registryKey.SetValue("Order.BltCopyBits.Enabled", 1); _registryKey.SetValue("Cap.DfbBackingMode", 3); _registryKey.SetValue("Screen.ForcedBpp", 32); _registryKey.SetValue("Pointer.Enabled", 1); _registryKey.SetValue("Attach.ToDesktop", 1); try { SafeChangeDisplaySettingsEx(device.DeviceName, ref deviceMode, IntPtr.Zero, CDS_UPDATEREGISTRY, IntPtr.Zero); SafeChangeDisplaySettingsEx(device.DeviceName, ref deviceMode, IntPtr.Zero, 0, IntPtr.Zero); } catch { } try { if (!mapSharedBuffers()) throw new InvalidOperationException("mapSharedBuffers failed"); } catch { throw new InvalidOperationException("mapSharedBuffers failed."); } }
/// <summary> /// /// </summary> private static void LoadDriver() { 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; } if ((_bitmapBpp = deviceMode.dmBitsPerPel) != 32) { throw new Exception("Unsupported bitmap format"); } 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; bool deviceFound; uint deviceIndex = 0; String drivers = ""; while (deviceFound = NativeMethods.EnumDisplayDevices(null, deviceIndex, ref device, 0)) { // Trace.WriteLine("DEBUG: Found display driver: " + device.DeviceString + " " + device.DeviceName); if (device.DeviceString == driverName) { break; } drivers = drivers + " " + device.DeviceString; deviceIndex++; } if (!deviceFound) { // MessageBox.Show("The appropriate mirror driver is not loaded. Only found " + drivers, "FATAL"); throw new Exception("Mirror driver not loaded"); } driverInstanceName = device.DeviceName; const string driverRegistryPath = "SYSTEM\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services"; _registryKey = Registry.LocalMachine.OpenSubKey(driverRegistryPath, true); if (_registryKey != null) { _registryKey = _registryKey.CreateSubKey(driverMiniportName); if (_registryKey != null) { _registryKey = _registryKey.CreateSubKey(driverDeviceNumber); } else { throw new Exception("Couldn't open registry key"); } } else { throw new Exception("Couldn't open registry key"); } // _registryKey.SetValue("Cap.DfbBackingMode", 0); // _registryKey.SetValue("Order.BltCopyBits.Enabled", 1); _registryKey.SetValue("Cap.DfbBackingMode", 3); _registryKey.SetValue("Screen.ForcedBpp", 32); _registryKey.SetValue("Pointer.Enabled", 1); _registryKey.SetValue("Attach.ToDesktop", 1); try { SafeChangeDisplaySettingsEx(device.DeviceName, ref deviceMode, IntPtr.Zero, CDS_UPDATEREGISTRY, IntPtr.Zero); SafeChangeDisplaySettingsEx(device.DeviceName, ref deviceMode, IntPtr.Zero, 0, IntPtr.Zero); } catch { } try { if (!mapSharedBuffers()) { throw new InvalidOperationException("mapSharedBuffers failed"); } } catch { throw new InvalidOperationException("mapSharedBuffers failed."); } }