views:

43

answers:

4

i want to repaint part of the window not the whole thing. i have no idea how to. im using win32 please no mfc........
thanks in advance


// create rect structure
RECT rect2;
rect2.left=0;
rect2.top=0;
rect2.right=225;
rect2.bottom=300;
// calling invalidateRect when left mouse button is donw
case WM_LBUTTONDOWN:
    InvalidateRect(hWnd, &rect2, false);
    break;
A: 

What's wrong with RedrawWindow ?

Kirill V. Lyadvinsky
if i redraw the whole window it will use too much of my cpu
Ramiz Toma
`RedrawWindow` redraws **part** of a window. Check `lprcUpdate` parameter.
Kirill V. Lyadvinsky
i tried it and it didn't work :/
Ramiz Toma
+2  A: 

Pass the rectangle of the portion of window, which you want to re-paint, in InvalidateRect() method. Read here for details.

Hemant
i already thought of that but it didn't work you can see my code ill post it in minute
Ramiz Toma
Define "didn't work". Also, if you have your own WM_PAINT handler, then you need to respect the clip rectangle it gives you. In general though, if this is for a game, as mentioned, you're most likely better off with DirectX if you're planning to do more than simple blitting and shapes.
EboMike
all im using gdi for is to draw a simple rectangle and to load some images
Ramiz Toma
+2  A: 

Is this for a game engine? It appears so since you are concerned about cpu usage on a full redraw.

If it is, then I'd recommend blitting to a back buffer image, keeping track of what portion of your back buffer has changed and copying only that portion to the screen once you are done rendering. This is called double buffering and will also take care of flickering issues you might see.

Adrian Grigore
yes im creating a game and im also using double buffering in my game
Ramiz Toma
A: 

As other answers have pointed out; when handling WM_PAINT you need to get the update rectangle/region and draw/blit accordingly.

see:
+ The WM_PAINT Message
+ Retrieving the Update Region
+ Invalidating and Validating the Update Region
+ Synchronous and Asynchronous Drawing

afriza