我的 win32 GUI 内容每秒都在变化,但除非手动移动窗口,否则不会显示更新。我试图每秒弹出一个消息框来触发窗口刷新并且它起作用了。因此它证明我的内容确实发生了变化但窗口没有更新。 我希望窗口每次都刷新而不弹出消息框,是否有用于此的窗口功能?谢谢
case WM_PAINT:
RECT fingerprintSection;
fingerprintSection.left=500;
fingerprintSection.top=300;
fingerprintSection.bottom=540;
fingerprintSection.right=660;
wmId = LOWORD(wParam);
hdc = BeginPaint(hWnd, &ps);
refresh=!refresh;
if((start==true)&&(refresh==true)&&(stop!=true))
{
windowName = MultiByteStringToWideString(name1, CP_ACP);
LoadAndBlitBitmap(windowName.c_str(), hdc,500,0);//loading a picture that doesnt change
fingerprint();
LoadAndBlitBitmap(TEXT("outresized.bmp"), hdc,500,300);//loading a picture that constantly change
refresh=!refresh;
//RedrawWindow(hWnd,&fingerprintSection,NULL,RDW_INTERNALPAINT|RDW_VALIDATE|RDW_UPDATENOW|RDW_NOCHILDREN);
InvalidateRect( hWnd, &fingerprintSection, TRUE );
}
EndPaint(hWnd, &ps);
break;
最佳答案
如果您在 WM_PAINT 之外的窗口中绘图(我猜在这种情况下,当您收到 WM_TIMER 消息时,您可能正在计时器上进行一些 GDI 绘图),那么您应该调用 InvalidateRect(),例如
InvalidateRect( hWnd, NULL, FALSE ); // invalidate whole window
这应该会导致 Windows 重绘整个窗口。如果您只写了一小块区域,请传递一个描述您所写区域的 RECT。
例如,如果您想在 Windows 过程接收到 WM_PAINT 消息时进行绘制AND,并希望强制每秒发生一次,然后设置一个计时器...
#define SECOND_TIMER 1000
case WM_INITDIALOG:
SetTimer( hWnd, SECOND_TIMER, SECOND_TIMER, NULL );
//other initialisation stuff
break;
case WM_TIMER:
if( wParam == SECOND_TIMER )
{
InvalidateRect( hWnd, NULL, FALSE ); // invalidate whole window
}
break;
在这种简单的情况下,整个窗口应该每秒重绘一次,因为 Windows 将由于 InvalidateRect 而发送 WM_PAINT 消息。理想情况下,您应该只使要重绘的部分无效。
关于c++ - win32 内容已更改但不显示更新,除非移动窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22277773/