Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

MDI Parent & Child Forms

pladeirapladeira Posts: 5Member
Hi there,

I need to know how to tell a mdichild form who is it's parent mdiform !

The scenario is: I have a vb6 application and need to split the application. For that i'm trying to put some mdichild forms in activex dll projects (COM). The problem is that these mdichild forms don't seem to know about their mdiparent form in the master application project.

Can anyone help me on this ?
«1

Comments

  • infidelinfidel Posts: 2,900Member
    : Hi there,
    :
    : I need to know how to tell a mdichild form who is it's parent mdiform !
    :
    : The scenario is: I have a vb6 application and need to split the application. For that i'm trying to put some mdichild forms in activex dll projects (COM). The problem is that these mdichild forms don't seem to know about their mdiparent form in the master application project.
    :
    : Can anyone help me on this ?

    I've only seen one way to do this and it involved various win32 API calls to pretend like a form in a DLL is a child of an MDI form. There's no way to do it without clever hacking like this.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : I've only seen one way to do this and it involved various win32 API calls to pretend like a form in a DLL is a child of an MDI form. There's no way to do it without clever hacking like this.
    :
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    : [code]
    : $ select * from users where clue > 0
    : no rows returned
    : [/code]
    :

    And there is no way the Parent MDI Form (in the main app) can create an instance of those MDI childs?
    Shouldn't that work? I mean: the instances of the MDI childs forms belong to the main application, so to the MDI Parent. The only difference is that the code is exposed by another project!

    Greets...
    Richard

  • pladeirapladeira Posts: 5Member
    : : I've only seen one way to do this and it involved various win32 API calls to pretend like a form in a DLL is a child of an MDI form. There's no way to do it without clever hacking like this.
    : :
    : :
    : : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    : :
    : : [code]
    : : $ select * from users where clue > 0
    : : no rows returned
    : : [/code]
    : :
    :
    : And there is no way the Parent MDI Form (in the main app) can create an instance of those MDI childs?
    : Shouldn't that work? I mean: the instances of the MDI childs forms belong to the main application, so to the MDI Parent. The only difference is that the code is exposed by another project!
    :
    : Greets...
    : Richard
    :
    :

    Richard ... it seems a great ideia (that i never thought of). I'm going to try this and ill tell you later if it works.

    Using the WinAPI calls could also work but i'll get into that only if this approach doesn't work.

    Thanks to you both !
  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : : I've only seen one way to do this and it involved various win32 API calls to pretend like a form in a DLL is a child of an MDI form. There's no way to do it without clever hacking like this.
    : :
    : :
    : : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    : :
    : : [code]
    : : $ select * from users where clue > 0
    : : no rows returned
    : : [/code]
    : :
    :
    : And there is no way the Parent MDI Form (in the main app) can create an instance of those MDI childs?
    : Shouldn't that work? I mean: the instances of the MDI childs forms belong to the main application, so to the MDI Parent. The only difference is that the code is exposed by another project!
    :
    : Greets...
    : Richard
    :
    :

    The API would let you, I believe; it's just VB that won't. VB also doesn't tell you that there's no difference between MDIChildren, MDIForms and Forms. The MDI property of a MDIForm is a MDI control set on a normal form. The MDIChild property merely designates the MDI control as the parent instead of the desktop. So don't be at all surprised if VB won't let you use a MDI child in a seperate project.

    Option 1: I've seen a control you can get that would allow you to drop an instance on a MDIForm and on MDIChildren in a seperate project. VB is somehow tricked into showing them properly. Unfortunately, I had no use for it so you'll have to hunt the net. Incidentally, this control is probably doing what infidel mentioned.

    Option 2: Create a "hosting" form in the MDI project. When you want to show a new MDIChild, create a new instance of the hosting form, pass it to the DLL and let the DLL create a "MDIChild" and move it onto the hosting form. This is my method though I haven't tried it in forever. I also suspect it's the basis for usercontrols.
  • pladeirapladeira Posts: 5Member
    Well, I've tried this approach but it doesn't seem to work.

    First of all a form is a special kind of object that is not public to the activeX dll, so my main app can't create a new instance of it !

    I could try to encapsulate the form in a class but that's another thing ... and i'm not quite sure how to do that.


    I tried also to use API function, like SetParent() and GetWindowLong()/SetWindowLong(). It did work ... more or less ... but there are quite a few drawbacks !

    Any more ideas ?! Thanks guys.
  • pladeirapladeira Posts: 5Member
    : : : I've only seen one way to do this and it involved various win32 API calls to pretend like a form in a DLL is a child of an MDI form. There's no way to do it without clever hacking like this.
    : : :
    : : :
    : : : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    : : :
    : : : [code]
    : : : $ select * from users where clue > 0
    : : : no rows returned
    : : : [/code]
    : : :
    : :
    : : And there is no way the Parent MDI Form (in the main app) can create an instance of those MDI childs?
    : : Shouldn't that work? I mean: the instances of the MDI childs forms belong to the main application, so to the MDI Parent. The only difference is that the code is exposed by another project!
    : :
    : : Greets...
    : : Richard
    : :
    : :
    :
    : The API would let you, I believe; it's just VB that won't. VB also doesn't tell you that there's no difference between MDIChildren, MDIForms and Forms. The MDI property of a MDIForm is a MDI control set on a normal form. The MDIChild property merely designates the MDI control as the parent instead of the desktop. So don't be at all surprised if VB won't let you use a MDI child in a seperate project.
    :
    : Option 1: I've seen a control you can get that would allow you to drop an instance on a MDIForm and on MDIChildren in a seperate project. VB is somehow tricked into showing them properly. Unfortunately, I had no use for it so you'll have to hunt the net. Incidentally, this control is probably doing what infidel mentioned.
    :
    : Option 2: Create a "hosting" form in the MDI project. When you want to show a new MDIChild, create a new instance of the hosting form, pass it to the DLL and let the DLL create a "MDIChild" and move it onto the hosting form. This is my method though I haven't tried it in forever. I also suspect it's the basis for usercontrols.
    :

    Hi there,

    Your option 2 seems a good ideia to try !
    I haven't understood what you mean when you say "move it onto the hosting form" ! How can i do that ?

    Thank you
  • DjSpiritDjSpirit Posts: 371Member
    : : I've only seen one way to do this and it involved various win32 API calls to pretend like a form in a DLL is a child of an MDI form. There's no way to do it without clever hacking like this.
    : :
    : :
    : : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    : :
    : : [code]
    : : $ select * from users where clue > 0
    : : no rows returned
    : : [/code]
    : :
    :
    : And there is no way the Parent MDI Form (in the main app) can create an instance of those MDI childs?
    : Shouldn't that work? I mean: the instances of the MDI childs forms belong to the main application, so to the MDI Parent. The only difference is that the code is exposed by another project!
    :
    : Greets...
    : Richard
    :
    [grey]You could create the mdichild form in the main application then setparent for the controls on your dllform to the mdiform. You would probably get some problems with positioning, but it should be overcomable.

    DjSpirit, they could of course have implemented som simple procedure to acheve this, but where would the fun in that be.[/grey]
  • pladeirapladeira Posts: 5Member
    : : : I've only seen one way to do this and it involved various win32 API calls to pretend like a form in a DLL is a child of an MDI form. There's no way to do it without clever hacking like this.
    : : :
    : : :
    : : : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    : : :
    : : : [code]
    : : : $ select * from users where clue > 0
    : : : no rows returned
    : : : [/code]
    : : :
    : :
    : : And there is no way the Parent MDI Form (in the main app) can create an instance of those MDI childs?
    : : Shouldn't that work? I mean: the instances of the MDI childs forms belong to the main application, so to the MDI Parent. The only difference is that the code is exposed by another project!
    : :
    : : Greets...
    : : Richard
    : :
    : [grey]You could create the mdichild form in the main application then setparent for the controls on your dllform to the mdiform. You would probably get some problems with positioning, but it should be overcomable.
    :
    : DjSpirit, they could of course have implemented som simple procedure to acheve this, but where would the fun in that be.[/grey]
    :

    I will try that to see if it works ...

    I have found 2 utilities on the net that do the trick ... and cost little !

    Here is a link for MDI Controller (50$)
    http://www.millennium.no/products/mdi/index.html

    There is another one called MDIExtender Control but has been discontinued.

    They seem to work fine.

    Anyway i'll try your solution.

    Thanks again.
  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    [b][red]This message was edited by Moderator at 2004-7-13 5:30:5[/red][/b][hr]
    : Your option 2 seems a good ideia to try !
    : I haven't understood what you mean when you say "move it onto the hosting form" ! How can i do that ?
    :

    Like I said, it's been a LONG time since I messed with that idea. It's a bit tricky to get working properly but it can be done. You use the SetParent API to change the form's parent.

    SetParent FormToBeMoved.hWnd, FormToHostIt.hWnd

    Are you familiar with using APIs?

    The form must be borderless or it'll look completely stupid! The form's styles must also be altered, do you know how to use Get/SetWindowStyle? You need to turn off Popup and turn on Child. Changing those styles should make it properly hostable. Then you'd call SetParent to move it.

    Even if you aren't familiar with APIs, this isn't too difficult to do; just let me know if you need more info.
  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : Well, I've tried this approach but it doesn't seem to work.
    :
    : First of all a form is a special kind of object that is not public to the activeX dll, so my main app can't create a new instance of it !
    :
    : I could try to encapsulate the form in a class but that's another thing ... and i'm not quite sure how to do that.
    :
    :
    : I tried also to use API function, like SetParent() and GetWindowLong()/SetWindowLong(). It did work ... more or less ... but there are quite a few drawbacks !
    :
    : Any more ideas ?! Thanks guys.
    :

    Don't encapsulate, simply return it.

    Umm, that was the idea I just gave you (in the other post). What drawbacks did you encounter?
«1
Sign In or Register to comment.