views:

430

answers:

5

Let's say i have three control A, B, C. They are all inherited from CDialog, A is a main dialog , A contains B, and B contains C. and each time i use mouse mouse drag C, B and C will move together.

This is a image:http://img507.imageshack.us/img507/7039/31709956.jpg

We know this will cause B and C to redraw themselves. and it might cause flicker.

And my question is whether not there is a method to double buffer these two dialogs B and C?

I know that in XP and vista, there is a attribute WS_EX_COMPOSITED that will help, but i don't want to use this.

someone might suggest me to use memDC, but my problem is how can i merge the actions in B's ondraw and C's ondraw function into a buffer ?

Hope someone know what i said.

Thanks in advance!

+2  A: 

what helpes flickering a lot is to overload the erasebackground method. This method fills the entire background with a solid color. The paint than paints all items on it. By removing the erasebackground, the paint will just paint over stuff which is already there, thus removing flickering.

Toad
but my problem is how can i merge the actions in B's ondraw and C's ondraw function into a buffer ? let say when i drag C, B and C will get redrawed, the sequence is B draw first and then C, it was finished in their own ondraw function, and I want to double buffer them into a bitmap and then draw it on top of A. but i don't know how to do this.
MemoryLeak
I can't imagine 2 separate windows being able to be redrawn using 1 offscreen bitmap. To do this, you need the dialogs to be something else than separate windows.
Toad
hi...I just saw your test image. Are the dialogs really completely drawn by you(so no controls on it?) In that case, why bother with the CDialog at all and just not draw them directly on the main windows yourself and thus eliminating flicker all together
Toad
since i will add some event handler on the child dialog C, for example drag and drop
MemoryLeak
WS_EX_COMPOSITED , this attribute can buffer all it's child into buffer and then draw it. but I don't want to use this....
MemoryLeak
even if you want to handle drag and drop, you can do this in the parent window, and depending if the mouse is hovering above one of the clients, it does different drop behaviours. I've made GUI systems in the past, which would run in one window, which where flickerfree, handled drag/drop, etc etc I'm thinking since you have no windows controls on your cdialogs but only userdrawn content, this way might be much more appropriate
Toad
could you download the source code from http://rapidshare.com/files/283950611/TestProject.7z.html, and have a look for me ? thanks ~~ I really tried all the methods , but fail...
MemoryLeak
+1  A: 

CS_PARENTDC will help.

Lixiang Xie
+1  A: 

I've never messed with double-buffering Windows' drawing calls myself, but I once came across a discussion about it on a Microsoft forum: http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/789a4116-d3b2-488e-801a-3f7bc1e4d33a/ Perhaps that might be helpful to you.

TheUndeadFish
A: 

Assuming B and C are children of A (the usual case for dialogs), A should have the WS_CLIPCHILDREN style set. If B and C are siblings of A instead, set A's WS_CLIPSIBLINGS bit.

Jerry Coffin
A: 

Take one MemDC for main dialog A and Combined MemDC for B & C. Now when u drag C , you are supposed to combined these 2 MemDC depending on current position by using BitBlt function and then finally you have to do bitblt of combined memDC on actual DC of the dialog.

Along with this you have to override onerasebackground method , so flicker wont be there.

Ashish