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




Reply With Quote