// movieWnd.cpp : implementation file // //#include "stdafx.h" #include "movie.h" #include "movieWnd.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // movieWnd IMPLEMENT_DYNCREATE(movieWnd, CFrameWnd) int x=0,y=0,i,d,c,xp; movieWnd::movieWnd() { Create(NULL,"¶¯»­"); char ch[8]; for (int i=0;i<4;i++) { for (int j=0;j<4;j++) { sprintf(ch,"%d.%d.bmp",i+1,j+1); bitmap[i][j]=new CBitmap; bitmap[i][j]->m_hObject=LoadImage(NULL,ch,IMAGE_BITMAP,93,100,LR_LOADFROMFILE); } } mdc=new CDC; CClientDC dc(this); mdc->CreateCompatibleDC(&dc); mdc->SelectObject(bitmap[0][0]); dir=0,index=0; } movieWnd::~movieWnd() { } BEGIN_MESSAGE_MAP(movieWnd, CFrameWnd) //{{AFX_MSG_MAP(movieWnd) ON_WM_PAINT() ON_WM_CREATE() ON_WM_TIMER() ON_WM_KEYDOWN() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // movieWnd message handlers void movieWnd::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here dc.BitBlt(0,0,93,100,mdc,0,0,SRCCOPY); // Do not call CFrameWnd::OnPaint() for painting messages } int movieWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here //SetTimer(1,100,NULL); return 0; } void movieWnd::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default CClientDC dc(this); if (dir>=4) { dir=0; } if (index<4) { mdc->SelectObject(bitmap[dir][index]); index++; } else { index=0; dir++; mdc->SelectObject(bitmap[dir][index]); } dc.BitBlt(0,0,93,100,mdc,0,0,SRCCOPY); CFrameWnd::OnTimer(nIDEvent); } void movieWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default CClientDC dc(this); dc.BitBlt(x,y,93,100,mdc,0,0,WHITENESS); if (nChar==VK_DOWN) { y+=20; if (dir==0) { index++; if (index==4) { index=0; } } else { index=0; dir=0; } } if (nChar==VK_UP) { y-=20; if (dir==3) { index++; if (index==4) { index=0; } } else { index=0; dir=3; } } if (nChar==VK_LEFT) { x-=20; if (dir==1) { index++; if (index==4) { index=0; } } else { index=0; dir=1; } } if (nChar==VK_RIGHT) { x+=20; if (dir==2) { index++; if (index==4) { index=0; } } else { index=0; dir=2; } } mdc->SelectObject(bitmap[dir][index]); dc.BitBlt(x,y,93,100,mdc,0,0,SRCCOPY); CFrameWnd::OnKeyDown(nChar, nRepCnt, nFlags); }