1.使用双缓存进行实现绘制图形的 测试用例
void CViewCamera::OnDraw(CDC* pDC)
{
CDocHADMap* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect rect;
GetClientRect(rect);
InitMapDC(pDC->GetSafeHdc(), rect);
int idx = theApp.queCamera.GetMemCameraRecent();
if (idx > -1){
::BitBlt(pDC->GetSafeHdc(), 0, 0,\
rect.right - rect.left,\
rect.bottom - rect.top,\
m_hMainMemDC[idx], 0, 0, SRCCOPY);
theApp.queCamera.SetMemIdle(idx);
//RecordTime(time);
}
/
if (!pDoc)
return;
}
void CViewCamera::InitMapDC(HDC hDC, RECT& stDrawRect)
{
if (m_bInit){
return;
}
for (int i=0; i<MAX_MEM; i++){
//create DC for main map
if(m_hMainMemDC[i] == NULL){
m_hMainMemDC[i] = ::CreateCompatibleDC(hDC);
}
int factor = 3;
int width = (stDrawRect.right - stDrawRect.left)*factor;// + DEF_BMP_MARGIN * factor;
int height = (stDrawRect.bottom - stDrawRect.top)*factor;// + DEF_BMP_MARGIN * factor;
//create bitmap for main map.
if (m_hMainMemDC[i] != NULL){
if (m_hMainBitmap[i] == NULL){
m_hMainBitmap[i] = ::CreateCompatibleBitmap(hDC, width, height);
if (m_hMainBitmap[i] != NULL){
(HBITMAP)::SelectObject(m_hMainMemDC[i], m_hMainBitmap[i]);
}
}
}
}
m_bInit = true;
return;
}
2.
void CViewCamera::InitMapDC(HDC hDC, RECT& stDrawRect)
{
if (m_bInit){
return;
}
for (int i=0; i<MAX_MEM; i++){
//create DC for main map
if(m_hMainMemDC[i] == NULL){
m_hMainMemDC[i] = ::CreateCompatibleDC(hDC);
}
int factor = 3;
int width = (stDrawRect.right - stDrawRect.left)*factor;// + DEF_BMP_MARGIN * factor;
int height = (stDrawRect.bottom - stDrawRect.top)*factor;// + DEF_BMP_MARGIN * factor;
//create bitmap for main map.
if (m_hMainMemDC[i] != NULL){
if (m_hMainBitmap[i] == NULL){
m_hMainBitmap[i] = ::CreateCompatibleBitmap(hDC, width, height);
if (m_hMainBitmap[i] != NULL){
(HBITMAP)::SelectObject(m_hMainMemDC[i], m_hMainBitmap[i]);
}
}
}
}
m_bInit = true;
return;
}
3.程序运行时间计算test
#if 1
#define F_PATH "Y:\\mytest.txt"
int main()
{
char name[80],pass[80];
FILE *fp=fopen(F_PATH,"a+");
if (fp==NULL)
{
printf("open file error!\n");
exit(0);
}
//MFC
LARGE_INTEGER freq;
LARGE_INTEGER start_t,stop_t;
double exe_time;
QueryPerformanceFrequency(&freq);//获得计数器的时钟频率
fprintf(stdout,"The frequency of your pc is %d\n",freq.QuadPart);
QueryPerformanceCounter(&start_t);//获得初始值
char cTmp[50];
while(gets(name) && gets(pass))
{
if (strcmp(name,"exit")==0 &&strcmp(pass,"1")==0)
{
break;
}
sprintf(name,"%s \t",name);
sprintf(pass,"%s \n",pass);
fputs(name,fp);
fputs(pass,fp);
}
QueryPerformanceCounter(&stop_t);//获得中止值
exe_time=(stop_t.QuadPart-start_t.QuadPart)/freq.QuadPart;
exe_time*=1000;//获取到毫秒
fprintf(stdout,"Your program excuted time is %fms.\r\n",exe_time);
sprintf(cTmp,"Your program excuted time is %fms.\r\n",exe_time);
fwrite(cTmp,strlen(cTmp),1,fp);
if (NULL==fp)
return -1;
printf("%s\t%s\n",name,pass);
fclose(fp);
fp=NULL;
getchar();
return 0;
}