19,468
社区成员
发帖
与我相关
我的任务
分享
void CGDIplusDemoView::OnDraw(CDC *pDC) {
Graphics graphics(this->m_hWnd);
//this->RedrawWindow();
WCHAR string[256];
wcscpy(string,L"123456789ABCDEFGHIJKLM");
FontFamily fontFamily(L"Arial");
Font font(&fontFamily,30,FontStyleRegular,UnitPixel);
Font font2(&fontFamily,18,FontStyleRegular,UnitPixel);
RectF layoutRect(10,10,130,90);
SolidBrush brush(Color(255,0,0,0));
RectF boundRect;
int codepointsFitted = 0;
int linesFilled = 0;
int strlen = wcslen(string);
graphics.MeasureString(string,strlen,&font,layoutRect,NULL,&boundRect,&codepointsFitted,&linesFilled);
graphics.DrawRectangle(&Pen(Color::Black,3),layoutRect);
CString s(string);
CString tmp;
tmp.Format("欲输出的字符串为\n\"%s\"\n共%d个字符,\n其中,在规定的输出矩形中,\n只输出%d行,共%d个字符",s[0],s.GetLength(),linesFilled,codepointsFitted);
}
WCHAR *pwszSrc = L"中国23456789";
int nSize = WideCharToMultiByte( // 先求char*的长度
CP_ACP, // ANSI代码页, 可随意给出
NULL, // 固定为NULL 原因不明
pwszSrc, // 源unicode字符串
-1, // 上一参数字符串被认为是以NULL为结束的字串并自动计算长度。
NULL, // 目标char*字串的缓冲区
0, // 若此值为零,函数返回上一参数的缓冲区所必需的字节数,此时上一参数为NULL。
NULL, // 特殊情况下使用,否则为NULL
FALSE); // 特殊情况下使用,否则为false
char *pszDst = new char[nSize];
WideCharToMultiByte( // 再得出char*字串
CP_ACP,
NULL,
pwszSrc, // 源unicode字符串
-1, // 上一参数字符串被认为是以NULL为结束的字串并自动计算长度。
pszDst, // 目标char*字串的缓冲区
nSize, // 上一参数缓冲区的大小
NULL,
FALSE);
MessageBoxA(pszDst);
delete []pszDst;