splash screen update/animation not working

B

BrianP

I'm trying to get a splash screen working. Yes, I've read the article
at

http://www.codeproject.com/netcf/casoast.asp

I modeled mine after that, but simplified it. I don't have a timer.
I'm just trying to load several forms of my application while the
splash screen is displayed, and call an update() method on the splash
screen after each form is loaded to show progress to the user. To
show the progress, I was trying to just move a rectangle across the
splash screen. The splash screen is displaying and then closing
correctly, but the rectangle isn't moving with each update. I've
verified with breakpoints that the splash form's update() is being
called when it's supposed to, and the onPaint method is being called,
so the problem is almost more of a graphics problem. Or maybe it has
to do with threading and Application.DoEvents(). But I'm mostly a
newb, so the problem could be anything ;-)

Also, I'm still working on VS 2003. That's what I started this
project on awhile ago. I'm now coming back to it after a long pause.
I'm working on getting VS2005, but I'd like to finish it up in 2003
and then convert/upgrade it to 2005.

Here are the relevant code snippets

from the main form :

main form contains

private static SplashForm splash;

private void FormMain_Load(object sender, System.EventArgs e)
{
Thread splashThread = new Thread(new ThreadStart(startSplash));
splashThread.Start();

Global.getBoardForm();
splash.update();
Application.DoEvents();
Global.getNewGameForm();
splash.update();
Application.DoEvents();
etc...

this.Enabled = true;
this.Visible = true;

closeSplash();
}

private void startSplash()
{
splash = new SplashForm();
Application.Run(splash);
}

private void closeSplash()
{
if (splash==null)
return;

splash.Invoke(new EventHandler(splash.KillMe));
splash.Dispose();
splash = null;
}

and the SplashForm :

private int count = 0;

// this will be called when each form is done loading, it basically
means to paint another
// 'progress' rectangle
public void update()
{
count++;
this.Refresh();
}

protected override void OnPaint(PaintEventArgs e)
{
Graphics gx = e.Graphics;
SolidBrush brush = new SolidBrush(Color.DarkCyan);
if(count>0)
{
gx.FillRectangle(brush, startX+(count*20), startY, 18, 35);
}
base.OnPaint (e);
}

Thanks!
 
B

BrianP

I'm trying to get a splash screen working. Yes, I've read the article
at

http://www.codeproject.com/netcf/casoast.asp

I modeled mine after that, but simplified it. I don't have a timer.
I'm just trying to load several forms of my application while the
splash screen is displayed, and call an update() method on the splash
screen after each form is loaded to show progress to the user. To
show the progress, I was trying to just move a rectangle across the
splash screen. The splash screen is displaying and then closing
correctly, but the rectangle isn't moving with each update. I've
verified with breakpoints that the splash form's update() is being
called when it's supposed to, and the onPaint method is being called,
so the problem is almost more of a graphics problem. Or maybe it has
to do with threading and Application.DoEvents(). But I'm mostly a
newb, so the problem could be anything ;-)

Also, I'm still working on VS 2003. That's what I started this
project on awhile ago. I'm now coming back to it after a long pause.
I'm working on getting VS2005, but I'd like to finish it up in 2003
and then convert/upgrade it to 2005.

Here are the relevant code snippets

from the main form :

main form contains

private static SplashForm splash;

private void FormMain_Load(object sender, System.EventArgs e)
{
Thread splashThread = new Thread(new ThreadStart(startSplash));
splashThread.Start();

Global.getBoardForm();
splash.update();
Application.DoEvents();
Global.getNewGameForm();
splash.update();
Application.DoEvents();
etc...

this.Enabled = true;
this.Visible = true;

closeSplash();

}

private void startSplash()
{
splash = new SplashForm();
Application.Run(splash);

}

private void closeSplash()
{
if (splash==null)
return;

splash.Invoke(new EventHandler(splash.KillMe));
splash.Dispose();
splash = null;

}

and the SplashForm :

private int count = 0;

// this will be called when each form is done loading, it basically
means to paint another
// 'progress' rectangle
public void update()
{
count++;
this.Refresh();

}

protected override void OnPaint(PaintEventArgs e)
{
Graphics gx = e.Graphics;
SolidBrush brush = new SolidBrush(Color.DarkCyan);
if(count>0)
{
gx.FillRectangle(brush, startX+(count*20), startY, 18, 35);
}
base.OnPaint (e);

}

Thanks!

Bumping to try to get some help on the busier work week, since I
submitted this on the weekend
 
G

Guest

Is startSplash (prro casing in the name there) the application entry point?
If not then you've got two calls to Application.Run, which in turn sets up 2
messag epumps, and then that's going to caus esome problems because the
messages for Main (like WM_PAINT) are going to get eaten by the second
message pump and likely never get dispatched to the actual intended target.

An app typically should have only one call to Application.Run. There are
reasons to have 2 (and a splash screen sometimes is that reason) but they
should alwasy be sequential - never nested.
 
B

BrianP

Is startSplash (prro casing in the name there) the application entry point?
If not then you've got two calls to Application.Run, which in turn sets up 2
messag epumps, and then that's going to caus esome problems because the
messages for Main (like WM_PAINT) are going to get eaten by the second
message pump and likely never get dispatched to the actual intended target.

An app typically should have only one call to Application.Run. There are
reasons to have 2 (and a splash screen sometimes is that reason) but they
should alwasy be sequential - never nested.

Thanks for your reply.

No, startSplash is not the application entry point. That is in the
FormMain class :

static void Main()
{
Application.Run(new FormMain());
}

So how should I be doing this? And where can I go to learn more about
Application.Run, Application.DoEvents, message pumps, etc.?
 
G

Guest

Thanks for your reply.

No, startSplash is not the application entry point. That is in the
FormMain class :

Yeah, that's what's killing you then. You need to shuffle things around so
that you start one form (probably Main) and then have it create the splash
form while remaining hidden.
So how should I be doing this? And where can I go to learn more about
Application.Run, Application.DoEvents, message pumps, etc.?

I've never seen a decent treatment of it. It basically requires an
understanding of how Windows messages get sent and dispatched. A reasonable
way to figure that out is to look at the Application2.Run method I wrote in
the OpenNETCF SDF (it's there is the old, free 1.x sources too) and see how
Run actually works, but it's just a standard Windows message pump.

-Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top