void CGame::GameRunDram()
{
HDC hdc = ::GetDC(m_hWnd);//获取hWnd设备描述表包括绘图属性,方法
CRect rc;
GetClientRect(m_hWnd, &rc);//获取当前客户区坐标位置信息 存储在rc.witch()
CDC *dc = CClientDC::FromHandle(hdc);//CDC是一个类 HDC的具体操作都在CDC封装
CDC m_dcMemory;
CBitmap bmp; //定义一个位图设备
bmp.CreateCompatibleBitmap(dc, rc.Width(), rc.Height());//建立一个与屏幕兼容的位图,大小就是窗口大小
m_dcMemory.CreateCompatibleDC(dc);//建立一个内存环境,以便位图在内存中保留下来
CBitmap* p0ldBitmap = m_dcMemory.SelectObject(&bmp);
//Graphics gh(m_dcMemory.GetSafeHdc());
Graphics gh(m_dcMemory.GetSafeHdc());
gh.Clear(Color::White);
gh.ResetClip();
DrawFps(gh);
::BitBlt(hdc,0,0,rc.Width(),rc.Height(),m_dcMemory.GetSafeHdc(),0,0,SRCCOPY);
//Image image(pStream, 0);
dc->DeleteDC();
return;
}
void CGame::DrawFps(Graphics &gh)
{
static int fps = 0;
m_fps++;
static DWORD dwLast = GetTickCount();
if (GetTickCount() - dwLast >= 1000) {
fps = m_fps;
m_fps = 0;
dwLast = GetTickCount();
}
{
CString s;
FontFamily* fontFamily = new FontFamily(_T("宋体"));
//FontFamily fontFamily(L"楷体");
s.Format(_T("FPS:%d"), fps);
SolidBrush brush(Color(0, 0, 0xFF));
// SolidBrush brush(RGB(255, 0, 255));
Gdiplus::Font font1(fontFamily,10.0);
CRect rc;
::GetClientRect(m_hWnd, &rc);
PointF origin(rc.right - 50,rc.top + 2);
gh.DrawString(s.GetString(), -1, &font1, origin, &brush);
}
}