Link to home
Start Free TrialLog in
Avatar of stevenc317
stevenc317

asked on

How do I show a splash screen??

When my program is loading how do I have a splash screen (with an image) come up for a few seconds (as everything else is loading)??
Avatar of galkin
galkin

If you are programming with VC++ you can add splash screen using component galerry. Go to Project->Add To Project->component and Controls. Choose "Developer Studio Components" and then "Splash screen". The necessary code will be automatically added to your project so your responsibility is only to change splash bitmap.
Avatar of stevenc317

ASKER

Sorry I am using Borland C++ Builder v1.0 for Win95
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
please tell me the codes that i need, I am a very basic C++ prgrammer.  I have Borland C++ Builder v1.0 for Win 95 (that is the newest version)
well there is a lot involved here.  Do you have specific questions?  For example, so you know how to create a window? (If not then you are probably asking that wrong question because your application should handle windows long before it handles splash screens.) Do you know how to add a bitmap to the resources?  Do you know how to load and display a bitmap?  I can help you with this stuff, but it is the core of windows programming and I don't want to waste time explaining things that you already know.
Good point.  I just need the following.
1) How do I have the window "SplashScreen1" come up as soon as the app loads??

2) How do I have "SplashScreen1" close after 5 seconds???

thanks
(1)  You can't display the splash screen when the program loads.  You have to wait until you get cntrol from windows.  How long you have to wait is going to depend.  I'll sketch a couple of possibilities.  

If the splash screen is created by the application (rather than a Dll), you could just put code at the start of WinMain() to create the window then do you program initialization stuff.  

However if your program does a lot of initialization stuff using global objects.  These objects will be initialized before WinMain() is called so there will be a noticable wait before the splash screen appears.  If that is the case, you can create a class that creates a splash screen in its constructor.  Then just create a global object of this class at the start of your program (global objects are initialized from the top of the file (translation unit) to the bottom, that is a C++ requirement.)  This causes the splash screen to display before any other objects are initalized and before winmain() is called.

If your exe uses Dll's that take a long time to initialize, then you may still have a long lag before the screen appears.  This is harder to fix perfectly.  But in this case you can create a Dll that displays the splash screen when it attaches to a process.  The Dll will be attached to you process even before your globals are initialized.  However you can't force the Dll to be attached before other Dll's.  However, if you've written all (or at least some) of the other Dll's. You can make them use the splash screen Dll so it will load first.  It will have to use a semaphore to prevent the creation of multiple splah screens in this case.


(2)  I would display the splash screen during initialization, regardless of how long it takes--unless you know you have minimum initialization to perform.

You can use SetTimer() to set a timer that will notify the splash screen window when it should close.  The window will receive a WM_TIMER message when the timer expires.  The handler for this message can close the window and destroy the timer (KillTimer()).

You could make the window be destroyed when two conditions are satisfied.  (1) it has received the timer notification.  (2) the application has notified it that initialization is complete.

I can give more details on any of these possiblilites if you need them.  I just don't want to elaborate on all of them.  If you're not sure what technique is best, you might want to try describing you application here.  (In terms of complexity, initialization requirements, and ExE/Dll design and usage.)
Ok for question one I think I am going to need to post my source code.  For question two, can you tell me the codes to close the window (I found out about the time, so don't worry about that part).

thanks
To close a window you just use DestroyWindow().  

Does that answer your question?  If not ask again, I'm having trouble understanding exactly what you are asking.  
thanks