Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating a Splash Screen

Status
Not open for further replies.

cyprus106

Programmer
Apr 30, 2001
654
0
0
I am having the absolute DARNDEST time finding code to create a splash screen in builder!!! I've done search after search and am getting awfully frusterated. Any help??

Cyprus
 
Let me explain this more effeciently:
I have this code currently, that I pieced together myself. And it's giving me all sorts of wierd exceptions and whatnot at funly times, especially when I close the program.

By the way I AM DEAD DESPERATE. I need to send this code to a potential employer today and this is the last part and I cannot find any material on this on the internet or in my books and the clock is ticking... eek!





/*initial code... */

#include "loadscreen.h"
#include "errorlog.h"
//---------------------------------------------------------------------------
USEFORM("main.cpp", MainForm);
USEFORM("LoadScreen.cpp", LoadScreenForm);
USEFORM("NewReservation.cpp", NewReservationForm);
USEFORM("NewClient.cpp", Form1);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{

try
{

{

bool showStartupForm = false;

try
{
/* there's some misc code here... */
showStartupForm = true;

}
catch (...)
{
showStartupForm = true;
}

Application->Initialize();

/* this means it needs to show the startup screen*/
if (showStartupForm)
{
Application->ShowMainForm = false;
LoadScreenForm = new TLoadScreenForm(Application);
LoadScreenForm->Show();
}

Application->CreateForm(__classid(TMainForm), &MainForm);
Application->Run();

}

}
catch (Exception &exception)
{
Application->ShowException(&exception);
}

Cyprus
 
Here's how I did it. The splash form is named TSplashForm (very original). The form itself only has a picture and a timer. When the timer is finished, the form closes.

The main application is named Cost to Produce Veneer and it is fairly large but for the splash screen, I only modified the main C++ form as you did. Note however, that I create the form instead of just calling it. I suspect that your errors deal with the fact that the form hasn't been "created" yet.
Code:
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
    // Run program only once so create a mutex
	HANDLE mutex;
    try
    {
		const char mutexname[] = "CostToProduceVeneer";
		// See if mutex already exists
		mutex = OpenMutex (0, false, mutexname);
		if (mutex == NULL)
		{
			// Mutex is NOT here
			// OK to create mutex and run application
			mutex = CreateMutex(NULL, true, mutexname);
		}
		else
		{
			// Mutex is running so cannot open another instance of program
			ShowMessage("Application Already Running");
			return 0;
		}

        Application->Initialize();
        // Display splash screen
		SplashForm=new TSplashForm(Application);
		SplashForm->Show();
		SplashForm->Update();
       // Done with splash screen
        Application->Title = "Cost To Produce Veneer";
        Application->CreateForm(__classid(TCTPVmainform), &CTPVmainform);
        Application->Run();
    }
    catch (Exception &exception)
    {
        Application->ShowException(&exception);
    }
	ReleaseMutex(mutex);
    return 0;
}

The code in the splash screen is very basic. I set the timer's event, I create a captionless form, and when it's all over, I free the memory allocated to the form.

Code:
//---------------------------------------------------------------------------
void __fastcall TSplashForm::SplashTimerTimer(TObject *Sender)
{
    Close();    
}
//---------------------------------------------------------------------------
void __fastcall TSplashForm::CreateParams(TCreateParams &Params)
{
    TForm::CreateParams(Params); // Base
    Params.Style &= ~WS_CAPTION; // then remove caption
}
//----------------------------------------------------------------------------
void __fastcall TSplashForm::FormClose(TObject *Sender,
      TCloseAction &Action)
{
    Action = caFree;    
}
//---------------------------------------------------------------------------

See if any of this helps.



James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
> I need to send this code to a potential employer today
And then what?

Compared to what work you'll actually be asked to do, employer entrance "exams" are just simple toys to weed out all the wannabies. Anyone with any credible competence should just walk through them.

Imagine you get the job, what are you going to do when presented with your first assignment? Come back here for more help?

If you pass the "exam", and then can't do the work, you'll have some explaining to do.

If they find out you handed in someone else's work, you'll have a LOT of explaining to do, and you can wave goodbye to any kind of reference.


--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
2ffat I don't know what I'd do without you! I appreciate the helpful (and PROMPT!) input! I'm still hitting a big snag: I threw in the CreateParams, (shouldda thought about that one) but when I close the application, it throws me into Forms.hpp and gives me an invalid pointer operation, and subsequently "External exception C00000025"

I have tried every which thing I can think of. Any ideas?

Cyprus
 
I'm not familiar with that exception. If you comment out or remove the CreateParams section, does the error go away?

If so, you might be able to set up the form's parameters at design time to do the same thing.



James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
I appreciate the concern, Salem. We all have our areas of expertise, and mine, regrettably, is not splash screens... or GUIs, that much, for that matter. However, I would like to make it shine with some graphics... Hence the problem. Being about 3:50 in the morning when I posted this didn't help either.




Cyprus
 
Hi,

To to that:
1- you create a normal form
2- you set BorderStyle: none
3- BorderWidth = 0
4- add in the form a TImage aligned to TClient
5- put the splash image into the TImage
6- In WinMain, add:
SplashForm->Show();
SplashForm->Repaint();
7- In your app, put a timer with 3..6 seconds
8- Into the timer react func:
SplashForm->Hide();
SplashForm->Close();
delete SplashForm;

It should work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top