简体   繁体   English

C++ WM_PAINT 定时器

[英]C++ WM_PAINT timer

How do I make a timer work in c++ WM_PAINT?如何让计时器在 c++ WM_PAINT 中工作? I'm trying to "print" it via Wm_Paint, because at the moment I don't know another method of adding a timer, googling didn't help.我正在尝试通过 Wm_Paint“打印”它,因为目前我不知道添加计时器的另一种方法,谷歌搜索没有帮助。

Here's what I have declared in CALLBACK :这是我在CALLBACK中声明的内容:

TCHAR s[10], str[20] = _T("Seconds: ");
    static int t;

case WM_CREATE:


        SetTimer(hwnd, 1, 1000, NULL);

And here's how I try to draw the timer:这是我尝试绘制计时器的方式:

hdc = BeginPaint(hwnd, &ps);
        hBrush = CreateSolidBrush(g_color);
        hPen = CreatePen(PS_NULL, 1, RGB(0, 0, 0));
        holdPen = HPEN(SelectObject(hdc, hPen));
        holdBrush = (HBRUSH)SelectObject(hdc, hBrush);

_tcscat(str + 9, _itot(t, s, 10));
        TextOut(hdc, 10, 300, str, _tcsclen(str));

SelectObject(hdc, holdBrush);
        SelectObject(hdc, holdPen);
        DeleteObject(hPen);
        DeleteObject(hBrush);
        EndPaint(hwnd, &ps);

So far, it just prints out "Seconds: 0" and stops updating.到目前为止,它只是打印出“Seconds: 0”并停止更新。

Ok so, for me to make it work, I've had to create a WM_TIMER case in my CALLBACK function, in the end it looked like this:好的,为了让它工作,我必须在我的CALLBACK function 中创建一个WM_TIMER案例,最后它看起来像这样:

//code above

case WM_TIMER:
t++;
InvalidateRect(hwnd, NULL, TRUE);
break;

//code below

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM