A whim, want to start the screen to fade, so to search for a half-day, no fruit. -_-b, but knew Animiatewindow this function. All right, let's get started. ^ ^. First, please add the following code to the CPP file or stdafx.h that you want to fade into the window (note that you need to add it to the front of the #include, otherwise it doesn't work.)
#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秒 oncreate message function Add fade in window or background bitmap code
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 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!