Link to home
Start Free TrialLog in
Avatar of Amnon
Amnon

asked on

Finding picture box hwnd.

Hello,

I'm painting from one application to other application's
picture box.
I need to know the other application picture box hwnd in order to paint in it (there's more than one picture box in the form and I don't want to pass the hwnd with communication between the application).
If I use FindWindow I can find the form (because I have the form caption) , but picture box have no caption and I don't
know how to find it hwnd.

Any suggestions ?

Thanks
Avatar of RichardE
RichardE


You do not indicate which version of VB you are using. This works in VB6 but not sure if VB5 allowed you to create form properties.

If using VB6 : Put the Picture box's HWND in a property of the form.

Create a form level property such as : PicBoxHandle

Then if that form's load event :

PicBoxHandle = Me.Picture1.hWnd  

Now when you "locate" that form from the other app, just check the PicBoxHandle property.



Avatar of Amnon

ASKER

I'm working with vb4 and can't craete a form level property .
ASKER CERTIFIED SOLUTION
Avatar of Sendoh
Sendoh
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The code as follow :

Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Function enumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
    Dim abc As String * 100
   
    GetClassName hwnd, abc, 100
    If InStr(abc, "PictureBox") Then
        MsgBox abc
        enumChildProc = False
    Else
        'MsgBox Str(hwnd)
        enumChildProc = True
    End If
End Function

Private Sub Command1_Click()
    EnumChildWindows Form1.hwnd, AddressOf enumChildProc, &H0
End Sub