Solved

Finding picture box hwnd.

Posted on 1999-01-10
4
399 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
  • 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 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.
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now