Hello,

Is it possible to make a control (a richedit control for example) paint onto your own DC instead of the window DC?

It probably involes intercepting WM_PAINT ....but then what?
Posted on 2003-11-11 04:25:28 by Lennon
your own DC instead of the window DC
What specifically do you mean by this? Yes it is possible to paint on another control's dc, but you need to obtain that dc first. And by doing so you are breaking one of the principles of OO programming: a control should only know about itself, nothing else, it knows it has a parent but doesn't know any details about that parent (except its hWnd).
Posted on 2003-11-11 06:42:34 by sluggy
You will have to be more specific. The DC that a control is drawn with normally belongs to the class of the object. You can super class the control with the CS_OWNDC style and each instance of that control will have it's own DC. It is a common misconception that you are drawing onto the DC, you are actually drawing with it. The oject itself holds it's position and size, the DC is simply used to describe the limitations with reference to the GDI of the device used to display the object and to modify the drawing tools to fit those limitations.
Posted on 2003-11-11 08:50:02 by donkey
I have a window with 2 richedit controls, 1 edit control, 1 static and 1 toolbar...

Now as you can probably tell i dont know exactly how everything works :stupid: .... but instead of these controls all being draw using the main window DC (hmm are they actually draw using the window DC?) and everything being displayed in my window without me having any control, I want to be able to create my own DC (backbuffer) and make all the controls draw onto this backbuffer.

This would give me the power to do things like a transparent blit of all the controls over a background picture, stop the problem of flickering with ease....etc...

Is there an easy way to go about this?
Posted on 2003-11-11 20:37:01 by Lennon
Controls are drawn to the display with a class copy of the display DC. In the case of CS_OWNDC the copy is specific to the control. The window DC is also just a copy of the display DC that is specific to that windows class. Each DC is copied in order to allow different bitmaps, brushes etc.. but they all start out as a copy of the display DC otherwise you would have color depth/resolution chaos.

Yes, you can use double buffering to reduce flickering, that is what it is for. There are a lot of examples of double buffered rich edit controls, just download some of the rich edit example code and find one that uses it.
Posted on 2003-11-11 20:49:57 by donkey
WM_PRINT ??

Most controls support this message and let you paint to a (mem)DC
Posted on 2003-11-12 04:49:41 by Edwin Knoppert
yes, i know what double buffering is, and i know its possible to have double buffered rich edit controls (not that i can find any examples).

What i need is the controls to be drawn by windows as normal only in offscreen memory, so i then have control over when and how each control is drawn on my window.

I need to know if its possible and if so a few pointers in the right direction.

Cheers,
Lennon.
Posted on 2003-11-13 20:21:33 by Lennon
yes, i know what double buffering is, and i know its possible to have double buffered rich edit controls (not that i can find any examples).

What i need is the controls to be drawn by windows as normal only in offscreen memory, so i then have control over when and how each control is drawn on my window.

I need to know if its possible and if so a few pointers in the right direction.

Cheers,
Lennon.
Posted on 2003-11-13 20:33:45 by Lennon
Hi, Lennon. :)

AFAIK some (but not all) controls will accept a DC handle to be passed in a WM_PAINT message. Those controls that support it will use the DC you pass them rather than the one returned by BeginPaint, this might be what you want.

BTW, did you manage to put pictures in a richedit? I was going to look into that when studying OOP, but I got involved in other projects...
Posted on 2003-11-14 19:56:52 by QvasiModo
Seems my previous answer is missed here?
Posted on 2003-11-17 03:06:54 by Edwin Knoppert
Hi,

Sorry my reply's are taking so long, i'm on holiday and don't have propper access to the internet at the moment.

Edwin, sorry i didn't reply to your post :o WM_PRINT isn't much help for what i'm doing, all the controls are being drawn by Windows at the moment and i want to keep it that way... i am just trying to change where Windows draws them...

Hi Qvasi :)

Pictures in Richedit *sigh* i ran into a brick wall so moved onto improving other things with the chat, got everything working nicely so i came back to the HORRIBLE problem ... and hence i ended up posting for help again!

My idea was to create a static window(or maybe just paint using the richedit's dc) the same size as the richedit window, then just parse the viewable text in the richedit window everytime it needs re-painting looking for certain characters -:

@@
@@ here is some text in a riched

So, i find the four @ characters, i then work out the top left coordinate and draw the emoticon onto the static/richedit DC.

This worked ok... appart from a horrible flickering problem :(

This was one of the reasons i posted, if i could make windows draw everything off-screen it would solve this problem and let me try a few other things i've been thinking of implementing.

I have found a way of making this work flicker free using WS_EX_COMPOSITED, but this only works in Windows XP...so i will look into your suggestion Qvasi.

:alright:

Thanks again,
Lennon.
Posted on 2003-11-17 04:16:15 by Lennon
I think you need to create a bitmap for your backbuffer, using desktop colors.. and then select your backDC into your backbuffer so you can blit to it.. blit the richedit to your own DC along with the graphics, then blit to your main window DC. that means your richedit will be hidden from view, but updated with each keystroke via blit so in theory it should be flickerless.

Just a edumacated guess..
Posted on 2003-11-18 23:36:28 by drarem