现在刚开始写遇到这样一个问题.我在屏幕上随机绘制方块.不管ONTIMER时间设置的多小.绘置的图都非常慢.
效率极低.这是不是说明用GDI绘图下落速度是不可以设置非常快的.直接看代码吧.贴出部分代码
int TertisBox::boxes[7][4][4] = {\
{{0,0,0,0},\
{1,1,1,1},\
{0,0,0,0},\
{0,0,0,0}},\
//
{{0,0,0,0},\
{0,1,1,0},\
{0,1,1,0},\
{0,0,0,0}},\
//
{{0,0,0,0},\
{1,1,0,0},\
{0,1,1,0},\
{0,0,0,0}},\
//
{{0,0,0,0},\
{0,0,1,1},\
{0,1,1,0},\
{0,0,0,0}},\
//
{{0,0,1,0},\
{0,1,1,1},\
{0,0,0,0},\
{0,0,0,0}},\
//
{{0,0,0,0},\
{1,1,1,0},\
{0,0,1,0},\
{0,0,0,0}},\
//
{{0,0,0,0},\
{0,1,1,1},\
{0,1,0,0},\
{0,0,0,0}}\
};//开始.
void CMainFrame::OnMenuStart()
{
m_wndView.SetTimer(1,200,NULL);
// TODO: 在此添加命令处理程序代码
}
void TertisBox::PaintBox(CClientDC* dc)
{
CPen pen(PS_SOLID,1,RGB(0,255,0));
CBrush brush(RGB(255,0,0));
CPen wPen(PS_SOLID,1,RGB(255,255,255));
CBrush wBrush(RGB(255,255,255)); int offset=5;
for(int j=0;j<4;j++)
for(int i=0;i<4;i++)
{
if(box[j][i]==1)
{
dc->SelectObject(&pen);
dc->SelectObject(&brush);
dc->Rectangle(i*20+5,j*20+5,(i+1)*20+5,(j+1)*20+5);
}
else
{
dc->SelectObject(&wPen);
dc->SelectObject(&wBrush);
dc->Rectangle(i*20+5,j*20+5,(i+1)*20+5,(j+1)*20+5);
}
}
}
void CChildView::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CClientDC dc(this);
srand(time(NULL));
int n=rand() % 7;
TertisBox box( n );
box.PaintBox(&dc);
CString str;
m_n++;
str.Format(_T("第 %d 个方块"),m_n);
this->GetParent()->SetWindowTextW(str);
CWnd::OnTimer(nIDEvent);
}当执行的时候发现这样一个问题.标题栏的数字狂涨.但是窗口中的方块不紧不慢的会制.大约1秒变一次方块.
程序也不会出错.
绘制的方块和上面的数字也不同步.请问这应该怎么改进.
效率极低.这是不是说明用GDI绘图下落速度是不可以设置非常快的.直接看代码吧.贴出部分代码
int TertisBox::boxes[7][4][4] = {\
{{0,0,0,0},\
{1,1,1,1},\
{0,0,0,0},\
{0,0,0,0}},\
//
{{0,0,0,0},\
{0,1,1,0},\
{0,1,1,0},\
{0,0,0,0}},\
//
{{0,0,0,0},\
{1,1,0,0},\
{0,1,1,0},\
{0,0,0,0}},\
//
{{0,0,0,0},\
{0,0,1,1},\
{0,1,1,0},\
{0,0,0,0}},\
//
{{0,0,1,0},\
{0,1,1,1},\
{0,0,0,0},\
{0,0,0,0}},\
//
{{0,0,0,0},\
{1,1,1,0},\
{0,0,1,0},\
{0,0,0,0}},\
//
{{0,0,0,0},\
{0,1,1,1},\
{0,1,0,0},\
{0,0,0,0}}\
};//开始.
void CMainFrame::OnMenuStart()
{
m_wndView.SetTimer(1,200,NULL);
// TODO: 在此添加命令处理程序代码
}
void TertisBox::PaintBox(CClientDC* dc)
{
CPen pen(PS_SOLID,1,RGB(0,255,0));
CBrush brush(RGB(255,0,0));
CPen wPen(PS_SOLID,1,RGB(255,255,255));
CBrush wBrush(RGB(255,255,255)); int offset=5;
for(int j=0;j<4;j++)
for(int i=0;i<4;i++)
{
if(box[j][i]==1)
{
dc->SelectObject(&pen);
dc->SelectObject(&brush);
dc->Rectangle(i*20+5,j*20+5,(i+1)*20+5,(j+1)*20+5);
}
else
{
dc->SelectObject(&wPen);
dc->SelectObject(&wBrush);
dc->Rectangle(i*20+5,j*20+5,(i+1)*20+5,(j+1)*20+5);
}
}
}
void CChildView::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CClientDC dc(this);
srand(time(NULL));
int n=rand() % 7;
TertisBox box( n );
box.PaintBox(&dc);
CString str;
m_n++;
str.Format(_T("第 %d 个方块"),m_n);
this->GetParent()->SetWindowTextW(str);
CWnd::OnTimer(nIDEvent);
}当执行的时候发现这样一个问题.标题栏的数字狂涨.但是窗口中的方块不紧不慢的会制.大约1秒变一次方块.
程序也不会出错.
绘制的方块和上面的数字也不同步.请问这应该怎么改进.
解决方案 »
- ListView控件拖动的问题
- 声明:禁止重复散分
- 请教::怎么用数组?
- 使用SDK开发的对话框如何捕捉WM_KEYDOWN
- 我在VC中想做一个flash播放器,可怎么也加载不了影片,郁闷ing……
- ·#¥%……—请问用vc如何应用Microsoft Text Driver象操作数据库一样操作文本文件(*.txt),哪有Demo程序?谢谢!
- 简单的问题,请进来看看
- 高手进来看看。
- 来个高手帮我解决一下
- 请教FindWindowEx的用法?谢谢
- 请问大侠这个错怎么改error LNK2001: unresolved external symbol
- vc2008 mfc 对话框设置器的标尺的单位是什么啊?
//开始.
void CMainFrame::OnMenuStart()
{
srand(time(NULL));
m_wndView.SetTimer(1,200,NULL); // TODO: 在此添加命令处理程序代码
}void CChildView::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CClientDC dc(this);
srand(time(NULL));你把这一句挪到 OnMenuStart里面去试试int n=rand() % 7;
TertisBox box( n );
box.PaintBox(&dc);
CString str;
m_n++;
str.Format(_T("第 %d 个方块"),m_n);
this->GetParent()->SetWindowTextW(str);
CWnd::OnTimer(nIDEvent);
}
楼主你好 我初学MFC 试着写扫雷俄罗斯方块之类的小游戏-ing
主能给我学习哈你写的俄罗斯方块么 我想要"俄罗斯方块"全部的相关文件
若可以 请发我邮箱[email protected] 不胜感激 谢谢