Results 1 to 5 of 5

Thread: Api

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2007
    Location
    Sweden
    Posts
    50

    Api

    Hi all!
    I want to receive the time and if the mediaplayer is paused using api.
    My problem is that the child is called Static but there’s 3 items there and it seems that I just get the first of them.
    Any one please?

    Heres my code so far:
    Code:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr
    Private Declare Function SendMessageString Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As IntPtr
    
    Private Const WM_GETTEXT As Integer = &HD
    
            Dim parent As IntPtr
            Dim child1 As IntPtr
            Dim child2 As IntPtr
            Dim s As String = Nothing
    
            parent = FindWindow("MediaPlayerClassicW", Nothing) 'get window handle
            child1 = FindWindowEx(parent, IntPtr.Zero, "#32770", Nothing)
            child2 = FindWindowEx(child1, IntPtr.Zero, "Static", Nothing)
            SendMessageString(child2, WM_GETTEXT, 50, s)
            MsgBox(s)
    Attached Images Attached Images  

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Api

    Code:
    child2 = FindWindowEx(child1, IntPtr.Zero, "Static", Nothing)
    That indicates that the search should start from the parent. Once you have the first child of that type, you call FindWindowEx again and specify the first child as the starting point for the search. That will give you the second child of that type. You can keep on calling FindWindowEx with the previous child handle to go through every child of a particular type.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2007
    Location
    Sweden
    Posts
    50

    Re: Api

    Thanks for taken the time
    I think I understand but I cant get it to work. Maybe I use SendMessageString wrong?
    However I do get a handle:
    Code:
            Dim parent As IntPtr
            Dim child1 As IntPtr
            Dim child2 As IntPtr
            Dim child3 As IntPtr
            Dim s As String = Nothing
    
            parent = FindWindow("MediaPlayerClassicW", Nothing) 'get window handle
            child1 = FindWindowEx(parent, IntPtr.Zero, "#32770", Nothing)
            child2 = FindWindowEx(child1, IntPtr.Zero, "Static", Nothing)
            child3 = FindWindowEx(child1, child2, "Static", Nothing)
            SendMessageString(child3, WM_GETTEXT, 50, s)
            MsgBox(s)
    Here the "s" returns nothing.
    But if I do like this:
    Code:
            child3 = FindWindowEx(child1, child2, "Static", "Paused")
    Then child3 return zero if "paused" dosent exists. But I would like to loop over all 3 Static and retrive the text.

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

    Re: Api

    This is done from memory but I think that you would get all child windows of a type like this:
    vb.net Code:
    1. Dim start As IntPtr = IntPtr.Zero
    2. Dim child As IntPtr = FindWindowEx(parent, start, "ClassName", Nothing)
    3.  
    4. Do Until child = IntPtr.Zero
    5.     'Use child here.
    6.  
    7.     start = child
    8.     child = FindWindowEx(parent, start, "ClassName", Nothing)
    9. Loop
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2007
    Location
    Sweden
    Posts
    50

    Resolved Re: Api

    Thats it! Thanks

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