With The Case Of  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
Download Evaluation
Pricing & Purchase?
E-XD++Visual C++/ MFC Products
Features Tour 
Electronic Form Solution
Visualization & HMI Solution
Power system HMI Solution
CAD Drawing and Printing Solution

Bar code labeling Solution
Workflow Solution

Coal industry HMI Solution
Instrumentation Gauge Solution

Report Printing Solution
Graphical modeling Solution
GIS mapping solution

Visio graphics solution
Industrial control SCADA &HMI Solution
BPM business process Solution

Industrial monitoring Solution
Flowchart and diagramming Solution
Organization Diagram Solution

Graphic editor Source Code
UML drawing editor Source Code
Map Diagramming Solution

Architectural Graphic Drawing Solution
Request Evaluation
ActiveX COM Products
Technical Support
  General Q & A
Discussion Board
Contact Us


Get Ready to Unleash the Power of UCanCode .NET


UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"

CDC Examples: Drawing vertical text

By WalderMort.

An extension to the GDI DrawText.


Did you ever want to draw vertical text, but the output was out of proportion? Here is the answer. A simple function written in plain Win32, no MFC required. The function behaves almost exactly the same as DrawText(), with the exception that the output is vertical.


This started out when I wanted to print tables. The data within my app had its own method of being displayed, so it seemed pointless to add support for tables; I instead opted to draw them. A line here and a line there, it was easy and quick. The problem came when I wanted to insert the header text. Many English words are too long to be displayed horizontally in this manner, going vertical was the most reasonable thing to do. But I found no function capable of doing this with a pleasant output. So I made my own.

Using the code

If you know the DrawText() function, then you will have no problems using this. It is almost identical. First, include the required files into your project. Anywhere you wish to use the function, include the header #include "VertDraw.h". The prototype for the function is:

int DrawVertText(    HDC hdc,            // Handle to the Device context
        LPCTSTR lpString,        // Null terminated string
        int nCount,        // Length of string in bytes
        LPRECT lpRect,        // Pointer to a rect
        UINT uFormat,        // Optional drawing flags
        UINT HcharSpacing = 3,     // Pixels between characters
        UINT VcharSpacing = 5 );    // Pixels between columns

The parameters are almost identical to DrawText(), with the exception of the last two.

The string provided to lpString must be NULL terminated. The function is fully MBCS and UNICODE compatible, so don't worry about your build configuration. To divide the string into columns, just do the same as you would with any other string. Anywhere you want a new column, add a newline character '\n'.

lpRect defines the area within which the function may draw. For best results, keep this rectangle as small as possible. Passing the whole client area will only serve to use up your processor time.

In the uFormat parameter, you may pass one or more of the following values:


Center the block of text horizontally

May not be used in combination with DV_RIGHT


Align the block of text to the right of the provided rectangle

May not be used in combination with DV_HCENTER


Center the block of text vertically

May not be used in combination with DV_BOTTOM


Align the block of text to the bottom of the provided rectangle

May not be used in combination with DV_VCENTER


Center the text both horizontally and vertically within the provided rectangle

May not be used in combination with DV_BOTTOM or DV_RIGHT


Align the text to the top

Aligns the text relative to the longest line


Center the text

Aligns the text relative to the longest line


Align the text to the bottom

Aligns the text relative to the longest line


Justify the text to the top and bottom

Aligns the text relative to the longest line


Calculate the rectangle needed to draw; but does not draw

The rectangle is calculated relative to the one you provide in the lpRect parameter


Forces the use of an internal double buffer

By default, no double buffer is used

HcharSpacing and VcharSpacing allow you to define how far apart you would like the characters and columns to be. Passing a value of 0 will result in the characters touching each other. For best results, leave them at their default values.

How it works

The code will kick into a loop, drawing each character to a small monochrome bitmap of screen. Each of the bits is examined in this bitmap to determine the width and height of the character. Note, any character from any language will work, provided you have the correct locale set. The dimensions of each character are stored. When this loop is complete, the character positions are calculated relative to the longest line and the character spacing entered by the user. All that's left is to call the regular DrawText() function for each of the characters, drawing them to the newly calculated positions.

Limitations and things to come

I think I have fixed them all in the new version.


  1. Version 1.0 released - August 25th, 2006

  2. Version 1.1 released - September 10th, 2006

    • Removed all the slow off-screen drawing, implemented a storage of positions in its place.

    • Added the DV_TEXTJUSTIFY and DV_DOUBLEBUFFER flags.

    • Corrected the problem with Italic fonts.

    • Corrected the problem with the background mode.


Download demo project - 41Kb
Download source - 4Kb

DrawText and CDC, VC++ Source Code, MFC Source Code and Visual C++.NET



Copyright ?1998-2022 UCanCode.Net Software , all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to