使用 TextOut 函数打印新行

Can*_*ral 5 c winapi

我正在尝试用函数打印一个新行TextOut

我试过

TextOut(hDC, 10, 20, "Hello\nWorld", strlen(text));
Run Code Online (Sandbox Code Playgroud)

但输出是“HelloWorld”。

如何使用 打印新行TextOut

小智 6

简单的。TextOut没有任何格式化功能。DrawText代替使用。请参阅格式化标志以将文本居中、计算矩形等。您不必使用DT_EDITCONTROL标志来完成DrawText格式化。例如,

HDC dc = ::GetDC(0);
RECT rc;
char *lpsz= "Hello\r\nWorld";
::SetRect(&rc,0,0,300,300);
::DrawText(dc,lpsz,::strlen(lpsz),&rc,DT_LEFT | DT_EXTERNALLEADING | DT_WORDBREAK);
::ReleaseDC(0,dc);
Run Code Online (Sandbox Code Playgroud)