Produced initial screen with VC

xiaoxiao2021-03-06  44

In the previous "computer studio", we have introduced the use of VB, VFP production initial screen, then,

How to draw software initial pictures in VC? This article will detail its design steps.

1. Create an SDI or MDI project.

2.  New or import a bitmap for IDB-SPLASH.

3.  Depends a subclass called CSPlashWnd from the CWND class and add two protection member variables:

CBitmap m-bitmap; // initial picture bitmap

Static csplashwnd c-psplashwnd;

/ / Pointer to the initial screen window

C-psplashWnd is a static member variable, and should begin with the implementation document (.cpp) of the class:

CSPLASHWND  CSPLASHWND :: C-PSPlashWnd;

4. Add a static public member function to the CSPlashWnd class showSplashScreen, this letter

Number 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-psplashwnd! = null) return;

C-psplashWnd = new csplashwnd;

IF (! c-psplashwnd-> create (pparentwnd))

// Create an initial screen window

Delete c-psplashwnd;

Else

C-psplashWnd-> 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-bitmap.loadbitmap (idb-splash))

// Load bitmap

Return False;

Bitmap BM;

M-bitmap.getbitmap (& BM);

Return Createex (0, AFXREGISTERWNDCLASS (0, AFXGetApp () -> LoadStandardCursor (IDC-WAIT)), NULL, WS-POPUP | 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-PAINT 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-bitmap.getbitmap (& BM);

CBitmap PoldbitMap = DCIMAGE.SELECTOBJECT (& M-bitmap);

Dc.Bitblt (0, 0. Bm.Bmwidth, Bm.Bmheight, & DCImage, 0, 0, srcopy); DCIMAGE.SELECTOBJECT (POLDBITMAP);

}

8. Map the WM-TIMER 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:

Ostncdestroy ()

{

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.

转载请注明原文地址:https://www.9cbs.com/read-55554.html

New Post(0)