the DrawText() function is for draw text with a rectangle size.
but if the DT_VCENTER is used with DT_SINGLELINE, how can i use the "\n" and "\t" strings formats?

Recommended Answers

All 5 Replies

Did you try DT_EXPANDTABS ?

Displays text on a single line only. Carriage returns and line feeds do not break the line.

yes, but it can't be combined with DT_VCENTER:
"Centers text vertically. This value is used only with the DT_SINGLELINE value."
i read it:

that says nothing about not being able to use VT_EXPANDTABS with DT_SINGLELINE or DT_VCENTER. The link you posted is the same one I posted. If you want to use '\n' or '\r' then you have to parse it yourself and split the line at '\n'

see these sample:

case WM_PAINT:
            HDC hdc;
            SIZE TextRect;
            RECT rect;
            PAINTSTRUCT a;
            DrawText(hdc,"hello world\nhi",-1, &rect, DT_CENTER | DT_EXPANDTABS | DT_VCENTER);
            return 0;

i get the new line and horizontal center, but not the vertical center :(

problem resolved:
1 - we must get the hdc and the string(with DT_CALRECT flag) rectangle:

RECT rect, textrect;
DrawText(hdc,"hello world\nhi\thello mother\nhello my dog",-1, &textrect, DT_CALCRECT);

now we change the top of hdc rectangle(rect):;// remember the rect is, always, less than textrect, or we can get negative values ;)

now we can show the text in vertical center:

DrawText(hdc,"hello world\nhi\thello mother\nhello my dog",-1, &rect, DT_CENTER | DT_EXPANDTABS);

thanks for all

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.