Clearing the client area (CDC) in VC++

RSMemphis

Golden Member
Oct 6, 2001
1,521
0
0
Is there a faster way (speed wise) than pDC->FillSolidRect(x,y,wx,wy,color); ?
If so, what's there to do?

Basically, I don't wanna call the refresh funtion with the option to clean the client window anymore, but only want to do it when necessary (i.e. when I need to redraw everything anyway).

Edit: Did not want all these smiley faces. Must have accidentally added them.
 

singh

Golden Member
Jul 5, 2001
1,449
0
0
You should use double-buffering and clear the memory CDC instead. Also, perform your own painting in the memory CDC. Once you're done, copy the mem CDC to the actual CDC. This will eliminate flicker and speed up the operations.
 

RSMemphis

Golden Member
Oct 6, 2001
1,521
0
0
Hmm, that is an excellent idea.
I may not implement this immediately, but I think once it runs, I will optimize that way.

I am a bit worried about memory allocation. Because I use the same coordinates for printing (LO_ENGLISH) and screen display (ANISOTROPIC), I use a client area of 7000 x 7000. Multiply that by the bit depth, and you get a lot of data. Does Windows automatically make the backup CDC the size of the actual screen, or do I need to start worrying about that? Also, does Windows only save non-white pixels?

Anyway, thanks for the idea.

Edit:
So basically, I have a CDC memoryDC; variable in View.h
Initialize memoryDC.CreateCompatibleDC(NULL); in the constructor;
Whenever I am not printing, I write to the memoryDC instead, when printing to the actual pDC.
So, the question for me really is - how big will the memoryDC be? I don't want to use to much RAM.
 

singh

Golden Member
Jul 5, 2001
1,449
0
0
No, you have to resize manually (handle WM_RESIZE and do it there). However, I believe there is a class on Code Project that is able to automate this process.

I have never worked with printer related stuff. But the Memory CDC is *ONLY* for what you see on the screen. Your "logical" window can be as big as you like, but you use the Memory CDC for only what the user can physically see on the screen (window client area). That way, it will not make too big of a difference.
 

singh

Golden Member
Jul 5, 2001
1,449
0
0
The memory CDC will be as big as your window size (without scrolling). RAM is cheap, don't worry about it. Even if it takes a 10 megs, it will be better than your window flickering like crazy.
 

RSMemphis

Golden Member
Oct 6, 2001
1,521
0
0
Hmm, I am wondering if the memory DC can take logical coordinates... But I don't think so. Well, converting it is not a big deal, either MFC or myself can provide code for that.
Most machines have 1024x768 at 32 bit, or about 3MB space. You are right, that's not so bad.

Do you use bitblt to copy the image over? I assume so.

Once again, thanks for your help.