views:

80

answers:

4

I'm creating a line chart control, and I need to write (or better say draw) the axis names and axis values.

I found DrawText and TextOut functions, but the text they show is flickering and don't know how to set the font and text orientation (I will need vertical text orientation as well as horizontal).

Are there any other functions you could recommend or how to use these stated above and get the results I need?

+3  A: 

I doubt the flickering is caused by DrawText or TextOut, but rather your paint method. If you are redrawing the entire window on the paint event it is likely to flcker as you erase the whole window, and then there is a perceptible delay before all elements are redrawn.

It may be possible to reduce the flicker acceptably by only painting the invalidated region; however this can become complex. A simpler method is to use double buffering; where you draw to a non-visible memory context, and then switch it to visible context.

Try Google'ing "MFC double buffering" for plenty of examples.

Clifford
thanks.i'll search for it.
kobac
A: 

@Clifford

I have a problem. Even when I have only one call of TextOut function (and no other calls besides this one) in OnPaint of my control I still have flickering.

How come? Is it possible that I will have to use double buffering for every application in which I want to draw something, no matter how much drawing I have in OnPaint?

Is it possible that something else is wrong here?

Just to remind you. I have a dialog based application and my custom made control (which for now just prints one word) placed on the main dialog.

In which case OnPaint of my control is called? Btw, I've just found out that OnPaint of my custom control is non-stop called. Just can't figure out, where from and why.

kobac
+1  A: 

It sounds like you are looking for CMemDC, which basically wraps your CDC (or CPaintDC). You do all your drawing to the CMemDC, it then copies itself to your original CDC when destructed.

http://www.codeproject.com/KB/GDI/flickerfree.aspx

Btw, Visual Studio 2010 has add this class to the latest MFC:

http://msdn.microsoft.com/en-us/library/cc308997.aspx

Inverse
A: 

Font & orientation you can set by doing GetLogFont(), modifying the LOGFONT members and then doing a CreateFontIndirect() with the modified settings. This is all win32 stuff with a very thin wrapper really, so you can read the Petzold to get details and more examples.

Roel