我正在尝试使用visual studio创建一个Windows窗体应用程序来捕获活动窗口应用程序的屏幕截图。我创建了一个捕获按钮,它捕获表单本身而不是Previous活动窗口。因此,我想切换到之前的活动窗口,并且应该捕获屏幕截图,将其视为当前活动窗口。我对VB比较新。请帮我解决这个问题。
谢谢。答案 0 :(得分:0)
一种方法是防止您的表单获得焦点,从而将“上一个”表单保留为活动的选定表单。
请参阅WS_EX_NOACTIVATE:
使用此样式创建的顶级窗口不会成为 用户点击它时的前景窗口。
Public Class Form1
Private Structure RECT
Public Left As Integer
Public Top As Integer
Public Right As Integer
Public Bottom As Integer
End Structure
Private Const WM_MOVING As Integer = &H216
Private Const WS_EX_NOACTIVATE As Integer = &H8000000
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or WS_EX_NOACTIVATE
Return cp
End Get
End Property
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_MOVING Then
Dim r As RECT = DirectCast(Runtime.InteropServices.Marshal.PtrToStructure(m.LParam, GetType(RECT)), RECT)
Me.Location = New Point(r.Left, r.Top)
End If
MyBase.WndProc(m)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Console.WriteLine("...your active screen capture code here...")
End Sub
End Class