|
-
Aug 1st, 2016, 09:50 AM
#8
Re: FindWindow function to find Google Chrome personal user's windows.
 Originally Posted by abhishek009
Can you tell me the exact method ? I mean I'm really confused. Otherwise I have to close all window and run one by one and close them after completing the task and re open whenever required. :/
You can try this, should get the window handle and caption text for the active tab in each open Chrome, tested on Win7 only,...
Code:
Imports System.Text
Imports System.Runtime.InteropServices
Public Class Form1
Private chromeWindows As New Dictionary(Of IntPtr, String)
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
chromeWindows.Clear() ' clear dic.
EnumWindows(AddressOf ClassesByName, IntPtr.Zero) ' enum windows w/classname "Chrome_WidgetWin_1".
' display contents
If chromeWindows.Count = 0 Then
MessageBox.Show("None found, list is empty!")
Else ' do something with the results,...
For Each chrome In chromeWindows
Debug.WriteLine("hWnd={0}, Title={1}", chrome.Key, chrome.Value)
Next
End If
End Sub
' Helper/API Funcs...
Private Function ClassesByName(ByVal hWnd As IntPtr, ByVal lParam As IntPtr) As Boolean
If ClassName(hWnd) = "Chrome_WidgetWin_1" Then 'Google Chrome main window class name.
Dim capText As New StringBuilder(255) ' get title bar txt/caption text
If GetWindowText(hWnd, capText, capText.Capacity) > 0 Then ' only add if has text.
chromeWindows.Add(hWnd, capText.ToString) ' add window handle and caption text to dic.
End If
End If
Return True
End Function
Private Function ClassName(ByVal hWnd As IntPtr) As String
Dim sbClassName As New StringBuilder(256)
GetClassName(hWnd, sbClassName, 256)
Return sbClassName.ToString
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As StringBuilder, ByVal cch As Integer) As Integer
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function GetClassName(ByVal hWnd As IntPtr, ByVal lpClassName As StringBuilder, ByVal nMaxCount As Integer) As Integer
End Function
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As EnumWindowsProcDelegate, ByVal lParam As IntPtr) As Boolean
Private Delegate Function EnumWindowsProcDelegate(ByVal hWnd As IntPtr, ByVal lParam As IntPtr) As Boolean
End Class
You may also want to take a look into UI Automation, don't use it myself but fwiw found one example here,
http://www.bluelightdev.com/get-list-open-chrome-tabs
Last edited by Edgemeal; Aug 1st, 2016 at 10:19 AM.
Reason: minor: shorten variable name.
Tags for this Thread
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
|