网站建站哪家公司好一点,网站建设推荐公司,网站做301将重定向到新域名,传媒网站源码使用GDI的MeasureString函数来实现这个功能
1、初始化GDI
#include gdiplus.h
using namespace Gdiplus;
#pragma comment(lib, gdiplus)
2、判断长度等
下面这个是判断字符串长度超过240像素后#xff0c;先获取字符串在240以内部分#xff0c;然…使用GDI的MeasureString函数来实现这个功能
1、初始化GDI
#include gdiplus.h
using namespace Gdiplus;
#pragma comment(lib, gdiplus)
2、判断长度等
下面这个是判断字符串长度超过240像素后先获取字符串在240以内部分然后超出的部分加...显示
Graphics gra(hdcBuffer);//首先创建字体相关FontFamily fontFamily(TEXT(Arial)); //字体Font font(fontFamily, 20, FontStyleRegular, UnitPixel); //30为字号就是文字的大小PointF pointF(0.0f, 0.0f); //绘画的x、y坐标WCHAR string[256];RectF boundRect; //作为MeasureString的参数调用MeasureString后会把x、y、高度和宽度填入boundRect里for (int i 0; i 100; i){AmpChildName_15[i] AmpChildName[i];lstrcpynW(string, (LPCTSTR)AmpChildName_15[i], AmpChildName_15[i].GetLength());//CString转换为WCHARgra.MeasureString(string, wcslen(string), font, pointF, boundRect);//使用GDI获取字符串像素大小if (boundRect.Width 240)//字符串像素宽度{//根据长度一个个来减少字符直到字符串小于240多余部分显示...for (int j 0; j AmpChildName_15[i].GetLength(); j){lstrcpynW(string, (LPCTSTR)AmpChildName_15[i], AmpChildName_15[i].GetLength() - j);//gra.MeasureString(string, wcslen(string), font, pointF, boundRect);if (boundRect.Width 240){AmpChildName_15[i] AmpChildName_15[i].Mid(0, AmpChildName_15[i].GetLength() - j) ...;break;}}}}