DoEvents equivalent for C++?

前端 未结 2 787
眼角桃花
眼角桃花 2020-12-06 13:42

I\'m new to native c++. Right now, I made it so when I press the left mouse button, it has a for loop that does InvalidateRect and draws a rectangle, and increments X by the

2条回答
  •  臣服心动
    2020-12-06 14:43

    I am a bit rusty in Win32 API, but the asynchronous way of doing this would be:

    • Invalidate the rect
    • Set a timer (see below) to send a message after 50ms
    • Return to the event loop to let WM_PAINT events happen
    • On receiving the timer message, move the rect, then repeat

    This way integrates nicely with being event driven. I realize this is not exactly what you ask for, but I thought I'd mention it as a possible solution anyway :)

    EDIT: A quick google turns up the Windows API call [SetTimer](http://msdn.microsoft.com/en-us/library/ms644906(VS.85,loband).aspx) which you can use to facilitate this. The message will be a WM_TIMER one.

提交回复
热议问题