分类: WINDOWS
2010-10-15 18:16:11
BOOL CMyWin::OnEraseBkgnd(CDC* pDC) { return pUE; //return CWnd::OnEraseBkgnd(pDC);//把系统原来的这条语句注释掉。 } |
GetClientRect(rectClient); rgn1.CreateRectRgnIndirect(rectClient); rgn2.CreateRectRgnIndirect(m_rectEdit); if(rgn1.CombineRgn(&rgn1,&rgn2,RGN_XOR) == ERROR)//处理后的rgn1只包括了Edit框之外的客户区域,这样,Edit将不会被我的背景覆盖而导致重画。 { ASSERT(FALSE); return ; } brush.CreateSolidBrush(m_clrBackgnd); pDC->FillRgn(&rgn1,&brush); brush.DeleteObject(); |
void CMyWin::OnPaint() { CPaintDC dc1(this); // device context for painting dcMemory.CreateCompatibleDC(&dc1); CBitmap bmp;//这里的Bitmap是必须的,否则当心弄出一个大黑块哦。 bmp.CreateCompatibleBitmap(&dc1,rectClient.Width(),rectClient.Height()); dcMemory.SelectObject(&bmp); //接下来你想怎么画就怎么画吧。 //dcMemory.FillRect(rectClient,&brush); dc1.BitBlt(0,0,rectClient.Width(),rectClient.Height(),&dcMemory,0,0,SRCCOPY); dcMemory.DeleteDC(); // Do not call CWnd::OnPaint() for painting messages } |
/*************************************************************************/ /************************************************************************/ /* 宏功能: 界面刷新时仅刷新指定控件以外的空白区域;可有效避免窗口闪烁 /* 使用于: WM_ERASEBKGND 消息处理函数 OnEraseBkgnd(); /************************************************************************/ #define ERASE_BKGND_BEGIN \ CRect bgRect;\ GetWindowRect(&bgRect);\ CRgn bgRgn;\ bgRgn.CreateRectRgnIndirect(bgRect); //#define ERASE_BKGND_BEGIN // Marco parameter 'IDC' specifies the identifier of the control #define ADD_NOERASE_CONTROL(IDC)\ {\ CRect controlRect;\ GetDlgItem(IDC)->GetWindowRect(&controlRect);\ CRgn controlRgn;\ controlRgn.CreateRectRgnIndirect(controlRect);\ if(bgRgn.CombineRgn(&bgRgn, &controlRgn, RGN_XOR)==ERROR)\ return false;\ } // Marco parameter 'noEraseRect' specifies a screen coordinates based RECT, // which needn't erase. #define ADD_NOERASE_RECT(noEraseRect)\ {\ CRgn noEraseRgn;\ noEraseRgn.CreateRectRgnIndirect(noEraseRect);\ if(bgRgn.CombineRgn(&bgRgn, &noEraseRgn, RGN_XOR)==ERROR)\ return false;\ } // Marco parameter 'pDC' is a kind of (CDC *) type. // Marco parameter 'clBrushColor' specifies the color to brush the area. #define ERASE_BKGND_END(pDC, clBrushColor)\ CBrush brush;\ brush.CreateSolidBrush(clBrushColor);\ CPoint saveOrg = (pDC)->GetWindowOrg();\ (pDC)->SetWindowOrg(bgRect.TopLeft());\ (pDC)->FillRgn(&bgRgn, &brush);\ (pDC)->SetWindowOrg(saveOrg);\ brush.DeleteObject();\ //#define ERASE_BKGND_END /*************************************************/ |
BOOL CMyWnd::OnEraseBkgnd(CDC* pDC) { ERASE_BKGND_BEGIN; ADD_NOERASE_RGN(IDC_BUTTON2); ADD_NOERASE_RGN(IDC_BUTTON1); ADD_NOERASE_RGN(IDC_LIST_STAT); ERASE_BKGND_END(pDC, GetSysColor(COLOR_3DFACE)); return false; } |
/* * No further full-erasing is required, * to prevent screen flashing caused by background erase and view repaint. * Only erase the blank area. */ BOOL CExListCtrl::OnEraseBkgnd(CDC* pDC) { //compute the holding-data-items area of this list control CRect rect; CPoint dataRgnTopLeftPoint; CPoint dataRgnBottomRightPoint; GetItemPosition(0 , &dataRgnTopLeftPoint); GetItemPosition(GetItemCount() , &dataRgnBottomRightPoint); if(!GetHeaderCtrl()->GetItemRect(GetHeaderCtrl()->GetItemCount()-1, rect)) return CListCtrl::OnEraseBkgnd(pDC); dataRgnBottomRightPoint.x = rect.right; rect.SetRect(dataRgnTopLeftPoint, (CPoint)(dataRgnBottomRightPoint - CPoint(2,2))); ClientToScreen(dataRgnRect); //compute and erase the blank area. Using the Marco. ERASE_BKGND_BEGIN; ADD_NOERASE_RECT(dataRgnRect); ERASE_BKGND_END(pDC, GetBkColor()); return false; } |