当前位置:编程学习 > VC++ >>

VC++随机矩形的程序,发现一个错误: 点击最小化时,弹出错误,未知软件异常

用这个替代消息循环: while (1) { if(PeekMessage(&msg, NULL, 0, 0,PM_REMOVE)) //第二个参数不能为NULL,否则关闭窗口无法正常退出 { if(msg.message==WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } else { //空闲时间,做其他事情 hdc=GetDC(hwnd); hbrush=CreateSolidBrush(RGB(rand()%255,rand()%255,rand()%255)); SelectObject(hdc,hbrush); hpen=CreatePen(PS_SOLID,2,RGB(rand()%255,rand()%255,rand()%255)); SelectObject(hdc,hpen); GetClientRect(hwnd,&rt); cxClient=rt.right-rt.left; cyClient=rt.bottom-rt.top; Rectangle(hdc,rand()%cxClient,rand()%cyClient,rand()%cxClient,rand()%cyClient); DeleteObject(hpen); DeleteObject(hbrush); ReleaseDC(hwnd,hdc); } } 把Rectangle那行注释掉就没事,Why?
答案:最小化之后:cxClient=rt.right-rt.left;cyClient=rt.bottom-rt.top; 都应该是0吧,
Rectangle(hdc,rand()%cxClient,rand()%cyClient,rand()%cxClient,rand()%cyClient);
你这条语句就有问题了。

上一个:Win-Tc和VC++环境有什么区别
下一个:在vc++6.0中自己敲键盘输入的下面的程序,编译后生成dll文件老是出现如下的提示:

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,