none
How to get a hWnd of an external ProgressBar in VB.NET RRS feed

  • Question

  • Hi all!

    I have a Form with a progressbar, and I'm trying to upgrade the value of my pb with the value of a third-party software progressbar. How could I do?
    Alternatively, how can I get a "get-list" of all the components of the other software so that i'll be able to interact with them?

    Thanks a lot!

    Saturday, February 2, 2019 4:22 PM

Answers

  • The following is a starting point only, not an answer.

    You need to get the handle for the progressbar first, use Spy.

    Select the search menu and then use the Finder tool (single click, hold and drag to the progress bar) to get the handle or class name (below handle).

    From there use the following API to get at the controls, from there it will depend on what you find but it will be a struggle to tap into things like a progress bar.

    Imports System.Runtime.InteropServices
    ...
    <DllImport("user32.dll", SetLastError := True)> _
    Private Shared Function FindWindow(lpClassName As String, lpWindowName As String) As IntPtr
    End Function


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, February 2, 2019 4:35 PM
    Moderator

All replies

  • The following is a starting point only, not an answer.

    You need to get the handle for the progressbar first, use Spy.

    Select the search menu and then use the Finder tool (single click, hold and drag to the progress bar) to get the handle or class name (below handle).

    From there use the following API to get at the controls, from there it will depend on what you find but it will be a struggle to tap into things like a progress bar.

    Imports System.Runtime.InteropServices
    ...
    <DllImport("user32.dll", SetLastError := True)> _
    Private Shared Function FindWindow(lpClassName As String, lpWindowName As String) As IntPtr
    End Function


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, February 2, 2019 4:35 PM
    Moderator
  • It depends on the class name of the ProgressBar and the hierarchy of controls (check with Spy++)

    For example, with a ProgressBar created in C++/CLI with VS 2015 in a form called "MyForm", I get the correct value with :

    Dim hWndDest As IntPtr = FindWindow(Nothing, "MyForm")
    Dim hWndProgress As IntPtr = FindWindowEx(hWndDest, IntPtr.Zero, "WindowsForms10.msctls_progress32.app.0.141b42a_r9_ad1", Nothing)
    Dim nPos As Integer = SendMessage(hWndProgress, PBM_GETPOS, 0, IntPtr.Zero)

    with declarations :

        <DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
        Public Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
        End Function
    
        <DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
        Public Shared Function FindWindowEx(ByVal hWndParent As IntPtr, ByVal hWndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
        End Function
        
        <DllImport("User32.dll", EntryPoint:="SendMessageW", SetLastError:=True)>
        Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As Integer
        End Function
        
        Const WM_USER = &H400
        Const PBM_GETPOS = WM_USER + 8

    Saturday, February 2, 2019 5:11 PM
  • Thanks a lot Kareninstructor, it works great!
    Monday, February 4, 2019 4:09 PM