How to enable the fade-in and fade-out startup screen in VC

Source: Internet
Author: User
One day, I tried to fade in and out the startup screen, so I went to google for a long time, but it was fruitless. But I understand the function of AnimiateWindow. Okay, let's get started. 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 ).

Reference content is as follows:

# 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:

Reference content is as follows:

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.

Reference content is as follows:

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:

Reference content is as follows:

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:

Reference content is as follows:

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:

Reference content is as follows:

Void CSplashWnd: OnTimer (UINT nIDEvent)
{
KillTimer (1); // disable timer 1
PostMessage (WM_CLOSE, 0, 0); // send the Close Window Information
}

Isn't it very easy? I think it is complicated to fade in and out the bitmap and window. I just learned VC and can't understand it. I had to come up with this simple method.

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.