怎样实现动画背景旗帜
以下代码是关于用类CmdiMainClient来显示动画背景旗帜的一个例子。原理是很简单的,我们只需要一系列连续的位图,并且让它连续显示。在这个例子中你可以用鼠标的右键来开始/停止这个动画,如果点左键的话,就可以显示一个子窗口,来保持动画是继续。为了你的方便,你可以把代码直接从浏览器中拷贝下去,并且插到你的代码中就行了。以下是代码:
#include "stdafx.h"
#include "banner.h"
#include "mainfrm.h"
#include "resource.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMdiMainClient
CMdiMainClient::CMdiMainClient(): m_sizeClient(0, 0)
{
VERIFY(m_bmpBackGround.LoadBitmap(IDB_BCKGRD));
ASSERT(m_bmpBackGround.GetSafeHandle());
VERIFY(m_bmpBackGround2.LoadBitmap(IDB_BITMAP0));
ASSERT(m_bmpBackGround2.GetSafeHandle());
BmpLoaded = 1;
StopRotation = FALSE;
}
CMdiMainClient::~CMdiMainClient()
{
if (m_bmpBackGround.GetSafeHandle())
m_bmpBackGround.DeleteObject();
if (m_bmpBackGround2.GetSafeHandle())
m_bmpBackGround2.DeleteObject();
}
BEGIN_MESSAGE_MAP(CMdiMainClient, CWnd)
//{{AFX_MSG_MAP(CMdiMainClient)
// NOTE - the ClassWizard will add and remove mapping macros here.
ON_WM_TIMER()ON_WM_ERASEBKGND()ON_WM_RBUTTONDOWN()ON_WM_LBUTTONDOWN()ON_WM_SIZE
()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMdiMainClient message handlers
BOOL CMdiMainClient::OnEraseBkgnd(CDC *pDC)
{
// Erase only the area needed
CRect rect;
GetClientRect(&rect);
SetTimer(0, 300, NULL);
// Place the bitmap
BITMAP bm;
CDC dcMem;
BITMAP bm2;
CDC dcMem2;
- 上一篇:在对话框中动态显示位图
- 下一篇:Visual C++中建立滚动视窗