MFC - CDC - DrawText 设置行高
#include <afxwin.h>
void MyDrawText(HDC hdc,LPWSTR str,INT count,LPRECT rect,UINT flags,LPDRAWTEXTPARAMS dtp,float* lineHeight=NULL)
{
int fontHeight;
TEXTMETRICW tm;
GetTextMetricsW(hdc, &tm);
if (flags & DT_EXTERNALLEADING)
fontHeight = tm.tmHeight + tm.tmExternalLeading;
else
fontHeight = tm.tmHeight;
float lh=lineHeight?*lineHeight:fontHeight;
BOOL invert_y = FALSE;
if (GetGraphicsMode(hdc) == GM_COMPATIBLE)
{
SIZE window_ext, viewport_ext;
GetWindowExtEx(hdc, &window_ext);
GetViewportExtEx(hdc, &viewport_ext);
if ((window_ext.cy > 0) != (viewport_ext.cy > 0))
invert_y = TRUE;
}
CRect line=rect;
line.bottom=line.top+fontHeight;
while(line.bottom<=rect->bottom)
{
DrawTextExW(hdc,str,count,line,flags,dtp);
str += dtp->uiLengthDrawn;
count -= dtp->uiLengthDrawn;
if(invert_y)
{
line.top -= lh;
line.bottom -= lh;
}
else
{
line.top += lh;
line.bottom += lh;
}
}
}