Finding picture box hwnd.

Posted on 1999-01-10
Last Modified: 2009-12-16

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 ?

Question by:Amnon
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 1455171

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.


Author Comment

ID: 1455172
I'm working with vb4 and can't craete a form level property .

Accepted Solution

Sendoh earned 100 total points
ID: 1455173
Hi !
I think you can get it by calling

Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

and get the classname of every child window by calling

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

Just check

if instr(className, "PictureBox") then

will do.

Hope this'll help you.

Expert Comment

ID: 1455174
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
        'MsgBox Str(hwnd)
        enumChildProc = True
    End If
End Function

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


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question