代码之家  ›  专栏  ›  技术社区  ›  D.R.

调光辅助监视器

  •  3
  • D.R.  · 技术社区  · 14 年前

    是否有人知道在保持主显示屏完全明亮的同时使辅助显示器变暗的编程方法?我已经研究了一些现有的软件,但是大多数只会使所有的监视器变暗(或者只调暗主监视器)。我觉得这可能是对Windows注册表的修改。(这是为Windows7平台)即使有人可以指出我的注册表项,可以修改屏幕亮度水平。我认为这是在操作系统中处理的,并不总是在监视器本身中。

    非常感谢您的任何帮助!

    3 回复  |  直到 14 年前
        1
  •  1
  •   martona    14 年前
        2
  •  0
  •   Ben Straub    14 年前

    这里最好的软件解决方案可能是为每个显示器创建一个无边界、分层的窗口,覆盖整个显示器,并将其背景色设置为50%不透明黑色。如何做到这一点取决于您使用的是哪个工具包:wpf?Win32?QT?

        3
  •  0
  •   Matt Wilko kingecg    14 年前

    本·斯特拉布和我有同样的想法。我用vb.net在Visual Studio 2010中创建了这个,您可以从中开始吗?使用的一些代码来自 Codeproject website

    Imports System.Runtime.InteropServices
    
    
    Public Class Form1
    
    Public Enum GWL As Integer
        ExStyle = -20
    End Enum
    
    Public Enum WS_EX As Integer
        Transparent = &H20
        Layered = &H80000
    End Enum
    
    Public Enum LWA As Integer
        ColorKey = &H1
        Alpha = &H2
    End Enum
    
    <DllImport("user32.dll", EntryPoint:="GetWindowLong")> _
    Public Shared Function GetWindowLong( _
        ByVal hWnd As IntPtr, _
        ByVal nIndex As GWL _
            ) As Integer
    End Function
    
    <DllImport("user32.dll", EntryPoint:="SetWindowLong")> _
    Public Shared Function SetWindowLong( _
        ByVal hWnd As IntPtr, _
        ByVal nIndex As GWL, _
        ByVal dwNewLong As WS_EX _
            ) As Integer
    End Function
    
    <DllImport("user32.dll", _
      EntryPoint:="SetLayeredWindowAttributes")> _
    Public Shared Function SetLayeredWindowAttributes( _
        ByVal hWnd As IntPtr, _
        ByVal crKey As Integer, _
        ByVal alpha As Byte, _
        ByVal dwFlags As LWA _
            ) As Boolean
    End Function
    
    Private _InitialStyle As Integer
    
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        _InitialStyle = GetWindowLong(Me.Handle, GWL.ExStyle)
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        Me.BackColor = Color.Black
        Me.Opacity = 0.1 'Range is 0 (Fully see through) to 1 (Fully opaque)
        Me.TopMost = True
        DimScreenByIndex(1) 'use 0, 1, etc depending on which screen you want to dim
    
        SetWindowLong(Me.Handle, GWL.ExStyle, _InitialStyle Or WS_EX.Layered Or WS_EX.Transparent)
        'Not needed if setting the opacity: SetLayeredWindowAttributes(Me.Handle, 0, 255 * 0.7, LWA.Alpha)
    
    End Sub
    
    Private Sub DimScreenByIndex(ByVal intScn As Integer)
        For intPtr As Integer = Screen.AllScreens.GetLowerBound(0) To Screen.AllScreens.GetUpperBound(0)
            If intPtr = intScn Then
                Me.Top = Screen.AllScreens(intPtr).Bounds.Top
                Me.Left = Screen.AllScreens(intPtr).Bounds.Left
                Me.Height = Screen.AllScreens(intPtr).Bounds.Height()
                Me.Width = Screen.AllScreens(intPtr).Bounds.Width
            End If
        Next
    End Sub
    End Class