win32 内容已更改,但除非移动窗口,否则不显示更新 [英] win32 content changed but doesn't show update unless window is moved

查看:72
本文介绍了win32 内容已更改,但除非移动窗口,否则不显示更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 win32 GUI 内容每秒都在变化,但除非手动移动窗口,否则它不会显示更新.我试图每秒弹出一个消息框以触发窗口刷新并且它起作用了.因此它证明我的内容确实发生了变化,但窗口没有更新.我希望窗口刷新而不每次都弹出消息框,是否有 Windows 功能?谢谢

My win32 GUI content changes every second but it doesn't show update unless the window is manually moved. I tried to pop up a messagebox every second to trigger the window to refresh and it worked. Hence it proves that my content really changes but the window doesnt update. I want the window to refresh without popping up a messagebox everytime, is there a windows function for this? Thanks

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() 例如

If you are drawing in a window outside of WM_PAINT (I guess in this case you are probably doing some GDI drawing on a timer when you get a WM_TIMER message), then you should call InvalidateRect() e.g.

InvalidateRect( hWnd, NULL, FALSE );   // invalidate whole window

这应该会导致 Windows 重新绘制整个窗口.如果你只写了一个小区域,传递一个 RECT 描述你写的区域.

This should cause Windows to redraw the whole window. If you have only written a small area, pass a RECT describing the area you have written.

如果你想在你的 windows 程序收到 WM_PAINT 消息时绘制 AND 例如,想要强制每秒发生一次,然后设置一个计时器......

If you want to draw when your windows procedure receives a WM_PAINT message AND for example, want to force that to happen every second, then set a timer...

#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 消息.理想情况下,您应该只使您正在重绘的部分无效.

In this simple case the whole window should be redrawn every second since Windows will send a WM_PAINT message due to the InvalidateRect. Ideally you should only invalidate the part you are redrawing.

这篇关于win32 内容已更改,但除非移动窗口,否则不显示更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆