How to create the startup screen of four VC programs

Source: Internet
Author: User

The startup screen can be used to reduce the boring feeling of waiting for the program to load (especially for some large programs); the second is to display the software name, copyright, and other prompts. How can I use VC ++ to create an app startup screen? This article provides four methods, the first three for document-based applications, and the fourth for dialog box-based applications.

1. Use the splash screen component in the component library to implement

(1) use Photoshop to create a startup image and save it in BMP format.

(2) Use Appwizard to create a single-document-based project splash.

(3) Insert bitmap resources into resources

Open the resource editor of VC ++, right-click the resources folder, select the import command, and insert the created bitmap. If the bitmap has more than 256 colors, a dialog box is displayed, prompting that the bitmap has been inserted but cannot be displayed in the bitmap editor. OK. Change the bitmap ID to idb_splash.

(4) Add the splash screen control.

① Select "project"/"add to project"/"conponents and controls" to open the dialog box, and double-click "Visual C ++ conponents" in the list box, select the "splash screen" control and click "insert ".

② Confirm or modify the class name and bitmap resource ID, and click OK.

③ Compile and connect. The beautiful startup screen is displayed.

(5) If you need to change the stop time of the startup screen, modify the second parameter of the settimer () function. The default value is 750 milliseconds. Location of the function:

Int csplashwnd: oncreate (maid)
{
...
// Set a timer to destroy the splash screen.
Settimer (1,750, null); // modify the second parameter to adjust the screen stay time
Return 0;
}

2. display the startup screen in the stateless dialog box.

(1) Use Appwizard to create a single-document-based project splash.

(2) import the image used as the startup screen and change its ID to idb_splash.

(3) create a dialog box to add a startup screen.

Create a dialog box in the resource and create a dialog box class csplashdlg. Add a picture control in the dialog box, open its "properties" dialog box, select general, select bitmap from the type drop-down list, and select the previously imported bitmap resource id value from the image drop-down list: idb_splash.

(4) modify the Display Effect of the dialog box

① Adjust the dialog box size, remove two automatically generated buttons, and remove the title bar selection from the "styles" page of "properties;

② Select the image, adjust the size to adapt to the Editable area of the dialog box, and modify the "styles" of its "properties"

Center it.

(5) Add the code for creating, displaying, and destroying the modeless dialog box in the oncreate () function of the cmainframe class.

# Include "splashdlg. H" // Add it to the header file call location of the mainfrm. cpp File
Int cmainframe: oncreate (maid)
{
Csplashdlg * DLG = new csplashdlg (this );
DLG-> Create (csplashdlg: IDD, this); // create dialog box
Dlg-> ShowWindow (SW_SHOW); // display the dialog box
Dlg-> UpdateWindow ();
Sleep (2000); // The duration of the screen display, in milliseconds
...
Dlg-> DestroyWindow (); // destruction dialog box
Return 0;
}

3. Display and destroy the startup screen by sending a message

① Repeat steps 1 to 4 in method 2.

② Use Class Wizard to add the message response function WM_TIMER for the CMainFrame Class.

③ Modify the code and send the WM_TIMER message to start and destroy the startup screen.

1) define variables of the dialog box class

Add # include "SplashDlg. h" to the MainFrm. h header, and add the public variable CSplashDlg * Splash to the definition of the CMainFram class.

2) Add the corresponding function code of the timer message

Void CMainFrame: OnTimer (UINT nIDEvent)
{
If (Splash-> IsWindowVisible ()){
Splash-> SetActiveWindow (); // set the startup screen to the current active window.
Splash-> UpdateWindow ();
Sleep (2000); // modify the screen display time.
Splash-> SendMessage (WM_CLOSE); // close the dialog box
}
Else {
SetActiveWindow ();
KillTimer (1); // clear the WM_TIMER event
}
}

3) modify the framework generation function OnCreate ()

Int CMainFrame: OnCreate (maid)
{
SetTimer (, NULL); // Add the WM_TIMER event with ID 1
Splash = new CSplashDlg ();
Splash-> Create (IDD_DIALOG1 );
Splash-> ShowWindow (SW_SHOW );
...
}

4. Create a dialog box-based application startup Screen

None of the above methods can bring a startup screen to a dialog box-based application. The following describes a method to bring a startup screen to a dialog box-based application. There is no main framework for dialog box-based applications, so you cannot use the previous methods to create a startup screen. However, we can port the startup screen file created in the method, and then modify the program.

(1) create a project Splash based on a single document with reference to method 1.

(2) create a project Cover based on the dialog box.

(3) file migration

① Copy the Splash1.cpp and Splash1.h Files from the Splash project created in method 1 to the Cover project and add them to Source Files and Header Files respectively;

② Import the bitmap file to the project resource and change the ID to IDB_SPLASH.

(4) modify the code to call the startup Screen

① Add the initinstance () function code of the ccoverapp

# Include "splash1.h" // Add it to the header file call location of the cover. cpp File
Bool ccoverapp: initinstance ()
{
Ccommandlineinfo using info;
Parsecommandline (partition info );
Csplashwnd: enablesplashscreen (effecinfo. m_bshowsplash );
...
}

② Use classwizard to add the oncreate () function to the ccoverdlg class of the dialog box, and modify the code # include "splash1.h" // Add it to the header file calling location of the coverdlg. cpp File

Int ccoverdlg: oncreate (maid)
{
...
Csplashwnd: showsplashscreen (this); // display the startup Screen
...
}

Note: Modification of the stop time of the startup screen is the same as method 1.

5. Conclusion

As mentioned above, the use of the startup screen can give users a strong impression and play a good role in publicity. The above programs have been debugged in Visual C ++ 6.0 and Windows2000.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.