VC simple fade-in and fade-out effect

Source: Internet
Author: User

First, add the following code to the CPP file or stdafx. H that needs to fade in and out of the window (note that it must be added before # include; otherwise, it will not work ).

# UNDEF winver // undefines the original version and redefines the version
# Define winver 0x5000 // to make the animatewindow function available

# Include <afxwin. h>


Then, add the oncreate, onclose, onerasebkgnd, and ontimer message functions to the relevant files. Remember to add the following content to the relevant destructor:

Settimer (1, 3000, null); // sets the timer to 1 and the timer to 3 seconds.


Add the fade-in window or background bitmap code to the oncreate message function.

Bool csplashwnd: oncreate (lpcreatestruct lpcs)
{
Centerwindow (); // The window is located in the center of the screen
Animatewindow (getsafehwnd (), 500, aw_blend); // fade-in image for 0.5 seconds

Return true;
}


The onclose message function is used to add the fade-out window or background bitmap code:

Void csplashwnd: onclose ()
{
Animatewindow (getsafehwnd (), 500, aw_blend | aw_hide); // fades out the image for 0.5 seconds

Cwnd: onclose ();
}


The onerasebkgnd message function is to add a background bitmap:

Bool csplashwnd: onerasebkgnd (CDC * PDC)
{
DDB msplashbitmap;
Msplashbitmap. displayddb (PDC, idb_splash); // display bitmap resource idb_splash

Return true;
}


The ontimer message function adds the Timed Shutdown code:

Void csplashwnd: ontimer (uint nidevent)
{
Killtimer (1); // disable timer 1
Postmessage (wm_close, 0, 0); // send the Close Window Information
}

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.