15,979
社区成员
发帖
与我相关
我的任务
分享
BOOL CDrawEditDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
// add edit rect,must here!
if(!m_blInitEditBr) m_SelEdit.ShowWindow(SW_HIDE);
// normal
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);//DeleteDC needed
CBitmap* pOldBitmap = dcMem.SelectObject(&m_bitmap);
// Retrieve the size of our bitmap...
BITMAP bmp;
m_bitmap.GetObject(sizeof(bmp),&bmp);
// and the size of our window's client area
CRect rect;
GetClientRect(&rect);
pDC->StretchBlt(rect.left, rect.top,rect.Width(), rect.Height(),
&dcMem,0, 0, bmp.bmWidth, bmp.bmHeight,SRCCOPY);
//
if(!m_blInitEditBr)
{// Create Edit background brush; only once !
CRect selEditRc;
m_SelEdit.GetWindowRect(selEditRc);
//we create the background brush of SelEdit
CDC dcMemEd;
dcMemEd.CreateCompatibleDC(pDC);//DeleteDC needed
//
CBitmap EditBmp;//DeleteObject needed
EditBmp.CreateCompatibleBitmap(pDC,selEditRc.Width(),selEditRc.Height());
//
CBitmap* pOld = dcMemEd.SelectObject(&EditBmp);
ScreenToClient(&selEditRc);
MapWindowPoints(this,selEditRc);
dcMemEd.BitBlt(0,0,selEditRc.Width(),selEditRc.Height(),
pDC,selEditRc.left, selEditRc.top, SRCCOPY);
CBitmap *nowBMP=dcMemEd.SelectObject(pOld);
// copy to CB for checking
#ifdef TEST
OpenClipboard();
EmptyClipboard();
SetClipboardData(CF_BITMAP,nowBMP->GetSafeHandle());
CloseClipboard();
#endif
m_pbrEd=new CBrush;
m_pbrEd->CreatePatternBrush(nowBMP);
m_blInitEditBr=TRUE;
//
DeleteObject(EditBmp);
dcMemEd.DeleteDC();
//
m_SelEdit.ShowWindow(SW_SHOW);
}
//
dcMem.SelectObject(pOldBitmap);
dcMem.DeleteDC();
//
return TRUE;
// return CDialog::OnEraseBkgnd(pDC);
}
BOOL CDrawEditDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);//DeleteDC needed
CBitmap* pOldBitmap = dcMem.SelectObject(&m_bitmap);
// Retrieve the size of our bitmap...
BITMAP bmp;
m_bitmap.GetObject(sizeof(bmp),&bmp);
// and the size of our window's client area
CRect rect;
GetClientRect(&rect);
// Create Edit background brush; only once !
if(!m_blInitEditBr)
{// add edit rect
CRgn prgnClip;
CRect selEditRc;
m_SelEdit.GetWindowRect(selEditRc);
prgnClip.CreateRectRgnIndirect(selEditRc);//DeleteObject needed
CDC* pDCex=GetDCEx(&prgnClip,DCX_PARENTCLIP);//ReleaseDC needed
// Fill the client area of dlg,include SelEdit with our bitmap
pDCex->StretchBlt(rect.left, rect.top,rect.Width(), rect.Height(),
&dcMem,0, 0, bmp.bmWidth, bmp.bmHeight,SRCCOPY);
//we create the background brush of SelEdit
CDC dcMemEd;
dcMemEd.CreateCompatibleDC(pDCex);//DeleteDC needed
CBitmap EditBmp;//DeleteObject needed
EditBmp.CreateCompatibleBitmap(pDCex,selEditRc.Width(),selEditRc.Height());
pOldBitmap = dcMemEd.SelectObject(&EditBmp);
ScreenToClient(&selEditRc);
MapWindowPoints(this,selEditRc);
dcMemEd.BitBlt(0,0,selEditRc.Width(),selEditRc.Height(),
pDCex,selEditRc.left, selEditRc.top, SRCCOPY);
CBitmap *nowBMP=dcMemEd.SelectObject(pOldBitmap);
// copy to CB for checking
#ifdef TEST
OpenClipboard();
EmptyClipboard();
SetClipboardData(CF_BITMAP,nowBMP->GetSafeHandle());
CloseClipboard();
#endif
m_pbrEd=new CBrush;
m_pbrEd->CreatePatternBrush(nowBMP);
m_blInitEditBr=TRUE;
//
DeleteObject(prgnClip);
DeleteObject(EditBmp);
ReleaseDC(pDCex);
dcMemEd.DeleteDC();
}
else
{// MORMAL
pDC->StretchBlt(rect.left, rect.top,rect.Width(), rect.Height(),
&dcMem,0, 0, bmp.bmWidth, bmp.bmHeight,SRCCOPY);
}
dcMem.SelectObject(pOldBitmap);
dcMem.DeleteDC();
//
return TRUE;
// return CDialog::OnEraseBkgnd(pDC);
}