Solved

MDI Child Forms within an ActiveX DLL

Posted on 1998-10-13
8
665 Views
Last Modified: 2008-02-20
The project we are working on is designed using an "add-in" metaphor.  We have a very light-weight MDI front end for this project.  One thing we want to do is be able to store MDI Child forms in an ActiveX  DLL and then reference them doing something like this:

Dim frmForm as Form
Set frmForm = <ActiveX DLL Reference>.GetSearchDialog

However, this generates a VB Runtime Error 366: Unable to load MDI Form.  We are assuming this means that the MDIChild form does not have a way of knowing who its parent would be.  We have tried using the SetParent API call for this, but we need to get the hWnd property of the MDIChild. Accessing any property of the MDIChild causes this error to occur.

Any thoughts...?

0
Comment
Question by:Mason
8 Comments
 
LVL 3

Expert Comment

by:vbWhiz
ID: 1439755
VB is probably not going to let you put one MDI parent's children inside another MDI parent, especially if the MDI parent for which the child is created hasn't been loaded yet. What charecteristics are you looking for in this child form? To be a child of VB's Parent form? You can gain this result by just changing the form's MDIChild property to false and then using the SetParent API Call.
0
 
LVL 2

Expert Comment

by:kswinney
ID: 1439756
Mason, I'm afraid vbWhiz is right.  You can't compile MDI children into an ActiveX DLL.  If what you're after is a container app that hosts add-ins, you have a couple of choices:

1) Write your forms as ActiveX Documents and host them inside a browser.

2) Write your own child form handler using the "SetParent" API call.  I have some friends doing this, so I know it can be done.

HTH.
0
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1439757
You can Compile as ActiveX.EXEs and Use MDI forms.

My boss loves to use them..
I think it sucks.. I would rather
Load up in process<dll> forms and "center" them over the Parent App.

I guess in your case it might be ok.  My boss only uses it for
a standard container.  but it doesnt do anything<theMdi> except hold an Exit button. <now you know why it sucks for me>

He also loves to Late bind everything.. <Arrgh>  
0
 

Author Comment

by:Mason
ID: 1439758
Compiling MDI Child Forms (regular forms with the MDIChild property set to True), not an MDIForm which is used for the parent, into an ActiveX EXE does not work.  Getting a reference to an MDI Child form that is located within the Active EXE and then attempting to access any property/method always results in a VB-Runtime Error 366: Unable to load MDI Form.  Again this has something to do with the MDI Child form not knowing who its parent form would be.  Unfortunately to get the hWnd of the MDI Child form (to use the SetParent API call) you need to access a property.  I am currently looking into other API calls to do this.

Too bad the MDIChild property is design time only!!!

The whole point is to be able to host the MDI Child forms inside the parent MDI Form.  It is very easy to place a regular form (MDIChild property set to False) inside an ActiveX DLL or EXE and then load it.  However these will not be hosted inside the parent container window.  They are mearly displayed on top of the parent.

Another suggestion was to use the SetParent API call.  You can do this with a regular form (MDIChild property set to false), however the behavior that this causes is nothing like what a true MDI Child form does.  Resizing the MDI Parent form does not cause the MDI Child form to resize within the parent if the child is maximized.  The MDI Childs menu is not merged with the parent forms menu, and a ton of other problems...

It was also suggested that we place these into ActiveX Documents, which we have done, however, it poses its own set of problems.  This does seem to be the best course of action to take, it at least works to a point.

Thanks for the response...

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1439759
Are you telling me that I am wrong?\

Are you saying that My MDI form in My ActiveX EXE can no host
MDI Children?

I beg to differ.

Or is it that you are having several MDI children all by themselves in the EXE.. and you are trying to set them to a MDI Form in another app?
0
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1439760
ah.. I misread your statement.. I did think it was odd that you were having an MDI calling another MDI with children.  

0
 

Accepted Solution

by:
lppjohns earned 200 total points
ID: 1439761
I have done exactly the magic that you are looking for on the matter of dll MDI children, be prepared to print this as this is a huge bastardization of the MDI process and I'm sure it breaks a dozen rules of programming.  Here goes.

Make your main executable an MDI parent and create a blank mdi child form that you will use as a template.

Make your dll a standard form that is not an MDI child.  Place the SetParent API function in this dll so that it is available later.  Create a public method (I called it PassHwnd) that alllows the long value of HWND to be passed in.

When your executable calls for the dll to be instantiated perform the following:
     1: Have the Main Executable create a new MDI child from that template MDI child specified earlier.
     2: Instantiate the dll (This should also show the dll's form)
     3: Call the PassHwnd method and pass in the windows handle of the new MDI child you just created in the executable.
     4. In the PassHwnd method in the dll, call the setparent api and set the dll form's parent to be the MDI child in the Main Executable (You just passed it in).  You will also have to arrange for the size of the form to fit in the MDI child, the boarder of the dll form must be fixed single and it can have no caption.  Also do not allow it to be sized by the user or moved by the user.  I chose to pass the size of the new form back to the Main Executable via an event and then resize it in main.  The top and left properties of the dll form must be set to zero.
     5. You now have an MDI grandchild, trapped in the MDI child that will behave similiarly to a real MDI child in that it can be moved offscreen to activate the scroll bars.
     6. Problems with this method are that it is complicated as hell and there are a  lot of variables that end up flying hither and thither.  We currently use it on a project and it has behaved with good stability, I just wouldn't want to be the poor guy 10 years down the road to look at it and try to work on it.
0
 
LVL 3

Expert Comment

by:vbWhiz
ID: 1439762
Clever :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

895 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

14 Experts available now in Live!

Get 1:1 Help Now