Results 1 to 27 of 27

Thread: Get Picture Box hWnd.

  1. #1

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Exclamation

    Does antbody know how to get the PictureBox hWnd? Assume the PictureBox Object does not support the Picture1.hWnd properties.

    Because I writing a program that run under WinCE OS where the PictureBox does not support the Picture1.hWnd properties.

    Your feedback is very useful!


  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Hehe, that was a pretty hard Q, i think, if WinCE does not support hWnds then why do you need it?
    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
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Unhappy I can get alternative choice

    But I currently developing a program that run under WinCE. So I need to resolve it. I know it is a hard Q, but I know you're guy should be able to provide me some idea about this task.

    In pricture box object, it does not have the Title, so can not use the FindWindow API function to locate the hWnd. Arhhhh Do help me!!!


  4. #4
    Addicted Member
    Join Date
    Feb 2000
    Posts
    224

    Use the class Name

    Use Findwindow api but use the class name, it is

    ThunderPictureBox

    in VB.


    If you can't pronounce my name, call me GURU

  5. #5

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Re: Use the class Name

    Originally posted by G.Kumaraguru
    Use Findwindow api but use the class name, it is

    ThunderPictureBox

    in VB.


    I did try it, but how about the lpWindowName arguement? We can leave it blank or put "". But sis put it as "". The result is still 0. That mean the API also can not find the PictureBox.

    But I used the Spy++ it does return me the PictureBox hWnd, Window, ClassName, Window Style, Window RECT value, Thread ID and Process ID. So I'm sure there must be a way to do it!

    Can Some Guru help me!!!

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Talking Here comes you Guru... ehm fanatic

    put a string variable instead of ""
    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.

  7. #7

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Exclamation Can not be others string

    Can not, still return zero to me. I think me can not simply pass a string to the lpWindowName arguement. Since it is one of the searching key for the FindWindow API function.

    Some more hints... please...

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Then what about vbnull, if that doesn't work then i don't know
    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.

  9. #9
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334

    Question Handle

    I was under the impression that the handle to a picture box could be obtained by just using

    Code:
    picture1.picture
    Just to show what I mean try this

    Code:
    Private Sub Command1_Click()
    
    MsgBox Picture1.Picture
    
    End Sub
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Actuatlly that's the same as using picture1.picture1.handle not picture1.hwnd - you get the handle of the picture instead
    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.

  11. #11

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Unhappy vbNull is working BUT...

    gravyboy, yours does not work. Thanks Kedaman, it work with vbNull as the lpWindowName arguement.

    Now, I've another problem... the vbNull work fine with one PictureBox control in the form. But, now I've 2 PictureBox (PictureBox1, PicureBox2) under the same Form call (frmMain.frm).

    So, I still can not use the FindWindow API to get the 2 PictureBox1 and PictureBox2 hWnd value that I'll use it to set the PictureBox1 become the child Window of PictureBox2 by using the SetParent API function:

    SetParent xHwnd, yHwnd

    Assume the xHwnd is the handle value fot PictureBox1,
    yHwnd is the handle value for PictureBox2.

    So, how the single FindWindow API function can differentiate the handle for PictureBox1 and PictureBox2?

    xHwnd = FindWindow("ThunderPictureBox",vbNull)
    yHwnd = FindWindow("ThunderPictureBox",vbNull)

    [Edited by Chris on 05-31-2000 at 06:28 AM]

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I'm not sure if there's any direct way then, but you could enumerate the parentwindow's childs, and get all the wnds
    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.

  13. #13
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Lightbulb

    The second parameter (lpWindowName) is expected to be a string, therefore, you must pass a string data type value:

    Code:
    Dim lHwnd As Long
    
    lHwnd = FindWindow("ThunderPictureBox",vbNullString)
    Also, since the Picturebox belongs to the form then you better use FindWindowEx API:
    Code:
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    
    Private Sub Command1_Click()
        Dim lHwnd As Long
        
        lHwnd = FindWindowEx(Me.hWnd, 0, "ThunderPictureBox", vbNullString)
    End Sub



  14. #14
    New Member
    Join Date
    May 2000
    Posts
    13

    Question off-topic...

    Sorry for the off-topic post, but what version if VB do you have to have to develop Win CE programs? Is there an app wizard or tutorial?

    Thanks,

    Shawn

  15. #15

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Re: off-topic...

    Originally posted by grizzly
    Sorry for the off-topic post, but what version if VB do you have to have to develop Win CE programs? Is there an app wizard or tutorial?

    Thanks,

    Shawn
    Just stay with you VB6 + SP3 + WinCE ToolKit for VB6 that enough already.

  16. #16
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Enumerating windows

    Ok, i have this for you
    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 Parent = GetDesktopWindow Then
        'If GetParent(hwnd) <> Parent Then If GetParent(hwnd) > 0 Then EnumFunction = True: Exit Function  'Exits if it's a indirect child
        'Else
        If GetParent(hwnd) <> Parent Then EnumFunction = True: Exit Function 'Exits if it's a indirect child
        'End If
        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
    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.

  17. #17

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    GetChild

    Thanks Kedaman, your GetChild work great but it return all the available child hwnd to me, which I just interested in those have WindowClass "ThunderPictureBox"

    Come on... more hints...

  18. #18
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Oh, i thought you would figure out, just make a loop checking the classnames of the wnd's and sort them out
    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.

  19. #19

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Kedaman, I'll try & tell you later.

  20. #20

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    GetClassName API

    Hi Kedaman, I just add the GetClassName API function ontop of you code & it work. The only think is the GetClassNAme API return me the PictureBox Class Name = "ThunderPictureBoxDC" instead of "ThunderPictureBox" Anyway, I manage to differentiate between the PictureBox and others control.

    Now, I have the handle for 2 different picture box, but how do I differentiate the handle is belong to which PictureBox.

    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 Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    
    Private returnval(), counter%, Parent&
    Private ReturnStr$, nReturn&, rethWnd$
    Private PichWnd(), hWndCnt%
    Private Function EnumFunction(ByVal hwnd&, ByVal lParam&) As Long
        'If Parent = GetDesktopWindow Then
        'If GetParent(hwnd) <> Parent Then If GetParent(hwnd) > 0 Then EnumFunction = True: Exit Function  'Exits if it's a indirect child
        'Else
        If GetParent(hwnd) <> Parent Then EnumFunction = True: Exit Function 'Exits if it's a indirect child
        'End If
        counter = counter + 1
        ReDim Preserve returnval(counter - 1)
        returnval(counter - 1) = hwnd
        
        ReturnStr = String(255, Chr(0))
        nReturn = GetClassName(hwnd, ReturnStr, 255)
        If nReturn <> 0 Then
            rethWnd = Left(ReturnStr, InStr(1, ReturnStr, Chr(0), vbBinaryCompare) - 1)
            If rethWnd = "ThunderPictureBoxDC" Then
                hWndCnt = hWndCnt + 1
                ReDim Preserve PichWnd(hWndCnt)
                PichWnd(hWndCnt) = hwnd
            End If
        End If
        EnumFunction = True
    End Function
    
    Public Function Getchild(Parenthwnd&)
        Parent = Parenthwnd
        counter = 0
        hWndCnt = 0
        EnumChildWindows Parenthwnd, AddressOf EnumFunction, 0
        If counter Then Getchild = returnval
        SetParent PichWnd(1), PichWnd(2)
    End Function

  21. #21
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Lightbulb

    Try something like this. Add a module to your project. Also, add a couple of pictureboxes a listbox and a button (for testing purposes). Copy this code to the module:
    Code:
    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    Public m_arrHwndPicBoxes() As Long
    
    
    Public Function EnumFunction(ByVal pHwnd As Long, ByVal lParam As Long) As Long
        Static intIndex As Long
        Dim lngRetVal As Long
        Dim strClassName As String
        
        'Get ClassName for pHwnd
        strClassName = Space(125)
        lngRetVal = GetClassName(pHwnd, strClassName, Len(strClassName))
        If lngRetVal Then
            strClassName = Left(strClassName, lngRetVal)
            'Check if the ClassName is ThunderPictureBox
            If strClassName = "ThunderPictureBoxDC" Then
                ReDim Preserve m_arrHwndPicBoxes(intIndex)
                m_arrHwndPicBoxes(intIndex) = pHwnd
                intIndex = intIndex + 1
            End If
        End If
        'Continue enumeration
        EnumFunction = 1
    End Function
    Copy this code to your form:
    Code:
    Private Sub Command1_Click()
        Dim i As Integer
        
        On Error Resume Next
        
        Call EnumChildWindows(Me.hwnd, AddressOf EnumFunction, 0)
        
        For i = LBound(m_arrHwndPicBoxes) To UBound(m_arrHwndPicBoxes)
            If Err.Number = 0 Then
                List1.AddItem m_arrHwndPicBoxes(i)
            End If
        Next
    End Sub

  22. #22

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Unhappy How to differentiate?

    Thanks both Kedaman & Serge, because you guys really look into my problem & I know this quite a hard question.

    Although I manage to get the handle for both PictureBox with the sample code from both of you kedaman and Serge, I still can not differentiate the handle is belong to which picture box.

    Thanks for your further Help.



  23. #23
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    There must be other properties of the wnd's that differs those boxes, ie, you can't have them laying on each other do you? If not you can get their rect's
    Code:
    Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As RECT) As Long
    Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    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.

  24. #24

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Unhappy Reference.

    Hi Kedaman, to get the Window Rect is not a problem, since your code can get the hWnd for both PictureBox. So, how do i differentiate the PictureBox just base on the window rect value? which should I set as a reference? because the PictureBox can be at any place when the program run.

    Thansk for all those helpful feedback.


  25. #25
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Well you drived me almost nuts when you said that, then i realized, you can still get the location of the pictureboxes, do they have left, top,width and heigh? If so you can compare
    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.

  26. #26

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Thumbs up Don't you feel this is very challenging

    no...Kedaman I did drive to nut, but just wander to find out how can achieve this task.

    I know, but let said my intial PictureBox1 is at
    Top = 0
    Left = 0
    Height = 100
    Width = 100

    and PictureBox2 at

    Top = 200
    Left = 200
    Height = 100
    Width = 100

    later PictureBox1 and PictureBox2 also move by the user to somewhere else, then I may lost the refernce point. I may still can resolve it by keep thier respective value into the registry. Don't you see that there was some may procedure to do upon the user have move the picture box?

    because I need to aware the Speed to the handheld device.

    Thanks a lot.

  27. #27
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Compare the rect to the current picturebox position (you have their names and position)
    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.

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