Advertisement

A simple MFC class

Started by July 05, 2000 08:54 AM
-1 comments, last by Floru 24 years, 5 months ago
Hi! Has anybody made some some games using MFC? Specifically I''m intrested in the graphical side of it. I know DirectX but now I''d like to try also MFC. My idea was following: If you make a dialog based application you can specify a region of the dialog and then my class handles all the drawing in this area. So if your dialog is for example 400x400 pixels big you could specify a region (30,30), (130,130). Then your class would have a drawing area of size 100x100. And my class also has a bitmap of the size of the drawing area. So if you draw a pixel it''s drawn to the bitmap and at last I blit the bitmap to the drawing area. Like double buffering..? How do you find this idea? I thought that it eases the work a little bit if you define a area and then your class handles the rest. If somebody has a little time to to check my code and make any suggestions. It would be quite helpful. I have to admit that my code is very sloooow. So any ways to optimize the speed? //definitions class CDisplay { public: CDisplayWin(); virtual ~CDisplayWin(); void SetDrawRect(int x1, int y1, int x2, int y2); BOOL SetPointerToWindow(CWnd *wnd); void SetPixel(int x, int y, unsigned long color); void Fill(COLORREF color); BOOL Flip(); private: CWnd *m_pWnd; CDC *m_pDC; CClientDC *m_pClientDC; CBitmap *m_pBitmap; } // code part CDisplayWin::CDisplayWin() { m_pWnd=NULL; m_pDC=NULL; m_pBitmap=NULL; } CDisplayWin::~CDisplayWin() { } void CDisplayWin::SetDrawRect(int x1, int y1, int x2, int y2) { m_areaDrawRect.x1=x1; m_areaDrawRect.x2=x2; m_areaDrawRect.y1=y1; m_areaDrawRect.y2=y2; m_pBitmap=new CBitmap(); m_pBitmap->CreateCompatibleBitmap(m_pClientDC, GetDrawAreaWidth(), GetDrawAreaHeight()); m_pDC->SelectObject(m_pBitmap); } // passes the window pointer from the dialog BOOL CDisplayWin::SetPointerToWindow(CWnd *wnd) { if(wnd!=NULL) { m_pWnd=wnd; m_pClientDC=new CClientDC(m_pWnd); m_pDC=new CDC(); m_pDC->CreateCompatibleDC(m_pClientDC); return TRUE; } else return FALSE; } void CDisplayWin::SetPixel(int x, int y, unsigned long color) { m_pDC->SetPixel(x, y, color); } // fill area with specific color void CDisplayWin::Fill(COLORREF color) { m_pDC->SelectObject(m_pBitmap); m_pDC->FillSolidRect(0, 0, GetDrawAreaWidth(), GetDrawAreaHeight(), color); } // the final call when everything is drawed, flips everything // to screen BOOL CDisplayWin::Flip() { m_pClientDC->BitBlt(m_areaDrawRect.x1, m_areaDrawRect.y1, GetDrawAreaWidth(), GetDrawAreaHeight(), m_pDC, 0, 0, SRCCOPY); return TRUE; } Thanks Floru

This topic is closed to new replies.

Advertisement