【问题标题】:Emulating clicks behind form模拟表单背后的点击
【发布时间】:2014-03-21 17:38:45
【问题描述】:

这篇文章与 Visual Basic .NET 2010 相关

我有几个问题要问你。我想枚举使用表单的 BackgroundImage 属性显示的位图中的每个像素,然后如果当前像素为黑色,我想模拟表单后面的单击。那么,我应该/我该怎么做呢?

例如(这里有一些伪代码):

For Each P As Pixel In Form1.BackgroundImage
    If P.Color = Color.Black Then
        EmulateClickBehindForm(P.Position)
    End If
Next

我的表单目前如下所示:

非常感谢您的帮助。

【问题讨论】:

    标签: vb.net bitmap pixel


    【解决方案1】:

    试试这样的:

    For Each P As Pixel In Form1.BackgroundImage
        If P.Color = Color.Black Then
            Dim sender As Object = Me
            Dim e As New MouseEventArgs(Windows.Forms.MouseButtons.Left, 1, P.Position.X, P.Position.Y, 0)
            Form_Click(sender, e)
        End If
    Next
    

    【讨论】:

    • 除非我需要真正的 Visual Basic 代码或真正了解我应该如何做而不是伪代码。我提供它的原因是为了更好地向那些编程的人解释。此外,应该点击的不是我的表单,而是它背后/下方的窗口。
    • 为了能够将 mouse 事件发送到表单后面的 whatever,您需要依靠 WinAPI 调用和挂钩来捕获鼠标的内容正在做你的形式。这不是一件小事。相信我,我做到了,这并不容易。如果你能更好地解释你想做什么我们也许能提供一些更合适的信息。
    • 我想重绘表格后面表面上的所有黑色像素。
    【解决方案2】:

    这样解决了:

            Dim Bmp As New Bitmap(Me.BackgroundImage)
            Dim Pos As New Point(Me.Location)
            Dim BmpSize As New Bitmap(Bmp.Width, Bmp.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb)
            For y As Integer = 0 To BmpSize.Height - 1
                For x = 0 To BmpSize.Width - 1
                    Dim curPixColor As Color = Bmp.GetPixel(x, y)
                    If curPixColor = Color.White Then Continue For
                    If IsColorBlack(curPixColor) Then
                        Dim pre = New Point(Pos.X + x, Pos.Y + y)
                        SetCursorPos(pre.X, pre.Y)
                        Application.DoEvents()
                        Threading.Thread.Sleep(50)
                        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
                        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
                    End If
                Next
            Next
    

    一些解释:

    我枚举背景图像中的像素,对于每个类似于黑色的像素,我让鼠标在屏幕上单击,在窗体的位置+像素的位置。

    真的很简单,这里有一些伪代码来阐明这个过程:

    For each P As Pixel In Form1.BackgroundImage
        If P.Color = Color.Black Then
            Click(Form1.Location.X + P.Location.X, Form1.Location.Y + P.Location.Y)
        End If
    Next
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-26
      • 2021-01-04
      • 2018-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多