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?

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: msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx

Edited 2 Years Ago by cambalinho

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;
            GetClientRect(hwnd,&rect);
            PAINTSTRUCT a;
            hdc=BeginPaint(hwnd,&a);
            SetBkMode(hdc,TRANSPARENT);
            DrawText(hdc,"hello world\nhi",-1, &rect, DT_CENTER | DT_EXPANDTABS | DT_VCENTER);
            EndPaint(hwnd,&a);
            return 0;

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

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

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

now we change the top of hdc rectangle(rect):

rect.top=rect.bottom/2-textrect.bottom/2;// 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

This question has already been answered. Start a new discussion instead.