console find windows

Holmono

New member
Joined
Feb 13, 2012
Messages
1
Programming Experience
Beginner
hwo can I make this work?

HTML:
Module Module1

    Sub Main()

        If (FindWindow("Notepad") = True) Then
            System.Console.WriteLine("Fount window")

        Else
            System.Console.WriteLine("No window found")

        End If

        System.Console.Write("Press enter to continue...")
        System.Console.ReadLine()

    End Sub

End Module

I get this error:
Error 1 'FindWindow' is not declared. It may be inaccessible due to its protection level. C:\Users\John\AppData\Local\Temporary Projects\ConsoleApplication1\Module1.vb 5 13 ConsoleApplication1
 
You have to declare the function. The VB.Net version takes two parameters (which as you can see is a bit of a nuisance in the case of Notepad!)


Module Module1
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr


Sub Main()




If FindWindow("Notepad", "Untitled - Notepad") Then
System.Console.WriteLine("Found window")


Else
System.Console.WriteLine("No window found")


End If


System.Console.Write("Press enter to continue...")
System.Console.ReadLine()
End Sub


End Module
 
Back
Top