Embed pop-up window in VB form

eschmunk
eschmunk used Ask the Experts™
on
I have a piece of C code that opens up a window when it is ran from a command line.  Is there a way to have it (the window) embedded into a form when it is ran from visual basic?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Use Setparent.
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

  lReturn = SetParent(YOURWINDOWHANDLE, VBFORMWINDOWHANDLE)

Example:

lReturn = SetParent (MyCWindow.hwnd, MyVBForm.hwnd)

Author

Commented:
Is the window handle just the name that is across the top of the window.
Nope.  It is a long value that uniquely identifies this window from all other windows currently in use.  To get a window handle from the name that is across the top of the window, use the Findwindow API.

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long


lCWindowHandle = FindWindow("","My C Window Started From Command Line")

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I used what you mentioned. It does not seem to take the window into a form. It still opens up in a seprate window.
Here's the code I use to do it in VB.  Pretty simple.  Since it's the API that's being used, I don't see a problem with the windows language (C vs VB)

2 forms in my project (Form1 and Form2)

Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Private Sub Command1_Click()
    Load Form2
   
    Call SetParent(Form2.hWnd, Form1.hWnd)
    Form2.Show
   
End Sub

Author

Commented:
Is that going to do what I need?

I need the window to be attached in say a picture box, or something of the sort in the form when the C program is ran.
Yes, but change the 2nd parameter of the Setparent call.


Here's the code I use to do it in VB.  Pretty simple.  Since it's the API that's being used, I don't see a problem with the windows language (C vs VB)

2 forms in my project (Form1 and Form2)

Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Private Sub Command1_Click()
   Load Form2
   
   '***This is the line of code that changed
   Call SetParent(Form2.hWnd, Form1.picture1.hWnd)
   Form2.Show
   
End Sub
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- award the points to twalgrave
Please leave any comments here within the
next seven days.

Author

Commented:
Why am I going to award points if the answer does not do what I intend for it to do.
eschmunk,
First of all, you didn't come back and indicate that the last answer did or did not satisfy your needs.  

Secondly, I have used this technique many times all with absolute success.

The experts here are willing to help, but if you give no feedback, we don't know how else to help.  If you'd care to post the code you have tested the solution with, perhaps we can look at it and get it working for you.

I noticed that you have 6 total questions asked.  3 of them are still open and you haven't provided any feedback on them (with the exception of the feedback provided here).  We need to know if we are on the right track.

eschmuck,

This question is scheduled for closure. If we do not here a response from you within 72 hours, it will be closed as recommended.

Netminder
EE Admin
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial