1. Create an SDI or MDI project.
2. New or import a bitmap for IDB 桽 PLASH.
3. Depends a subclass called CSPlashWnd from the CWND class and add two protection member variables:
CBITMAP M 梑 ITMAP; // Initial picture bitmap
Static CSPlashWnd C 梡 SplashWnd;
/ / Pointer to the initial screen window
C 梡 SplashWnd is a static member variable, which should begin with the implementation document (.cpp) of the class:
CSPLASHWND CSPLASHWND :: C 梡 SplashWnd;
4. Add a static public member function showSplashScreen to the CSPlashWnd class. This function
Will be called by the main frame window:
Void CsplashWnd :: ShowsplashScreen (CWND PANTWND)
{// This function passed the parameter is the main frame window
IF (c 梡 splashwnd! = null) return;
C 梡 splashwnd = new csplashwnd;
IF (! c 梡 splashwnd-> create (pparentWnd))
// Create an initial screen window
Delete C 梡 SplashWnd;
Else
C 梡 SplashWnd-> UpdateWindow ();
/ / Display the initial screen window
}
5. Edit the CREATE function called in the showSplashScreen function (Protection member function):
Bool csplashWnd :: Create (CWND PANTWND) {
IF (! m 梑 itmap.loadbitmap (idb 桽 plas))
// Load bitmap
Return False;
Bitmap BM;
M 梑 ITMap.GetBitmap (& BM);
Return Createex (0, AFXREGISTERWNDCLASS (0, AFXGetApp () -> LoadStandardCursor (IDC 梂 AIT)), NULL, WS 桺 OPUP | WS?
Visible, 0, 0, Bm.BmWidth, BM.Bmheight, PparentWnd-> GetsafehWnd (), NULL);
// Create a child window for the main frame window
}
6. CreateEx will call the oncreate function for the initialization of the window, and overload this function:
INT CSPLASHWND :: OnCreate (lpcreatestruct lpcreatestruct)
{
IF (CWnd :: OnCreate (lpcreatestructure) == - 1)
Return -1;
CenterWindow ();
SetTimer (1,1000, null); // Time Control
Return 0;
}
7. Send a WM 桺 AINT message when the window is displayed, so we miss this message:
Void csplashwnd :: onpaint ()
{
CPAINTDC DC (this);
CDC DCIMAGE;
IF (! DCIMAGE.CREATECOMPALEDC (& DC)) Return;
Bitmap BM;
M 梑 ITMap.GetBitmap (& BM);
CBitmap PoldbitMap = DCIMAGE.SELECTOBJECT (& M 梑 ITMAP);
Dc.Bitblt (0, 0, Bm.Bmwidth, Bm.Bmheight, & DCImage, 0, 0, Srccopy);
DCIMAGE.SELECTOBJECT (POLDBITMAP);
}
8. Mapping the WM 桾 IMER message to destroy the window after a certain period of time:
Void csplashWnd :: ONTIMER (uint nidevent) {
DestroyWindow (); // Destroy the initial screen window
AFXGETMAINWND () -> UpdateWindow ();
// Refresh the main frame window
}
9. To prevent memory overflow, the window is destroyed to release the CSPLASHWND object, for this, we overload
Virtual function Postncdestroy, this function is called after the window is destroyed:
Void csplashWnd :: Postncdestroy ()
{
DELETE THIS;
}
10. Finally, in order to display the initial screen, we last tune the oncreate function in the main frame window.
With the showsplashscreen function, of course don't forget to include the csplashwnd's header file:
CSPLASHWND :: ShowsplashScreen (this);
The above program is debugged in VC 6.0.