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