简体   繁体   中英

What are useful functions for drawing text (MFC)?

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?

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM