vc  显示文字 图片

1.画背景颜色

  HDC hdc=::GetDC(h1);
  RECT rt;
  rt.top=0;
  rt.left=20;
  rt.bottom=1;
  rt.right=500;
  //GetClientRect(h1, &rt);
  HBRUSH hBrush=CreateSolidBrush(RGB(0,0,0));
  hBrush=(HBRUSH)SelectObject(hdc, hBrush);
  PatBlt(hdc, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, PATCOPY);
  hBrush=(HBRUSH)SelectObject(hdc, hBrush);
  DeleteObject(hBrush);
  ::ReleaseDC(h1,hdc);

2.画背景图

 CDC memdc;
       memdc.CreateCompatibleDC(&dc);//创建兼容DC

       CBitmap bkg;
       bkg.LoadBitmap(IDB_BITMAP1);//载入位图

       BITMAP bkginfo;
       bkg.GetBitmap(&bkginfo);//获取位图信息

       memdc.SelectObject(&bkg);

       RECT rect;
       GetWindowRect(&rect);//获取对话框信息

       dc.StretchBlt(0,0,rect.right-rect.left,rect.bottom-rect.top,&memdc,0,0,bkginfo.bmWidth,bkginfo.bmHeight,SRCCOPY);

3.输出文字

RECT rt1;
 //lf.lfCharSet=GB2312_CHARSET;
 //strcpy(lf.lfFaceName,"雅黑");
 lf.lfHeight=lfHeight;
 lf.lfItalic=false;
 rt1.left=left;
   rt1.top=top;
 rt1.bottom=bottom;
 rt1.right=right;
 HDC hdc1 = ::GetDC(h1);

 //SetBkMode(hdc1,TRANSPARENT);
 SetBkColor(hdc1,RGB(bgR,bgG,bgB));

    SetTextColor(hdc1,RGB(lfR,lfG,lfB)); 
 HFONT hFont=CreateFontIndirect(&lf);  
 HFONT hOldFont=(HFONT)::SelectObject(hdc1,hFont);//设置新字体


 DrawText(hdc1, s, lstrlen(s), &rt1,
    DT_SINGLELINE |DT_VCENTER | DT_LEFT);// DT_CENTER); 

 hFont=(HFONT)::SelectObject(hdc1,hOldFont);//恢复原来的字体.

 DeleteObject(hFont);
 DeleteObject(hOldFont);
 ::ReleaseDC(h1,hdc1);
 
 
 4.画背景图

 

OnEraseBkgnd(CDC *pDC)
{
    CRect rc;
    mVideoWindow.GetWindowRect(&rc);
    ScreenToClient(&rc);
    pDC->ExcludeClipRect(&rc);

 
  CRect rect;
  GetClientRect(&rect);//加载背景位图
  //下边加入获取绝对路径:
  CString szSysPath_T,strFullPath;
  strFullPath =m_Path;
  strFullPath+=_T("\\img\\bg.bmp");

  CFile   file;
  file.Open( strFullPath,CFile::modeRead);
  int   len    file.GetLength();
  char   *buf    new   char[len];
  file.Read(buf,len);
  file.Close();
  CBrush   brush;
  const   void   *buf2    buf    sizeof(BITMAPFILEHEADER);
  brush.CreateDIBPatternBrush(buf2,DIB_RGB_COLORS);

  pDC-> SelectObject(&brush);
  pDC-> FillRect(rect,&brush);
  delete   []buf;
  return TRUE;
    //return CDialog::OnEraseBkgnd(pDC);
}

 

5.画图

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值