VC
中用简易方法实现淡入淡出的启动画面
一日心血来潮,想给启动画面来个淡入淡出,于是去谷歌
(google)
查了半天,无果。但知道了
AnimiateWindow
这个函数。好吧
,让我们开始吧。首先,请在需要淡入淡出
窗口
的
cpp
文件或者
stdafx.h
加入下列代码
(
注意要加在
#include
前面哦,否则没有作用哦
)
。
#undef WINVER // 取消原有版本定义 , 重新定义版本
#define WINVER 0x5000 // 为了使 AnimateWindow 函数可用
#include <afxwin.h>
然后在相关文件分别加入 OnCreate,OnClose,OnEraseBkgnd 和 OnTimer 消息函数。记得在相关构析函数内加入 :
SetTimer(1, 3000, NULL); // 设定定时器 1, 定时 3 秒
OnCreate 消息函数里添加淡入窗口或者背景位图代码
BOOL CSplashWnd::OnCreate(LPCREATESTRUCT lpcs)
{
CenterWindow(); // 窗口位于屏幕中心
AnimateWindow(GetSafeHwnd(), 500, AW_BLEND); // 淡入图片 0.5 秒
return true;
}
OnClose 消息函数是添加淡出窗口或背景位图代码:
void CSplashWnd::OnClose()
{
AnimateWindow(GetSafeHwnd(), 500, AW_BLEND | AW_HIDE); // 淡出图片 0.5 秒
CWnd::OnClose();
}
OnEraseBkgnd 消息函数是添加背景 位图 :
BOOL CSplashWnd::OnEraseBkgnd(CDC *pDC)
{
DDB mSplashBitmap;
mSplashBitmap.DisplayDDB(pDC, IDB_SPLASH); // 显示位图资源 IDB_SPLASH
return true;
}
OnTimer 消息函数是添加定时关闭代码:
void CSplashWnd::OnTimer(UINT nIDEvent)
{
KillTimer(1); // 关闭定时器 1
PostMessage(WM_CLOSE, 0, 0); // 发送关闭窗口信息
}
#undef WINVER // 取消原有版本定义 , 重新定义版本
#define WINVER 0x5000 // 为了使 AnimateWindow 函数可用
#include <afxwin.h>
然后在相关文件分别加入 OnCreate,OnClose,OnEraseBkgnd 和 OnTimer 消息函数。记得在相关构析函数内加入 :
SetTimer(1, 3000, NULL); // 设定定时器 1, 定时 3 秒
OnCreate 消息函数里添加淡入窗口或者背景位图代码
BOOL CSplashWnd::OnCreate(LPCREATESTRUCT lpcs)
{
CenterWindow(); // 窗口位于屏幕中心
AnimateWindow(GetSafeHwnd(), 500, AW_BLEND); // 淡入图片 0.5 秒
return true;
}
OnClose 消息函数是添加淡出窗口或背景位图代码:
void CSplashWnd::OnClose()
{
AnimateWindow(GetSafeHwnd(), 500, AW_BLEND | AW_HIDE); // 淡出图片 0.5 秒
CWnd::OnClose();
}
OnEraseBkgnd 消息函数是添加背景 位图 :
BOOL CSplashWnd::OnEraseBkgnd(CDC *pDC)
{
DDB mSplashBitmap;
mSplashBitmap.DisplayDDB(pDC, IDB_SPLASH); // 显示位图资源 IDB_SPLASH
return true;
}
OnTimer 消息函数是添加定时关闭代码:
void CSplashWnd::OnTimer(UINT nIDEvent)
{
KillTimer(1); // 关闭定时器 1
PostMessage(WM_CLOSE, 0, 0); // 发送关闭窗口信息
}