HDC hdc = ::GetDC(m_hWnd); LOGFONT lf = { 0 }; lf.lfWeight = 16; //平均宽度 lf.lfHeight = 40;//字体高度 lf.lfCharSet = GB2312_CHARSET; HFONT hfont = ::CreateFontIndirect(&lf); HFONT holdfont= (HFONT)SelectObject(hdc, hfont);//新对象替换相同类型的对象 /* 参数1:HDC hdc DC句柄 参数2:HGDIOBJ hgdiobj 新对象 但该对象的句柄必须使用以下函数创建才有效: Bitmap(位图) CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDIBitmap, CreateDIBSection Brush(画刷) CreateBrushIndirect, eateDIBPatternBrush, CreateDIBPatternBrushPt, CreateHatchBrush, CreatePatternBrush, CreateSolidBrush Font(字体) CreateFont, CreateFontIndirect Pen(画笔) CreatePen, CreatePenIndirect Region(区域) CombineRgn, CreateEllipticRgn, CreateEllipticRgnIndirect, CreatePolygonRgn, CreateRectRgn, CreateRectRgnIndirect 返回值:HGDIOBJ 如果选择对象不是区域并且函数执行成功,那么返回值是被取代的对象的句柄 如果选择对象是区域并且函数执行成功,返回如下一值 如果发生错误并且选择对象不是一个区域,那么返回值为NULL,否则返回HGDI_ERROR */ RECT rect = { 50,50,400,400 }; int n=DrawText(hdc,_T("GDI测试"),-1,&rect,DT_LEFT); SelectObject(hdc, holdfont); BOOL b=DeleteObject(hfont); //删除对象
标签:lf,MFC,对象,SelectObject,选择对象,hdc,句柄 From: https://www.cnblogs.com/liming19680104/p/17323469.html