Are these rectangles windows? If not, it's best to make them labels.
Then just invalidate those labels and it will redraw.
You can also actually try to draw what you need on the invisible dc - and then just copy it - when whole buffer is ready - onto the screen dc
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
You might try overriding WM_ERASEBKGRND and just return non zero.
Just read through some tutorial... Is this Double buffering you talking about? If so, i'm busy adding some code... Not sure how it works but will update you on my progress...
The idea is...
1. Create a DC on buffer
2. Add/draw rectangles on Buffer DC
3. Copy back to DC to client area using BitBlt()...
You would just add labels to your window. They're called "static," I think. Create them just like any other windows. Labels are made to contain text and appears invisible to the dialog.
So you could make labels and seeing as they are windows, draw upon them and invalidate them.
Yep, it's double buffer and the general idea you have is correct.
Basically, it's to avoid drawing anything on the window until you've finished drawing at which time you copy the data over to the window.
It's similar to games which also tend to use some double buffering technique.
Will check this later.. now am busy wif double buffering....
Q. Is it essential to first delete the DC on buffer only after you copied it to client area DC? Thing is i have about 5 rectangles. Currently i draw each on DC created by BegingPaint(), then delete after drawing it, draw next Rec, then delete until i finish drawing all... The example i have draws object(s) on Memory DC on a buffer, then copies the buffer DC to Client DC, then only after copying deletes the Buffer DC.... To clear my question, is it safe to draw all five rectangles without deleting each separately on Buffer DC, then delete all after copying back to Client DC... (Hope this question is clear)Yep, it's double buffer and the general idea you have is correct.
Basically, it's to avoid drawing anything on the window until you've finished drawing at which time you copy the data over to the window.
It's similar to games which also tend to use some double buffering technique.
Yes. The easiest way is to create a memory DC that mirrors your dialog. Then draw everything on the memory DC where you would draw on your dialog.
When done drawing everything, you can request BeginPaint, get your DC, blit over, End Paint and release your memory DC.
Note that dynamically creating a memory DC for each paint may have a performance impact, so you might want to create a global memory DC and overwrite the information on it and blit it.
I'm not an expert in the area, but this is how it works, I think.
Hang on, think i got myself mixed up here... Noticed i have two things to delete... First Brushes & Pens, Then the DC (rather releasing MemDC)... My concern is deleting brushes and pens for each rectangle before BitBlt'ing to Window DC!.... would that have an effect? Shoudn' be a prob deleting/releasing DC on buffer after copying, but need to delete brushes before coping...
Init:
Create memory DC.
Select proper pens/brushes on memory DC.
Paint:
Draw rectangle 1 on memory DC.
Draw rectangle 2 on memory DC.
Draw rectangle 3 on memory DC.
Draw rectangle 4 on memory DC.
Draw rectangle 5 on memory DC.
Etc.
BeginPaint
Blit memory DC to window DC
EndPaint
End:
Free memory DC
Blit copies the information from one DC to another. Pens/brushes are used when drawing on the DC, so when using blit, you don't need them.
Also about brushes / pens. If you create them, then you must free them. If you don't create them (you can select already existing, stock objects), then you don't need to free them.
This is about how I would see the code.
@Elysia, i have a feeling that putting the lines in blue outside WM_PAINT rather in WM_CREATE may improve the code efficiency (or reduce flickers as well)... In fact ASAIC the only thing that should now be within WM_PAINT is the bitblt function.... Do you know what the following language in red is/means
Code:case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Fügen Sie hier den Zeichnungscode hinzu... EndPaint(hWnd, &ps); break;