c++游戏设计二:反转扑克牌

来源:互联网 发布:netstat命令详解 mac 编辑:程序博客网 时间:2024/06/17 18:34
<span style="font-family: Arial, Helvetica, sans-serif;">#include <afxwin.h></span>
class CMyWnd :public CFrameWnd{private:CDC *m_pmdc[4];CBitmap *m_pbitmap;CString myPath[5];int currentState[4];CRect myRect[4];public:CMyWnd(){Create(NULL,"Second App");CClientDC dc(this);//Initialize the pathmyPath[0]="../image/back.bmp";myPath[1]="../image/q.bmp";myPath[2]="../image/10.bmp";myPath[3]="../image/j.bmp";myPath[4]="../image/joker.bmp";//Intialize the rectmyRect[0].SetRect(50,50,200,250);myRect[1].SetRect(50,350,200,550);myRect[2].SetRect(400,50,550,250);myRect[3].SetRect(400,350,550,550);memset(currentState,0,4);MoveWindow(200,20,600,600);m_pbitmap=new CBitmap;for(int i=0;i<4;i++){m_pbitmap->m_hObject=(HBITMAP)::LoadImage(NULL,myPath[0],              IMAGE_BITMAP, 0,0,LR_LOADFROMFILE);m_pmdc[i]=new CDC;m_pmdc[i]->CreateCompatibleDC(&dc);m_pmdc[i]->SelectObject(m_pbitmap);m_pbitmap->DeleteObject();}}~CMyWnd(){delete m_pbitmap;for(int i=0;i<4;i++){delete m_pmdc[i];}}DECLARE_MESSAGE_MAP()afx_msg void OnPaint();afx_msg void OnTimer(UINT_PTR nIDEvent);afx_msg void OnLButtonUp(UINT nFlags, CPoint point);};class CMyApp:public CWinApp{public:BOOL InitInstance();};BOOL CMyApp::InitInstance(){CMyWnd *pf=new CMyWnd;pf->ShowWindow(m_nCmdShow);pf->UpdateWindow();this->m_pMainWnd=pf;return TRUE;}CMyApp FirstApp;BEGIN_MESSAGE_MAP(CMyWnd, CFrameWnd)ON_WM_PAINT()ON_WM_LBUTTONUP()END_MESSAGE_MAP()void CMyWnd::OnPaint(){CPaintDC dc(this); // device context for painting// TODO: 在此处添加消息处理程序代码// 不为绘图消息调用 CFrameWnd::OnPaint()for(int i=0;i<4;i++){dc.StretchBlt(myRect[i].left,myRect[i].top,150,200,m_pmdc[i],0,0,150,200,SRCCOPY);/*在这里我们删除m_pbitmap中对象的原因是不清楚内存指向的情况,多个m_pmdc指向一个m_pbitmap的话,会导致后面的不可用那么我们就暂时理解成一个map只能被一个cdc所用,这个map是给了cdc一个地址呢还是直接将其剪切到cdc的地址空间了呢?m_pbitmap->DeleteObject();if(flag==0)m_pbitmap->m_hObject=(HBITMAP)::LoadImage(NULL,myPath[0],              IMAGE_BITMAP, 0,0,LR_LOADFROMFILE);*/}}void CMyWnd::OnLButtonUp(UINT nFlags, CPoint point){// TODO: 在此添加消息处理程序代码和/或调用默认值for(int i=0;i<4;i++){if(myRect[i].PtInRect(point)){this->currentState[i]++;if(this->currentState[i]%2==0){m_pbitmap->m_hObject=(HBITMAP)::LoadImage(NULL,this->myPath[i+1], IMAGE_BITMAP, 0,0,LR_LOADFROMFILE);}else{m_pbitmap->m_hObject=(HBITMAP)::LoadImage(NULL,this->myPath[0],              IMAGE_BITMAP, 0,0,LR_LOADFROMFILE);}m_pmdc[i]->SelectObject(m_pbitmap);InvalidateRect(&myRect[i]);}}CFrameWnd::OnLButtonDown(nFlags, point);}

                                             
0 0
原创粉丝点击