我正在尝试制作一个可以在屏幕中间覆盖透明图像的应用程序。我的目标是为没有十字准线的游戏制作十字准线。我的想法是检测活动窗口标题是否与游戏名称匹配,如果是,则显示重叠的十字准线。我如何制作屏幕叠加?这是我目前的代码:
Private Function GetCaption() As String
Dim Caption As New System.Text.StringBuilder(256)
Dim hWnd As IntPtr = GetForegroundWindow()
GetWindowText(hWnd, Caption, Caption.Capacity)
Return Caption.ToString()
End Function
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If GetCaption() = "Game NameOf" Then
'Display Crosshair
End If
End sub
答案 0 :(得分:2)
此方法适用于大多数游戏,但仅适用于 windowmode!
停用您的Windowboarders:
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
将您的transperency键设置为黑色。个
Me.TransparencyKey = Color.Black
将背景颜色设置为黑色:
Me.PictureBox1.BackColor = Color.Black
将窗口设置为前景:
Me.TopMost = true
最大化您的窗口:
Me.WindowState = FormWindowState.Maximized
现在,您可以在Timer1_Tick或Form1_Paint事件中绘制Picturebox。非Black的所有内容都将被绘制到您的桌面。
Dim g As = GraphicsPictureBox1.CreateGraphics
...
g.DrawLine(Pens.Red, 10, 10, 200, 200)
重要:强>
要通过窗口传递鼠标和键盘的输入,您必须在.net创建表单时添加WS_EX_TRANSPARENT
标记。这可以通过overriding CreateParams
proterty:
Const WS_EX_TRANSPARENT As Long = &H20
...
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim SecPerm As New SecurityPermission(SecurityPermissionFlag.UnmanagedCode)
SecPerm.Demand()
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or WS_EX_TRANSPARENT
Return cp
End Get
End Property
希望我能帮助你。