WinAPI DrawText 新行

Evg*_*yev 0 windows winapi drawtext

如何使每个字符串从新行出现?

int i = 1;
char *s = *environ;
    for (; s; i++) {
        DrawText(hdc, s, -1, &rect,
            DT_WORDBREAK | DT_EDITCONTROL | DT_BOTTOM);
            s = *(environ + i);
         }
Run Code Online (Sandbox Code Playgroud)

Jon*_*ter 5

使用函数返回的值DrawText(绘制的文本的高度)来偏移下一行文本的矩形。

int i = 1;
char *s = *environ;
for (; s; i++) {
    int height = DrawText(hdc, s, -1, &rect,
        DT_WORDBREAK | DT_EDITCONTROL | DT_BOTTOM);
    OffsetRect(&rect, 0, height);
    s = *(environ + i);
}
Run Code Online (Sandbox Code Playgroud)