本工程使用MFC框架,制作镂空图的显示和刷新。
MFC创建人物行走动画C++
MFC创建人物行走动画C++
因为图片扣的不好的原因,会有边框。
下面是代码:

#include <afxwin.h>


class CMyWnd :public CFrameWnd {
private:
	CDC * cdc;
	CBitmap* mbmp[12];
	CBitmap* sbmp[12];
	CRect rect;
	char m_szFileName[20];
	char s_szFileName[20];
	int order = 0;
	int pos = 1000;
public:
	
	CMyWnd() {

		Create(NULL, "我的窗口");
		CClientDC dc(this);
		GetClientRect(rect);
		cdc = new CDC;
		cdc->CreateCompatibleDC(&dc);
		for (int i = 0; i < 12; i++)
		{
			mbmp[i] = new CBitmap;
			sbmp[i] = new CBitmap;
			sprintf_s(m_szFileName, "ER0%dM.bmp", (i + 1));
			mbmp[i]->m_hObject = LoadImage(NULL, m_szFileName,
				IMAGE_BITMAP, 200, 300, LR_LOADFROMFILE);
			sprintf_s(s_szFileName, "ER0%dS.bmp", (i + 1));
			sbmp[i]->m_hObject = LoadImage(NULL, s_szFileName,
				IMAGE_BITMAP, 200, 300, LR_LOADFROMFILE);
		}
		
	};
		
	
	DECLARE_MESSAGE_MAP()
	afx_msg void OnPaint();
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
};

CMyWnd *pf;
UINT myProc(LPVOID pParam) {
	while (1) {
		pf->Invalidate();
		Sleep(200);
	}
}



class CMyApp :public CWinApp {
	BOOL InitInstance();

};
BOOL CMyApp::InitInstance() {
	pf = new CMyWnd();

	pf->ShowWindow(m_nCmdShow);
	pf->UpdateWindow();
	this->m_pMainWnd = pf;
	AfxBeginThread(myProc, NULL);
	return TRUE;
}
CMyApp myApp;BEGIN_MESSAGE_MAP(CMyWnd, CFrameWnd)
ON_WM_PAINT()

ON_WM_KEYDOWN()
END_MESSAGE_MAP()


void CMyWnd::OnPaint()
{
	CPaintDC dc(this);
	cdc->SelectObject(mbmp[order]);
	dc.BitBlt(pos, rect.bottom/2, 200, 300, cdc, 0, 0, SRCAND);
	cdc->SelectObject(sbmp[order]);
	dc.BitBlt(pos, rect.bottom / 2, 200, 300, cdc, 0, 0, SRCPAINT);
	order = (11 == order) ? 0 : ++order;
	pos -= 10;
	if (pos <= 100) {
		pos = 1000;
	}
}




void CMyWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if (nChar == VK_RIGHT) {
		pos += 10;
	}
	if (nChar == VK_LEFT) {
		pos -= 10;
	}
	CFrameWnd::OnKeyDown(nChar, nRepCnt, nFlags);
}

希望对你们有帮助,学习一下MFC也会有用的哦!

相关文章:

  • 2022-01-01
  • 2021-12-21
  • 2021-11-29
  • 2021-11-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-04-01
  • 2022-12-23
  • 2021-12-17
  • 2022-12-23
相关资源
相似解决方案