情况是这样的
我在OnDraw里加载了两张bitmap1和bitmap2图片,想实现这样的效果--就是我鼠标点击某个区域后,这个区域内的bitmap1部分被bitmap2的该部分替换。
我的问题是:我在点击某个区域之后,效果也达到了,但是当我把窗口最大化或是最小化或者用另外一个窗口覆盖之后,整个bitmap1都被bitmap2替换了。哪位大侠能告诉我这是什么原因呢?
我在OnDraw里加载了两张bitmap1和bitmap2图片,想实现这样的效果--就是我鼠标点击某个区域后,这个区域内的bitmap1部分被bitmap2的该部分替换。
我的问题是:我在点击某个区域之后,效果也达到了,但是当我把窗口最大化或是最小化或者用另外一个窗口覆盖之后,整个bitmap1都被bitmap2替换了。哪位大侠能告诉我这是什么原因呢?
BOOL CDCLabCtrlProView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
this->GetClientRect(rect);//获取当前客户区
if(m_flag1==0)
{
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1); BITMAP bmp;
bitmap.GetBitmap(&bmp); CDC dc;
dc.CreateCompatibleDC(pDC); dc.SelectObject(&bitmap); //CRect rect;
//GetClientRect(&rect);
//pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,SRCCOPY);
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
}
else
{
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP2); BITMAP bmp;
bitmap.GetBitmap(&bmp); CDC dc;
dc.CreateCompatibleDC(pDC); dc.SelectObject(&bitmap); //CRect rect;
//GetClientRect(&rect);
//pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,SRCCOPY);
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
}
return TRUE;
// return CView::OnEraseBkgnd(pDC);
}if(m_ptms.x>0&&m_ptms.x<rect.Width()/2&&m_ptms.y>0&&m_ptms.y<rect.Height()/2)
{
m_flag1=1;
m_inrect=TRUE;
CRect rect(0,0,rect.Width()/2,rect.Height()/2); //选定重绘区域
InvalidateRect(&rect,TRUE);
// this->Invalidate(TRUE); //当前客户区全部重绘
}
else if(m_ptms.x>rect.Width()/2&&m_ptms.x<rect.Width()&&m_ptms.y>0&&m_ptms.y<rect.Height()/2)
{
m_flag1=1;
CRect rect(rect.Width()/2,0,rect.Width(),rect.Height()/2); //选定重绘区域
InvalidateRect(&rect,TRUE);
}
else if(m_ptms.x>0&&m_ptms.x<rect.Width()/2&&m_ptms.y>rect.Height()/2&&m_ptms.y<rect.Height())
{
m_flag1=1;
CRect rect(0,rect.Height()/2,rect.Width()/2,rect.Height()); //选定重绘区域
InvalidateRect(&rect,TRUE);
}
else if(m_ptms.x>rect.Width()/2&&m_ptms.x<rect.Width()&&m_ptms.y>rect.Height()/2&&m_ptms.y<rect.Height())
{
m_flag1=1;
CRect rect(rect.Width()/2,rect.Height()/2,rect.Width(),rect.Height()); //选定重绘区域
InvalidateRect(&rect,TRUE);
}
我就设置了一个int型变量,当鼠标在一个区域点击的时候,该变量为1,然后用InvalidateRect对这个区域进行重绘,然后就是我的问题了
大家给看看怎么解决
这样才能执行你想要的重绘。