Windows app without a master window

  • Thread starter Thread starter Harlan Messinger
  • Start date Start date
H

Harlan Messinger

I've set up a Windows app in C# for working with a type of document I've
designed. When I use my app's File | Open menu item, after presenting
the Open Files dialog it opens my selected file in a new window, which
is of the same type as the app's main window.

Now, when I have several documents open, as in Microsoft Word, I should
be able to close any one of them without the app shutting down until all
the document windows have been closed. And this is what happens--except
when I close the original window. Doing that, of course, shuts down the
application, since this is the window referenced in the application's
message loop.

How do I structure the application so that it opens a window initially,
as Word does, but without giving that one window sole control over the
application?
 
Harlan said:
I've set up a Windows app in C# for working with a type of document I've
designed. When I use my app's File | Open menu item, after presenting
the Open Files dialog it opens my selected file in a new window, which
is of the same type as the app's main window.

Now, when I have several documents open, as in Microsoft Word, I should
be able to close any one of them without the app shutting down until all
the document windows have been closed. And this is what happens--except
when I close the original window. Doing that, of course, shuts down the
application, since this is the window referenced in the application's
message loop.

How do I structure the application so that it opens a window initially,
as Word does, but without giving that one window sole control over the
application?

I think I figured it out, assuming this is the *correct* way. Replace

Application.Run(new ProjectWindow());

with

(new ProjectWindow()).Show();
Application.Run();

and set up my own singleton window manager that the first ProjectWindow
will cause to be instantiated and that will call Application.Exit() when
no open ProjectWindows remain.
 
Two thoughts...

Make another hidden window the application window and open an instance of
your document window automatically at start up.

Use MDI and have all the documents open up in MDI child windows. Can close
any child window (document) you want, or all of them when you close the main
window (this is how Word works)
 
Back
Top