CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2001
    Location
    Denmark
    Posts
    21

    Only one instance of MDI Child Forms

    Hey

    I'm making a windows MDI application. I have a menu where I can select the mdi child forms to view. But when one instance of a Form is opend a new one can't be opend. How do I make this the best way??

    It's like in Microsoft Excel, where it only is possible to make one instance of each toolbar
    Last edited by naxos; December 27th, 2002 at 12:23 PM.

  2. #2
    Join Date
    Dec 2002
    Location
    Germany
    Posts
    4

    Smile

    Hi,

    I had this kind of problem some time ago, and unfortumately the exact source code is not availabel now to me.

    I solved the problem this way.
    First, assign to your form, where you want to do the one window job a document template.

    In the mainframe.cpp add a message handler for the new Window.

    In that handler you have to find the attached document, which shall be opened.
    See if it is of the type of your One-Window-Template
    If it is not, you can do the normal job.
    If it is, find out, if a view is attached to that template.
    If it is not, you can do the normal job.
    If a View is attached, find out if it is minimized or so.
    Restore the View.

    I try to find that piece of code on my machine and post you the source code. But this will take a couple of days.

    Sorry for the inconfiniance.

    Regards

    GSte

  3. #3
    Join Date
    Jul 2001
    Location
    Denmark
    Posts
    21
    Well thanks

    But first of all i'm coding in C# I found this code og making a simple implemetation og af singleton pattern:

    using System;
    class SingleInstanceClass
    {
    private static SingleInstanceClass sic= null;
    private static bool instanceFlag = false;
    private SingleInstanceClass()
    {
    }

    public static SingleInstanceClass Create()
    {
    if(! instanceFlag)
    {
    sic = new SingleInstanceClass();
    instanceFlag = true;
    return sic;
    }
    else
    {
    return null;
    }
    }

    protected void Finalize()
    {
    instanceFlag = false;
    }
    }


    class MyClient
    {
    public static void Main()
    {
    SingleInstanceClass sic1,sic2;
    sic1 = SingleInstanceClass.Create();
    if(sic1 != null)
    Console.WriteLine("OK");
    sic2 = SingleInstanceClass.Create();
    if(sic2 == null)
    Console.WriteLine("NO MORE OBJECTS");
    }
    }


    a little modification and I think it is that

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured