-
January 22nd, 2008, 06:00 PM
#1
FindWindowEx
FindWindowEx retrieves the handle to a window whose class name and/or window name match the specified strings. The function searches child windows, beginning with the one following the given child window.
Code:
Const HWND_DESKTOP As Int32 = 0
Public Declare Function apiFindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Text = "Form1"
'Get handle by window title. You can specify the class name too.
Dim hwnd As Int32 = apiFindWindowEx(HWND_DESKTOP, 0, Nothing, "Form1")
Me.Text = "Handle by title: " & hwnd
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Text = "Form1"
'Get handle by window class name.
Dim hwnd As Int32 = apiFindWindowEx(HWND_DESKTOP, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
Me.Text = "Handle by class name: " & hwnd
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Text = "Form1"
'Get handles of all sibling windows that have the same parent(Desktop window).
Dim hwnd As Int32 = HWND_DESKTOP
Dim cwnd As Int32 = 0
Do
cwnd = apiFindWindowEx(hwnd, cwnd, Nothing, Nothing)
If cwnd = 0 Then Exit Do
Me.Text = "Top level sibling handle: " & cwnd
System.Threading.Thread.Sleep(1) 'Give a chance to see the new handle
Loop
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Text = "Form1"
' Get child window by window title. You can specify the class name too.
Dim hwnd As Int32 = apiFindWindowEx(HWND_DESKTOP, 0, Nothing, "Form1")
Dim cwnd As Int32 = apiFindWindowEx(hwnd, 0, Nothing, "Button1")
Me.Text = "Child handle by title: " & cwnd
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Me.Text = "Form1"
'Get handle of all sibling child windows that have the same parent(Top-level window).
Dim hwnd As Int32 = apiFindWindowEx(HWND_DESKTOP, 0, Nothing, "Form1")
Dim cwnd As Int32 = 0
Do
cwnd = apiFindWindowEx(hwnd, cwnd, Nothing, Nothing)
If cwnd = 0 Then Exit Do
Me.Text = "Child sibling handle: " & cwnd
System.Threading.Thread.Sleep(200) 'Give a chance to see the new handle.
Loop
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|