Solved

MDI Child Forms within an ActiveX DLL

Posted on 1998-10-13
8
687 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

792 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