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!