Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27514

VS 2010 What kind of handle does EnumWindows API returns?

$
0
0
Hi All,
I am confused. I have tried to use the EnumWindows API to get the handles to the windows in my computer. When the code runs, I cannot find the handle of an opened window in the list of handles that EnumWindows returned. So now, I would like to know the kind of handles that EnumWindows API returns. Why is the window handle of a window that was opened via Process.Start("NotePad.exe") not listed?

Please, run the code if you can. Check the list and see if the NotePad handle is in it. Then, please, tell me what is wrong with the approach. I am looking to get the proper handle to a window so that I can position the window on a preferred parent. I do not want to use the MainWindowHandle property because some processes such as PDF do not return non-zero main window handle in my computer (Windows 7 Pro SP1, X64).

Code:

Imports System
Imports System.Runtime.InteropServices


Public Delegate Function CallBack(ByVal hwnd As Integer, ByVal lParam As Integer) As Boolean

Public Module EnumReportApp
    Dim cnt As Integer = 0
   
    Declare Function EnumWindows Lib "user32" (ByVal x As CallBack, ByVal y As Integer) As Integer

    Public Sub Main()

        EnumWindows(AddressOf EnumReportApp.Report, 0)

        Dim p As Process = Process.Start("NotePad.exe")
        p.WaitForInputIdle()
        p.Refresh()
        Console.WriteLine()
        Console.WriteLine("The current number of windows is: " & cnt)
        Console.WriteLine()
        Console.WriteLine("NotePad's current handle is: " & p.MainWindowHandle.ToString)
        Console.ReadLine()
    End Sub 'Main

   
    Public Function Report(ByVal hwnd As Integer, ByVal lParam As Integer) As Boolean
        Console.Write("Window handle is: ")
        Console.WriteLine(hwnd)
        cnt = cnt + 1
        Return True
       
    End Function 'Report
End Module 'EnumReportApp


Viewing all articles
Browse latest Browse all 27514

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>