Results 1 to 10 of 10

Thread: FindWindowEx

  1. #1

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I am using:

    Code:
    X = FindWindowEx(hwnd, 0&, "RICHEDIT", vbNullString)
    to get the hWnd of one the rich edit boxes on a form of another program so I can send text to. This works fine, the problem I have is there are two rich edit boxes on the form how do I get the other rich edit box hWnd?
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Code:
    Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
    
    Private returnval(), counter%, Parent&
    Private Function EnumFunction(ByVal hwnd&, ByVal lParam&) As Long
        If GetParent(hwnd) <> Parent Then EnumFunction = True: Exit Function 'Exits if it's a indirect child
        counter = counter + 1
        ReDim Preserve returnval(counter - 1)
        returnval(counter - 1) = hwnd
        EnumFunction = True
    End Function
    
    Public Function Getchild(Parenthwnd&)
        Parent = Parenthwnd
        counter = 0
        EnumChildWindows Parenthwnd, AddressOf EnumFunction, 0
        If counter Then Getchild = returnval
    End Function
    You could enumerate the child windows of your form and check for their classnames, catch both richtextboxes and check for their specific size or position to determine which one it is
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Once again Kedaman you rule!!

    Thanks
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Or you can still use FindWindowEx function by looping through all children that's class name is RICHEDIT:
    Code:
    Dim lngChildHwnd As Long
    Dim arrChildren() As Long
    Dim i As Integer
    
    lngChildHwnd = 1
    Do until lngChildHwnd = 0
        lngChildHwnd = FindWindowEx(ParentHwnd, lngChildHwnd, "RICHEDIT", vbNullString)
    
        If lngChildHwnd Then
            Redim Preserve arrChildren(i)
            arrChildren(i) = lngChildHwnd
            i = i + 1
        End If
    Loop
    arrChildren now holds window handles of all RICHEDIT children (assuming that ParentHwnd is a parent window handle).

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Yep, but Serge seems to have found a better solution!
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I can't get serge's solution to work though it will only find the first hWnd then it stops.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  7. #7
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Are you sure you pass a parent that has more then 1 RICHEDIT child???

  8. #8

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Positive I used spy++ and both are named RICHEDIT and they both have different hWnds
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Hmm I tried the same and didn't get any handles of the Richtextboxes at all, are you sure the arguments are correct?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    It's hard to say if it's working correctly or not, since I don't know what application you're trying to use to send the text to.

    This code was tested with the form and 5 RichTextboxes sitting on it. It has created an array with 5 elements. Even though classname of the RichTextBox in VB is different, it shouldn't be any different then to look for RICHEDIT.

    [Edited by Serge on 10-20-2000 at 07:25 PM]

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