【问题标题】:Transparent Overlay透明叠加
【发布时间】:2016-05-20 22:41:21
【问题描述】:

我正在尝试制作一个应用程序,它可以在我的屏幕上叠加一个透明图像。我的目标是为没有十字准线的游戏制作十字准线。我的想法是检测活动窗口标题是否与游戏名称匹配,如果匹配则显示覆盖的十字准线。我将如何制作屏幕覆盖?这是我当前的代码:

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

【问题讨论】:

    标签: vb.net overlay


    【解决方案1】:

    此方法适用于大多数游戏,但仅适用于窗口模式!

    1. 在您的表单上放置一个图片框并最大化您的图片框
    2. 禁用您的 Windowboarders:

      Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None

    3. 将透明键设置为黑色。钍

      Me.TransparencyKey = Color.Black

    4. 将背景颜色设置为黑色:

      Me.PictureBox1.BackColor = Color.Black

    5. 将窗口设置为前景:

      Me.TopMost = true

    6. 最大化你的窗口:

      Me.WindowState = FormWindowState.Maximized

    现在您可以在 Timer1_Tick 或 Form1_Paint 事件中在 Picturebox 上绘图。所有不是黑色的东西都将被绘制到您的桌面上。

    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
    

    希望我能帮到你。

    【讨论】:

    • Hej Al-aex!非常感谢! WS_EX_TRANSPARENT 完成了这项工作!我跳过了图片框,并在标签中使用了一个简单的“+”符号作为范围。
    猜你喜欢
    • 2014-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多