Solved

MDI Child Forms within an ActiveX DLL

Posted on 1998-10-13
8
658 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:TheAnswerMan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Clever :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VB6 add a minute to the date time value 8 44
Access 2016 VB code 9 85
DIR issue 7 45
vb6 connector to SQL Server 2 32
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 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

11 Experts available now in Live!

Get 1:1 Help Now