2010-11-16 75 views
3

有谁知道在保持主显示屏全亮的同时使辅助监视器变暗的编程方式吗?我调查了一些现有的软件,但大多数只会调暗所有显示器(或仅显示主显示器)。我觉得这可能是一个Windows注册表修改。 (这将用于Windows 7平台)即使有人可以指向我可以修改屏幕亮度级别的注册表项。我认为这是在操作系统中处理的,并不总是在显示器本身。调光辅助监视器

任何和所有的帮助,非常感谢!

回答

1

http://msdn.microsoft.com/en-us/library/ms775240.aspx

使用SetMonitorBrightness API。

+0

我之前没有使用过很多微软API。你有可能为了它的工作方式而插入一小段代码或伪代码吗?我将不胜感激! (只要我想出如何使用它编写快速程序,这可能会被标记为答案) – 2011-01-26 17:46:59

0

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

+0

我还没有选择工具包。我很乐意使用任何东西(但我想要一个基于软件的解决方案) – 2010-11-27 05:44:27

0

本施特劳布和我有同样的想法。我用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