Results 1 to 2 of 2

Thread: console find windows

  1. #1
    Holmono is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2012
    Posts
    1
    Reputation
    0

    console find windows

    hwo can I make this work?

    HTML Code:
    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

  2. #2
    Dunfiddlin's Avatar
    Dunfiddlin is offline VB.NET Forum Master
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    253
    Reputation
    31
    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking