2011-04-03 00:31:59|?次阅读|上传:wustguangh【已有?条评论】发表评论
关键词:C/C++, MFC, 界面设计|来源:唯设编程网
下列源码实现了MFC编程在Static控件中显示位图,以及位图的缩放显示:
//在Static控件内显示位图 void C**Dlg::ShowBmpInStaic() { HBITMAP hbitmap; //将pStatic指向要显示的地方 CStatic *pStatic = NULL; //根据ID获取Static控件 pStatic=(CStatic*)GetDlgItem(IDC_IMAGE); //装载资源*.bmp hbitmap=(HBITMAP)::LoadImage (::AfxGetInstanceHandle(),"*.bmp", IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION); CBitmap hbmp; hbmp.Attach(hbitmap); //获取图片内容 BITMAP bm; hbmp.GetBitmap(&bm); CDC dcMem; //创建兼容DC dcMem.CreateCompatibleDC(GetDC()); CBitmap *pOldBitmap=(CBitmap*)dcMem.SelectObject(hbmp); CRect lRect; //获取Static控件的大小范围 pStatic->GetClientRect(&lRect); //在Static控件上显示位图 pStatic->GetDC()->StretchBlt(lRect.left ,lRect.top ,lRect.Width(),lRect.Height(), &dcMem,0 ,0,bm.bmWidth,bm.bmHeight,SRCCOPY); dcMem.SelectObject(&pOldBitmap); }