Vc.net to implement splash screen fade in

Source: Internet
Author: User

Looking for a long time did not find the implementation of the start screen to a fade in the code, had to write a, oh, it is good to show you.

#undef WINVER //取消原有版本定义,重新定义版本
#define WINVER 0x5000 //为了使AnimateWindow函数可用

#include <afxwin.h>

The ONCREATE,ONCLOSE,ONERASEBKGND and OnTimer message functions are then added to the related files separately. Remember to include in the associated destructor function:

SetTimer(1, 3000, NULL); //设定定时器1,定时3秒

Add a fade window or background bitmap code to the OnCreate message function:

BOOL CSplashWnd::OnCreate(LPCREATESTRUCT lpcs)
{
CenterWindow(); //窗口位于屏幕中心
AnimateWindow(GetSafeHwnd(), 500, AW_BLEND); //淡入图片0.5秒

return true;
}

The OnClose message function is to add a fading window or a background bitmap code:

void CSplashWnd::OnClose()
{
AnimateWindow(GetSafeHwnd(), 500, AW_BLEND | AW_HIDE); //淡出图片0.5秒

CWnd::OnClose();
}

The ONERASEBKGND message function is to add a background bitmap:

BOOL CSplashWnd::OnEraseBkgnd(CDC *pDC)
{
DDB mSplashBitmap;
mSplashBitmap.DisplayDDB(pDC, IDB_SPLASH); //显示位图资源IDB_SPLASH

return true;
}

The OnTimer message function is to add a timed shutdown code:

void CSplashWnd::OnTimer(UINT nIDEvent)
{
KillTimer(1); //关闭定时器1
PostMessage(WM_CLOSE, 0, 0); //发送关闭窗口信息
}

is not very simple, I see some about the bitmap and the window fade is very complicated, I just learn VC soon, can not understand. Had to come up with this simple method. Have any suggestions and comments welcome everyone to point out!

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.