Solved

Finding picture box hwnd.

Posted on 1999-01-10
4
437 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 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

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

696 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