有如下乘员变量
CBitmap bmp
程序在构造函数中把图像加载进来
CTestView::CTestView()
{
bmp.LoadBitmap(IDB_BITMAP1);
//IDB_BITMAP1为位图的ID
}在OnDraw函数中显示图像
void CTestView::OnDraw(CDC* pDC)
{
CTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CDC *hMemDC=new CDC;
hMemDC->CreateCompatibleDC(pDC);
hMemDC->SelectObject(bmp);
CRect rc;
GetClientRect(&rc);
BITMAP hbmp;
bmp.GetBitmap(&hbmp);
pDC->StretchBlt(0,0,rc.Width(),rc.Height(),hMemDC,0,0,hbmp.bmWidth,hbmp.bmHeight,SRCCOPY);
}
"更新"菜单时执行的代码,目的是刷新图片
void CTestView::OnUpdate()
{
// TODO: Add your command handler code here
Invalidate();
}
可是当我点击更新菜单时,图像并不显示,不知道为什么?请各路高手不吝赐教
CBitmap bmp
程序在构造函数中把图像加载进来
CTestView::CTestView()
{
bmp.LoadBitmap(IDB_BITMAP1);
//IDB_BITMAP1为位图的ID
}在OnDraw函数中显示图像
void CTestView::OnDraw(CDC* pDC)
{
CTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CDC *hMemDC=new CDC;
hMemDC->CreateCompatibleDC(pDC);
hMemDC->SelectObject(bmp);
CRect rc;
GetClientRect(&rc);
BITMAP hbmp;
bmp.GetBitmap(&hbmp);
pDC->StretchBlt(0,0,rc.Width(),rc.Height(),hMemDC,0,0,hbmp.bmWidth,hbmp.bmHeight,SRCCOPY);
}
"更新"菜单时执行的代码,目的是刷新图片
void CTestView::OnUpdate()
{
// TODO: Add your command handler code here
Invalidate();
}
可是当我点击更新菜单时,图像并不显示,不知道为什么?请各路高手不吝赐教
{
CTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CRect rc;
GetClientRect(&rc);
CDC *hMemDC=new CDC;
hMemDC->CreateCompatibleDC(pDC);
bmp.CreateCompatibleBitmap(pDC,rc.right,rc.bottom);
hMemDC->SelectObject(bmp);
BITMAP hbmp;
bmp.GetBitmap(&hbmp);
pDC->StretchBlt(0,0,rc.Width(),rc.Height(),hMemDC,0,0,hbmp.bmWidth,hbmp.bmHeight,SRCCOPY);
hMemDC->DeleteDC();
delete hMemDC;
}