?
Solved

Finding picture box hwnd.

Posted on 1999-01-10
4
Medium Priority
?
445 Views
Last Modified: 2009-12-16
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
0
Comment
Question by:Amnon
[X]
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
4 Comments
 
LVL 1

Expert Comment

by:RichardE
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.



0
 

Author Comment

by:Amnon
ID: 1455172
I'm working with vb4 and can't craete a form level property .
0
 
LVL 3

Accepted Solution

by:
Sendoh earned 300 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.
0
 
LVL 3

Expert Comment

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

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

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

801 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