Imports System.Reflection

Public Class frmProcessCapture
    Public ProcessId As Integer
    Public ProcessName As String
    Public WindowTitle As String

    Private _CurrentProcess As String = String.Empty

    Public Sub New()
        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
    End Sub

    Public Sub New(CurrentProcess As String)
        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        _CurrentProcess = CurrentProcess
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Dim oWindow = ClassWindowAPI.GetWindowInfo()

        If oWindow Is Nothing Then
            Exit Sub
        End If

        Dim oProgramName As String = Assembly.GetEntryAssembly().GetName().Name
        Dim oIsClipboardWatcherWindow = oWindow.ProcessName <> oProgramName
        Dim oIsCorrectProcessName = IIf(_CurrentProcess = String.Empty, True, oWindow.ProcessName = _CurrentProcess)

        txtPID.Text = oWindow.ProcessId
        txtName.Text = oWindow.ProcessName
        txtWindowTitle.Text = oWindow.WindowTitle
        ProcessId = oWindow.ProcessId
        ProcessName = oWindow.ProcessName
        WindowTitle = oWindow.WindowTitle

        If oIsClipboardWatcherWindow And oIsCorrectProcessName Then
            Button1.Enabled = True
            txtName.BackColor = SystemColors.Control
        Else
            Button1.Enabled = False
            txtName.BackColor = Color.LightSalmon
        End If
    End Sub

    Private Sub frmProcessCapture_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
    End Sub
End Class