-
Jul 31st, 2016, 11:11 PM
#1
Thread Starter
Banned
[SOLVED] FindWindow function to find Google Chrome personal user's windows.
Hello,
So I have created and running multiple google chrome instances with different users. Link : http://image.prntscr.com/image/286c7...a5e58c5501.png
I would like to find particular instance and bring it to front. But it's not working as expected.
For example, For the "Person 12 - Goole Chrome" window, I tried to find with this but didn't work. Link : http://image.prntscr.com/image/15837...c8072627e2.png
When I tried with notepad, it worked. Is there any other way to find the Google Chrome personal user's window and bring it to front ?
PHP Code:
Public Class Form1
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function FindWindow(
ByVal lpClassName As String,
ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll")>
Private Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim Name As String = "Person 12 - Goole Chrome"
Dim ptr As IntPtr = FindWindow(Nothing, Name)
SetForegroundWindow(ptr)
End Sub
End Class
Thank You!
Last edited by abhishek009; Aug 3rd, 2016 at 12:43 AM.
-
Aug 1st, 2016, 02:37 AM
#2
Thread Starter
Banned
Re: FindWindow function to find Google Chrome personal user's windows.
-
Aug 1st, 2016, 02:44 AM
#3
Re: FindWindow function to find Google Chrome personal user's windows.
Clearly "Person 12 - Goole Chrome" is not the name of the window you're looking for. Have you used a tool like Spy++, WinID or Winspector to examine the window?
Last edited by jmcilhinney; Aug 1st, 2016 at 02:47 AM.
-
Aug 1st, 2016, 02:47 AM
#4
Re: FindWindow function to find Google Chrome personal user's windows.
Originally Posted by abhishek009
Bump!
Please don't bump your threads. Bumping at all is frowned on, let alone after a few hours. Your question is no more important than anyone else's so there's no good reason to push it back above the more recent ones. If it's still on the first page of the New Posts list, which is where I found it, then there's no reason to do anything. If it slips from that first page, then you should try to consider why that's happened and provide additional information or at least ask what additional information might be useful rather than just bumping. We are all volunteers and we all live in different time zones so we'll get to it if and when we can.
-
Aug 1st, 2016, 02:58 AM
#5
Thread Starter
Banned
Re: FindWindow function to find Google Chrome personal user's windows.
Originally Posted by jmcilhinney
Clearly "Person 12 - Goole Chrome" is not the name of the window you're looking for. Have you used a tool like Spy++, WinID or Winspector to examine the window?
Yes I tried. But every window having the same name. How can find window uniquely ? Kindly suggest me another way. And sorry for bumping.
-
Aug 1st, 2016, 03:01 AM
#6
Re: FindWindow function to find Google Chrome personal user's windows.
You'll have to enumerate the windows and examine each one to see whether it has the properties you're looking for. If you already know that they all have the same name then you can't just use an arbitrary name and expect it to work just because it would be convenient for you.
-
Aug 1st, 2016, 03:23 AM
#7
Thread Starter
Banned
Re: FindWindow function to find Google Chrome personal user's windows.
Originally Posted by jmcilhinney
You'll have to enumerate the windows and examine each one to see whether it has the properties you're looking for. If you already know that they all have the same name then you can't just use an arbitrary name and expect it to work just because it would be convenient for you.
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. :/
-
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.
-
Aug 2nd, 2016, 11:50 PM
#9
Thread Starter
Banned
Re: FindWindow function to find Google Chrome personal user's windows.
Last edited by abhishek009; Aug 3rd, 2016 at 12:42 AM.
Reason: solved.
-
Aug 3rd, 2016, 12:41 AM
#10
Thread Starter
Banned
Re: FindWindow function to find Google Chrome personal user's windows.
Originally Posted by Edgemeal
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
Thank You so much!!! Really appreciated
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
|