事情是这样的,我在使用 WinAPI 绘图时因为不会用 Direct2D 绘制文字,所以就在 Direct2D 绘制好后加了 GDI+ 绘制文字,就像这样:
class _: public D2D1Window {
protected:
......
void DrawSence() {
CreateGraphResource();
pTarget -> BeginDraw();
// Direct 2D 绘图代码
pTarget -> EndDraw();
// SafeRelease 代码
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd_,&ps);
// GDI+ 绘图代码
EndPaint(hwnd_,&ps);
}
......
void TickProgram() {
if(......) {
DrawSence();
......
} ......
}
......
LRESULT WinProc(UINT uMsg,WPARAM wParam,LPARAM lParam) {
if(uMsg == WM_CREATE) {
// Create D2D1Factory...
} if(uMsg == WM_DESTROY) {
SafeFree(&pTarget);
SafeFree(&pFactory);
PostQuitMessage(0);
return 0;
} if(uMsg == WM_PAINT) {
TickProgram();
return 0;
} ......
return DefWindowProc(hwnd_,uMsg,wParam,lParam);
}
......
} __;
然后尽管我在 MessageLoop 里每次都调用 InvalidateWindow 和 UpdateWindow,游戏还是只能在屏幕需要重绘时运行,不重绘就卡在那,求解决方案。