2
Answers

Windows Forms Application::Run confusion

Tom

Tom

14y
2.9k
1
Hello,

Please be gentle with me - I'm early on in a steep learning curve!  I have inherited an application which I have to maintain - I'm using .NET 2.0 and VS2005 Professional  (and C++, but I hope the same principles apply as with C#).

I have a fairly simple application, which is based around one form.   However, it also has an optional registration dialog to display first, and a splash screen.

The code I have is almost certainly very wrong - my 'main' function looks something like:

.
.
.
   if (registration needed) {
    Form ^ dialogRegistration = gcnew registration();

dialogRegistration->ShowDialog();
    }

Application::Run(gcnew SplashScreen());

Application::Run(gcnew MainAppForm());
.
.
.

See what I mean?  Not only does this app contain *two* Application::Runs, but it also first displays a dialog before the first Application::Run - so presumably before there's a message pump etc set up at all?

Strangely, this application does work - it's sold numerous copies to the paying public.  I've had very occasional reports of errors at startup, which is what's caused me to look at this in the first place.  But 99% of times, including on all my systems here, it works fine.

My questions are - is the code above as broken as I think?  And can anyone guide me as to how I should be doing it?  The functionality needs to remain:

1 (optionally) do a form A (the registration form).   Then...
2 do splash screen.  Then...
3 do form B (the application's main form).

Thanks in advance for any help.
Tom

Answers (2)
0
Sam Hobbs

Sam Hobbs

NA 28.7k 1.3m 14y

Yes, your assumption that there is no message loop is incorrect. Is my assumption valid that you did not look at the Application.Run Method (Form) documentation? It says right at the top "Begins running a standard application message loop on the current thread". Note also that by definition of what a dialog is, there is a message loop for the dialog; that is how dialogs work.
 
Now since you assumed that there is not a message loop, you did not say anything about the real problem. If you need help with the real problem, then you need to be more specific about that.
0
Jaish Mathews

Jaish Mathews

NA 7.3k 1.2m 14y

Hi,
How about,
if (registration needed) {
<<SHOW DIALOG>>
<<IN DIALOG OK BUTTON SHOW SPLASH>>
<<IN SLASH OK BUTTON SHOW MAIN FORM>>
}
else
{
<<   SHOW SPLASH>>

<<IN SLASH OK BUTTON SHOW MAIN FORM>>
}