初始化对话框时先 AddFontResource(L"\\sdmmc\\msyh.ttf"); (sdmmc是sd卡路径下)
然后在绘制函数里面添加你要加的OnPaint() 为了防止重绘,所以先创建内存DC
LOGFONT lf;
int nOldBkMode;
HFONT hFontOld, hFontNew;
// Create the font.
memset(&lf, 0, sizeof(lf));
lf.lfHeight = -19;
lf.lfWeight = 700;
lf.lfCharSet = GB2312_CHARSET;
lf.lfOutPrecision= OUT_DEFAULT_PRECIS;
lf.lfClipPrecision= CLIP_STROKE_PRECIS;
lf.lfQuality = ANTIALIASED_QUALITY;
lf.lfPitchAndFamily= DEFAULT_PITCH|FF_MODERN;
_tcscpy(lf.lfFaceName, L"微软雅黑");
hFontNew = CreateFontIndirect(&lf);
RECT rc;
HDC hMemDC, hSrcDC;
HBITMAP hMemBMP, hOldMemBMP;
HBITMAP hSrcBMP, hOldSrcBMP;
int nWidth, nHeight;
TCHAR szWndTitle[MAX_LOADSTRING];
GetClientRect(hWnd, &rc);
nWidth = rc.right - rc.left;
nHeight = rc.bottom - rc.top;
// Create memory objects
hMemDC = CreateCompatibleDC(hdc);
hMemBMP = CreateCompatibleBitmap(hdc, nWidth, nHeight);
hOldMemBMP = (HBITMAP)SelectObject(hMemDC, hMemBMP);
// Draw background
hSrcBMP = LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1)); //默认设置一张底图
if(hSrcBMP != NULL)
{
hSrcDC = CreateCompatibleDC(hdc);
hOldSrcBMP = (HBITMAP)SelectObject(hSrcDC, hSrcBMP);
BitBlt(hMemDC, 0, 0, nWidth, nHeight, hSrcDC, 0, 0, SRCCOPY);
SelectObject(hSrcDC, hOldSrcBMP);
DeleteDC(hSrcDC);
DeleteObject(hSrcBMP);
//select font
hFontOld = (HFONT)SelectObject(hMemDC, hFontNew);
SetBkMode(hMemDC, TRANSPARENT);
DrawText(hMemDC, str, _tcslen(str), rect, DT_LEFT|DT_TOP|DT_WORDBREAK);
}
// Display the composed picture
BitBlt(hdc, 0, 0, nWidth, nHeight, hMemDC, 0, 0, SRCCOPY);
// Delete memory objects
SelectObject(hMemDC, hOldMemBMP);
SelectObject(hMemDC,hFontOld);
DeleteObject(hMemBMP);
DeleteDC(hMemDC);
最后析构的时候移除字体
RemoveFontResource(L"\\sdmmc\\msyh.ttf");