FindWindow + GetForegroundWindow comparing VB.NET

Posts 1–3 of 3 · Page 1 of 1
FindWindow + GetForegroundWindow comparing VB.NET
Wusup AVA coders/players,

So I'm trying to see if AVA window is active or not. But for some reason it's not working. I cannot detect exactly what I'm doing wrong.

Import DLL I am using: There are different ways but I'm using this.
Code:
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Function FindWindow( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As String) As IntPtr
    End Function

    <DllImport("user32.dll", SetLastError:=True)> _
    Private Shared Function GetForegroundWindow() As IntPtr
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _
        ByVal childAfter As IntPtr, _
        ByVal lclassName As String, _
        ByVal windowTitle As String) As IntPtr
    End Function
^ I know I don't need the child window, but I just have it there.

This is what I'm trying to do after:
Code:
Dim Trigger As Boolean = GetAsyncKeyState(Keys.LButton)
Dim avaWndw As IntPtr = FindWindow("AVAWindowClass", "Alliance of Valiant Arms")
Dim FGW As IntPtr = GetForegroundWindow()

If avaWndw = FGW Then
    If Trigger = True Then
        'Macro code here.
    End If
End If
Inside the the double If statements, I have my macro code's. Now When AVA is running the macro wont be triggered. However if I comment out the first if statement, then the macro works perfectly fine. Is the way I'm importing the DLL wrong? Or what am I doing wrong?
Quote Originally Posted by jaydeeph View Post
Wusup AVA coders/players,

So I'm trying to see if AVA window is active or not. But for some reason it's not working. I cannot detect exactly what I'm doing wrong.

Import DLL I am using: There are different ways but I'm using this.
Code:
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Function FindWindow( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As String) As IntPtr
    End Function

    <DllImport("user32.dll", SetLastError:=True)> _
    Private Shared Function GetForegroundWindow() As IntPtr
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _
        ByVal childAfter As IntPtr, _
        ByVal lclassName As String, _
        ByVal windowTitle As String) As IntPtr
    End Function
^ I know I don't need the child window, but I just have it there.

This is what I'm trying to do after:
Code:
Dim Trigger As Boolean = GetAsyncKeyState(Keys.LButton)
Dim avaWndw As IntPtr = FindWindow("AVAWindowClass", "Alliance of Valiant Arms")
Dim FGW As IntPtr = GetForegroundWindow()

If avaWndw = FGW Then
    If Trigger = True Then
        'Macro code here.
    End If
End If
Inside the the double If statements, I have my macro code's. Now When AVA is running the macro wont be triggered. However if I comment out the first if statement, then the macro works perfectly fine. Is the way I'm importing the DLL wrong? Or what am I doing wrong?
No, all imports are okay. The problem is the window's class name. When using FindWindow(), you need to input the name of the window class for whatever window you want, since in this case it's AVA, the its' name is "LaunchUnrealUWindowsClient" (You find the class's name using Spy++).
Quote Originally Posted by R3DDOT View Post

No, all imports are okay. The problem is the window's class name. When using FindWindow(), you need to input the name of the window class for whatever window you want, since in this case it's AVA, the its' name is "LaunchUnrealUWindowsClient" (You find the class's name using Spy++).
Thanks @R3DDOT. I see where I was going wrong. And thanks for the Spy++ didn't know about that feature .

Edit: Thanks a lot my friend. Found it and working .
Edit 2: I didn't realise you gave me its' name already. Until I went into Spy++ and then I realised you gave it to me. Haha :P
Posts 1–3 of 3 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us