‘-– Find the PID of the Application that Owns the Window -– GetWindowText(hWnd, WindowTitle, TitleLength + 1) ‘-– Find the Length of the Window’s Title -–ĭim WindowTitle As String = StrDup(TitleLength + 1, "*") ‘-– Get the Handle to the Current Forground Window -–ĭim hWnd As IntPtr = GetForegroundWindow() Private Sub timerActiveWindowCheck_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerActiveWindowCheck.Tick Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Integer Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As IntPtr, ByVal WinTitle As String, ByVal MaxLength As Integer) As Integer Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As IntPtr, ByRef lpdwProcessID As Integer) As Integer Private Declare Function GetForegroundWindow Lib "user32.dll" () As IntPtr It detects the name of the form, the name of the app, the name of the process id. But I spent time on it so hopefully it will help you too. The funny thing was I ended up not using it because I went with a simpler solution of using a boolean that was assigned as true if the form was opened then to false when closed. For a particular assignment I had at GE, it was required to determine if a particular form was already open and if so prevent that form from being opened again.
0 Comments
Leave a Reply. |