![]() |
#2
panfeng4152015-05-07 16:19
![]() class MemDC : public CDC { CSize m_size; public: MemDC(void); ~MemDC(void); //加载进程内位图的构造函数 MemDC(UINT nBitmap,CDC* pDC=NULL) { LoadBitmap( nBitmap,pDC); } //加载进程外位图的构造函数 MemDC(LPCWSTR szFile, CDC* pDC=NULL) { LoadBitmap( szFile, pDC); } //创建空白位图的构造函数 MemDC(int cx, int cy,CDC* pDC=NULL) { Create( cx, cy, pDC); } int GetWidth() {return m_size.cx;} int GetHeight() {return m_size.cy;} BOOL DeleteDC() { if (!GetSafeHdc()) return FALSE; CBitmap *pBitmap=GetCurrentBitmap(); if(pBitmap) pBitmap->DeleteObject(); return CDC::DeleteDC(); } //创建空白位图 BOOL Create(int cx, int cy,CDC* pDC=NULL) { CBitmap bmp; if (!bmp.CreateCompatibleBitmap(pDC,cx,cy)) return FALSE; m_size.cx=cx; m_size.cy=cy; CreateCompatibleDC(pDC); SelectObject(&bmp); return TRUE; } //进程内资源加载 BOOL LoadBitmap(UINT nBitmap,CDC* pDC=NULL) { CBitmap bmp; if (!bmp.LoadBitmap(nBitmap)) return FALSE; BITMAP bm; bmp.GetBitmap(&bm); m_size.cx=bm.bmWidth; m_size.cy=bm.bmHeight; CreateCompatibleDC(pDC); SelectObject(&bmp); return TRUE; } //进程外位图图片加载 BOOL LoadBitmap(LPCWSTR szFile, CDC* pDC=NULL) { HBITMAP hBitmap = (HBITMAP)LoadImage(NULL,szFile,IMAGE_BITMAP, 0,0,LR_LOADFROMFILE); if (!hBitmap) return FALSE; BITMAP bm; GetObject(hBitmap,sizeof(bm),&bm); m_size.cx=bm.bmWidth; m_size.cy=bm.bmHeight; CreateCompatibleDC(pDC); SelectObject(hBitmap); return TRUE; } }; |

void CDGrainDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
static int i =5;
CString str;
str.Format(L"\%d0.bmp",i);
MemDC mdc(str);
CClientDC dc(this);
dc.BitBlt(10,10,mdc.GetWidth(),mdc.GetHeight(),&mdc,0,0,SRCCOPY);
if (++i>12)
i=5;
CDialogEx::OnTimer(nIDEvent);
}
{
// TODO: Add your message handler code here and/or call default
static int i =5;
CString str;
str.Format(L"\%d0.bmp",i);
MemDC mdc(str);
CClientDC dc(this);
dc.BitBlt(10,10,mdc.GetWidth(),mdc.GetHeight(),&mdc,0,0,SRCCOPY);
if (++i>12)
i=5;
CDialogEx::OnTimer(nIDEvent);
}
[ 本帖最后由 panfeng415 于 2015-5-7 16:18 编辑 ]