Place VC++ child dialog(dll) inside VB form ??
Hi all,
I have VC++ regular dll which creates a dialog as child and returns pointer.
My requirement is i need to invoke this DLL from VB and place the created child dialog inside VB form
First of all is this possible? is yes how can we achive it?
//////////////////////////////////////////////////////////
Background
I dont have much idea about VB as i am vc++ programmer, My colleague says its impossible to display a vc++ child dialog(dll) in her VB form but can display a vc++ dialog if its of popup style.
But my requirement is VC++ child dialog has to be displayed inside VB forms and not as popop window.
Re: Place VC++ child dialog(dll) inside VB form ??
Possible it is.
First you have to declare the function and its origin like
Code:
Declare Function myDllFunction Lib "mydll.dll" ([optioanl parameters]) As Long
In your VB ptogram you invoke it like
Code:
Dim retval As Long
retval = myDllFunction([parameters if any])
The appearance of the popup, however, would propably be on top of the B windows, but not actually inside them.
The function should return the actual window handle (hWnd) of the popup, then we could think of methods to make a VB window parent to it, or at least simulate an appearance "within" the VB window.
Re: Place VC++ child dialog(dll) inside VB form ??
Thanks for the reply.
Quote:
Originally Posted by
WoF
Possible it is.
First you have to declare the function and its origin like
Code:
Declare Function myDllFunction Lib "mydll.dll" ([optioanl parameters]) As Long
In your VB ptogram you invoke it like
Code:
Dim retval As Long
retval = myDllFunction([parameters if any])
She has done these steps and is able to display it as Popup.
Quote:
Originally Posted by
WoF
The appearance of the popup, however, would propably be on top of the B windows, but not actually inside them.
Yes, this is the problem.
Quote:
Originally Posted by
WoF
The function should return the actual window handle (hWnd) of the popup,
The function can be modified to return hWnd, no issues.
Quote:
Originally Posted by
WoF
then we could think of methods to make a VB window parent to it, or at least simulate an appearance "within" the VB window.
What are all the methods to make a VB window parent to it? as i am passing child window m_hwnd to VB.
Please lets not simulate the appearance "within" the VB window.
Re: Place VC++ child dialog(dll) inside VB form ??
There is an API call SetParent, which should do what you want:
http://allapi.mentalis.org/apilist/SetParent.shtml
Although I'm not quite sure about a form "in" another form, except if the parent is an MDI form which has child forms within its area.
1 Attachment(s)
Re: Place VC++ child dialog(dll) inside VB form ??
A sample VC++ dll called VCDllChildDlg has been attached.
Entry function is CallDllChildWindow which returns HWND
extern "C" __declspec(dllexport) HWND CallDllChildWindow()
Can you place the vc++ child dialog inside VB Form? If vb is MDI form or just a Form no issues.
Re: Place VC++ child dialog(dll) inside VB form ??
Well, why can't you?
Did you try the SetParent function according to the instructions?
It gives us all a bad feeling to run unknown code from a dll on our ccomputers.
Re: Place VC++ child dialog(dll) inside VB form ??
Quote:
Originally Posted by
WoF
Well, why can't you?
Beacause i dont know VB
Quote:
Originally Posted by
WoF
Did you try the SetParent function according to the instructions?
I cant tell the VB guys as they say they are expert and they cant achieve above requirement.
Quote:
Originally Posted by
WoF
It gives us all a bad feeling to run unknown code from a dll on our ccomputers.
To be honest, If i were you i would have created the VB app and would have attached VB source here instead of using an unknown code. I guess it hardly a 5 lines of code.
Re: Place VC++ child dialog(dll) inside VB form ??
You could post the code:
w/CODE TAGS
Re: Place VC++ child dialog(dll) inside VB form ??
Ok, I misunderstood.
So, assumed you have a form named Form1 and you want to open your dll's child and attach it to Form1 then this is the code:
Code:
'First the SetParent API function is declared.
Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
'Then the function inside your dll is declared.
Declare Function CallDllChildWindow Lib "VCDllChildDlg.dll" () As Long
'A variable ChildWindow is declared to hold the hWnd of the child
Private ChildhWnd As Long
Sub OpenAndAttachChild()
' this calls your dll for the child window and calls SetParent to attach it to the Form1.
Dim res As Long
ChildhWnd = CallDllChildWindow
res = SetParent(ChildhWnd, Form1.hWnd)
If res <> 0 Then 'you have succeeded, otherwise the call failed for some reason.
End Sub
Instead of Form1.hWnd you could write Me.hWnd when the code is within the parent form.
Re: Place VC++ child dialog(dll) inside VB form ??
@WoF - Much appreciated for the code.
When i copied your code to form1.frm it was giving compiler errors.
I figured out that we have to add Private before 'Declare' keyword with the help of google.
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Thats it, it worked for me :thumb:.