Implementation of Flash Screen Graphics stunt Effects

Source: Internet
Author: User

 

 

Flash screens are often used in actual program development. If it takes some time to initialize the program, it is more necessary to design the pop-up screen. This will not only make your program beautiful, but also write your version information on it. There are many advantages. There is a splash screen component in the VC ++ 6.0 component library that can be added to the program.

A pop-up screen is actually a window, and its base class is CWnd. It is no different from a normal window, except that the window is displayed at the beginning. Use the Class Wizard to generate a new class whose base class is CWnd. Add the following variables to the new class.

 

CDC MemDC;// Create a memory DC

BITMAP bm;// Create a bitmap Structure Variable

CBitmap m_bitmap;// Create a bitmap object

CBitmap * old_bitmap;// Create a bitmap object pointer

Import a bitmap to a resource. The color can be greater256 colors, but the bitmap above 256 cannot be edited in VC. Initialize the constructor. M_bitmap.LoadBitmap (IDB_BITMAP1); // copy the resource bitmap

M_bitmap.GetBitmap (& bm); // obtain the size information in the bitmap structure.

And # include "resource. h" in the header file of the class. Otherwise, the error IDB_BITMAP1 is not defined during compilation. Then add a function CreatLjxWnd () to the class to generate a window. Add the following code:CreateEx (0,

AfxRegisterWndClass (0, AfxGetApp ()-> LoadStandardCursor (IDC_ARROW), // registration class

"Animatesplash", // window title

WS_POPUP, // The window is pop-up

0, 0, bm. bmWidth, bm. bmHeight, // create a window with the same size as the bitmap

NULL,

NULL,

NULL );

In this case, we can display the bitmap in the window. There are many special effects, such as fade in and translucent. Here we use the random block method. The principle is to divide the bitmap data in the memory device context object (such as MemDC) into one hundred groups of data in the aspect and aspect ten equal portions, then, a group of the one hundred sets of data is randomly retrieved and displayed to the corresponding location of the bitmap to be displayed in the target device (such as ClientDC) until all the one hundred sets of data are displayed. We added the WM_PAINT message, and vc ++ automatically generated the corresponding function to respond to the message. The stunt display code is also executed in this function. Add code to the function: MemDC. CreateCompatibleDC (NULL); // create a dc-compatible memory DC for bitmap placement.

Old_bitmap = MemDC. SelectObject (& m_bitmap); // select the created bitmap into the memory DC.

// Random block image display stunt Algorithm

Int I, j, stepx, stepy, dispnum, x, y;

Int ljx [20] [20];// Array records the displayed data groups

For (I = 0; I <20; I ++)

For (j = 0; j <20; j ++)

Ljx [I] [j] = 0;

Stepx = bm. bmWidth/20;

Stepy = bm. bmHeight/20;

Srand (unsigned) time (NULL ));

Dispnum = 0; // record the number of displayed data groups

While (1 ){

X = rand () % 20;

Y = rand () % 20;

If (ljx [x] [y]) // if it is 1, it is displayed and the loop jumps out.

Continue;

Ljx [x] [y] = 1; // display, set to 1

Dc. StretchBlt (x * stepx,// The logical abscissa of the target device

Y * stepy,// Logical ordinate of the target device

Stepx,// Display the pixel width of a bitmap

Stepy,// Display the pixel height of a bitmap

& MemDC,// Bitmap memory device object

Related Article

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.