2

I out text but he climbed by region of my window, how I can fix it? Here part of my code

PAINTSTRUCT ps;
    hdc=BeginPaint(hWnd3,&ps);
    LOGFONT lf;
    lf.lfWidth=0;
    lf.lfHeight=14;
    strcpy(lf.lfFaceName,"Times New Roman");
    lf.lfEscapement=lf.lfStrikeOut=lf.lfUnderline=0;
    lf.lfClipPrecision=CLIP_DEFAULT_PRECIS;
    lf.lfCharSet=1251;
    lf.lfOrientation=0;
    hf=CreateFontIndirect(&lf);
    SelectObject(hdc,hf);
    SetTextAlign(hdc,TA_CENTER);
    GetClientRect(hWnd,&r);
    TextOut(hdc,r.right/2,r.bottom/2,"Some text",strlen("Some text"));
    DeleteObject(hf);
    EndPaint(hWnd3,&ps);

Text will be much longer than "Some text".

Oleh
  • 644
  • 11
  • 19

1 Answers1

2

Use DrawText() instead on TextOut(). DrawText lets you specify a rectangle for clipping the text. DrawText() can also be used to calculate the size of the rectangle that will be needed.

SoapBox
  • 20,457
  • 3
  • 51
  • 87
  • I used this function,I needed that text go to new line when he goes to end of window area, something like in console \n. Sory for bad formalization of the question. I newbie in WinAPI – Oleh Sep 24 '13 at 19:46
  • 1
    thank you I find that I want, use DT_WORDBREAK and all works perfect – Oleh Sep 24 '13 at 21:06