Splash windows are used by programmers to occupy users while their program boots. They are buttonless dialog windows which display a message about the program (legal, promotional or entertaining). The dialog appears for a predetermined amount of time then closes itself
Create a splash dialog as a buttonless child dialog in the resource editor. Next create any bitmaps you want to use in your dialog. Remember to number them below 100 so you can display them in a button. In this case I used a borrowed icon. Next create the Borland buttons numbered with the bitmap number plus 1000 and add the text to your dialog.
Create a new dialog class associated with your splash dialog using class expert. You will need to add four functions to this class.
The use of the EvCtrColor to color a window and the CleanupWindow to delete the brush created for it are covered in the discussion of coloring dialogs. In this case the SetupWindow sets the color of the background and then centers the Splash box and sets a timer.
void SplashDlg::SetupWindow ()
{
TDialog::SetupWindow();
// INSERT>> Your code here.
dlgBrush = new TBrush(TColor::White);
SetTimer(1,4000);
TRect scrnRect, dlgRect;
HWND hWnd = GetActiveWindow();
::GetWindowRect(hWnd,&scrnRect);
GetWindowRect(dlgRect);
int xpos = (scrnRect.right - scrnRect.left) / 2 -
(dlgRect.right - dlgRect.left) / 2; //calc splash screen pos
int ypos = (scrnRect.bottom - scrnRect.top) / 2 -
(dlgRect.bottom - dlgRect.top) / 2;
MoveWindow(xpos,ypos,dlgRect.Width(),dlgRect.Height()); //move dialog to center
}
The event timer is created in Class Expert by selecting the WM_TIMER event from the other messages list. When the timer created in SetupWindow sends the message WM_TIMER, our event hander kills the timer then closes the window.
void SplashDlg::EvTimer (uint timerId)
{
TDialog::EvTimer(timerId);
// INSERT>> Your code here.
KillTimer(1);
PostMessage(WM_CLOSE,0,0); //close dialog box
}
The CleanupWindow functions simply deletes the brush created in the SetupWindow command.
The splash window is displayed when the program is initialized, so in an SDI environment must be initialized in the SDIDecFrame::SetupWindow function. Add a pointer to the splash window as a member of type TDialog * to the SDIDecFrame class. Then add this code to the SetupWindow function for this class.
splashDialog = new SplashDlg(this);
splashDialog->Create();
For complete code click here.