Click to See Complete Forum and Search --> : Only one instance of MDI Child Forms


naxos
December 27th, 2002, 10:36 AM
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

G Steudtel
December 27th, 2002, 11:34 AM
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

naxos
December 27th, 2002, 11:39 AM
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