wince6.0添加外部字体库

初始化对话框时先 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");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值