Results 1 to 10 of 10

Thread: [SOLVED] FindWindow function to find Google Chrome personal user's windows.

  1. #1

    Thread Starter
    Banned
    Join Date
    Jun 2014
    Location
    https://t.me/pump_upp
    Posts
    41

    Resolved [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:=TrueCharSet:=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 ObjectAs EventArgsHandles MyBase.Load

            Dim Name 
    As String "Person 12 - Goole Chrome"
            
    Dim ptr As IntPtr FindWindow(NothingName)
            
    SetForegroundWindow(ptr)
        
    End Sub
    End 
    Class 

    Thank You!
    Last edited by abhishek009; Aug 3rd, 2016 at 12:43 AM.

  2. #2

    Thread Starter
    Banned
    Join Date
    Jun 2014
    Location
    https://t.me/pump_upp
    Posts
    41

    Re: FindWindow function to find Google Chrome personal user's windows.

    Bump!

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    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?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: FindWindow function to find Google Chrome personal user's windows.

    Quote Originally Posted by abhishek009 View Post
    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.

  5. #5

    Thread Starter
    Banned
    Join Date
    Jun 2014
    Location
    https://t.me/pump_upp
    Posts
    41

    Re: FindWindow function to find Google Chrome personal user's windows.

    Quote Originally Posted by jmcilhinney View Post
    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.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    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.

  7. #7

    Thread Starter
    Banned
    Join Date
    Jun 2014
    Location
    https://t.me/pump_upp
    Posts
    41

    Re: FindWindow function to find Google Chrome personal user's windows.

    Quote Originally Posted by jmcilhinney View Post
    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. :/

  8. #8
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: FindWindow function to find Google Chrome personal user's windows.

    Quote Originally Posted by abhishek009 View Post
    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.

  9. #9

    Thread Starter
    Banned
    Join Date
    Jun 2014
    Location
    https://t.me/pump_upp
    Posts
    41

    Re: FindWindow function to find Google Chrome personal user's windows.

    Solved.
    Last edited by abhishek009; Aug 3rd, 2016 at 12:42 AM. Reason: solved.

  10. #10

    Thread Starter
    Banned
    Join Date
    Jun 2014
    Location
    https://t.me/pump_upp
    Posts
    41

    Re: FindWindow function to find Google Chrome personal user's windows.

    Quote Originally Posted by Edgemeal View Post
    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
  •  



Click Here to Expand Forum to Full Width