I make a small Win32GUI program, but the screen are flickering when I redraw it with InvalidateRect(hwnd, NULL, true); in WM_TIMER.
To avoid this, I have inserted the SwapBuffers(mygraphhandler); command into first line of WM_PAINT.
Now, the screen aren't flickering, but my program is slowed down.
Soembody can help me to avoid screen flickering and slowness? Using SwapBuffers() isn't the right way to perform double buffering?
I have tried the double buffering example from robertelder website and fortunatelly it works well.
But I have two notices: 1. You can see this in the example:
"NOTE: you may need to set the window background not to draw itself before you register the window class: [NAME_OF_YOUR_WNDCLASSEX].hbrBackground = NULL;"
I rewrote my code to set this to NULL, because the screen is flickering without this, but what if I would like use another background color than black? 2. When I use these lines:
1 2 3 4
int win_width = Client_Rect.right - Client_Rect.left;
int win_height = Client_Rect.bottom + Client_Rect.left;
I get the following error message:
"F:\progsetup\codeblocks-17.12mingw-nosetup\sajatok\ablakosrajz\Jatekom\main.cpp|245|note: crosses initialization of 'int win_height'|"
and similar to int win_width.
Therefore I must skip these lines and use numbers directly to add the width and height of the window. But it is not good when the player resize the window.
How can I use the width and height variables of the window correctly?