CMsgDlg是 Dialog的一个类, IDB_BITMAP1 在资源里,可就是位图显示不了。请教各位大侠。
void CMsgDlg::drawmap()
{
CBitmap hbmp; CStatic *pStaic=(CStatic*)GetDlgItem(IDC_cao);
hbmp.LoadBitmap(IDB_BITMAP1);
BITMAP bm;
hbmp.GetBitmap(&bm); CDC dcMem;
dcMem.CreateCompatibleDC(GetDC());
CBitmap *poldBitmap=(CBitmap*)dcMem.SelectObject(hbmp); CRect lRect;
pStaic->GetClientRect(&lRect);
lRect.NormalizeRect(); pStaic->GetDC()->StretchBlt(lRect.left ,lRect.top ,lRect.Width(),lRect.Height(),
&dcMem,0 ,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
dcMem.SelectObject(&poldBitmap);
}
void CMsgDlg::drawmap()
{
CBitmap hbmp; CStatic *pStaic=(CStatic*)GetDlgItem(IDC_cao);
hbmp.LoadBitmap(IDB_BITMAP1);
BITMAP bm;
hbmp.GetBitmap(&bm); CDC dcMem;
dcMem.CreateCompatibleDC(GetDC());
CBitmap *poldBitmap=(CBitmap*)dcMem.SelectObject(hbmp); CRect lRect;
pStaic->GetClientRect(&lRect);
lRect.NormalizeRect(); pStaic->GetDC()->StretchBlt(lRect.left ,lRect.top ,lRect.Width(),lRect.Height(),
&dcMem,0 ,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
dcMem.SelectObject(&poldBitmap);
}
lpy2003 为什么要加wm_paint 消息. 我在函数体内加了 SendMessage(WM_PAINT); 也不行 :(
答】
HBITMAP hbitmap;
//获得指向静态控件的指针
CStatic *pStatic=(CStatic *)GetDlgItem(IDC_SHOWBMP);
//获得位图句柄
HBITMAP Bitmap;
//设置静态控件的样式,使其可以使用位图,并试位标显示使居中
pStatic->ModifyStyle(0xF,SS_BITMAP|SS_CENTERIMAGE);
//设置静态控件显示位图
pStatic->SetBitmap(hBitmap);
GetClientRect(&rect);
CDC memDC;
CDC *pDC;
pDC = GetDC();
CBitmap bitmap;
CBitmap *pOldbitmap;
BITMAP hbitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
memDC.CreateCompatibleDC(pDC);
pOldbitmap = memDC.SelectObject(&bitmap);
bitmap.GetBitmap(&hbitmap);
CSize size(hbitmap.bmWidth,hbitmap.bmHeight);
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&memDC,0,0,size.cx,size.cy,SRCCOPY);
memDC.SelectObject(pOldbitmap);
ReleaseDC(pDC);
CDialog::OnPaint();
{........
}