flicker issue in Onpaint
-
Hi Guys, I am getting flicker while painting a border on control, bannerbar(its derived from CWnd only). So the case if control is getting focus , border should get paint otherwise not. I am handling OnsetFocus and OnKillfocus and calling Paintborder() in which I checked if banner got focus(by checking m_BannerHasFocus flag) i will call parent->InavlidateRect() here i passed banner rect as argument. In Onpaint I am taking PS_DOT pen (if its have focus) and PS_NULL if don' have focus. I am getting flicker while its getting/loosing focus Even i pass FALSE parameter in InvalidateRect, which will not erase background. Please help me out. I pasted source code here. Thanks void CBannerBar::OnSetFocus(CWnd* pOldWnd) { CBaseWnd::OnSetFocus(pOldWnd); // TODO: Add your message handler code here m_BannerHasFocus = true; PaintBannerBorder(); } void CBannerBar::OnKillFocus(CWnd* pNewWnd) { CBaseWnd::OnKillFocus(pNewWnd); // TODO: Add your message handler code here m_BannerHasFocus = false; PaintBannerBorder(); } void CBannerBar::PaintBannerBorder() { //Invalidate the control in order to hide the focus rectangle. CRect rect; GetWindowRect(&rect); CWnd* pParent = GetParent(); if (!rect.IsRectEmpty() && pParent != NULL) { pParent->ScreenToClient(rect); pParent->InvalidateRect(rect, FALSE); } } void CBannerBar::OnPaint() { CPaintDC dc(this); // device context for painting // create a brush of the background color and paint the window with it CBrush brush (BACK_COLOR); dc.FillRect(&dc.m_ps.rcPaint, &brush); brush.DeleteObject(); CDC* pDC = GetWindowDC(); CRect rect; GetWindowRect(&rect); rect.OffsetRect(-rect.left, -rect.top); COLORREF dColour = GetSysColor(COLOR_HIGHLIGHT); if (m_BannerHasFocus) { dColour = RGB(255, 0, 0); } CPen pen(m_BannerHasFocus ? PS_DOT : PS_NULL, 1, dColour); CPen* penOld = (CPen*)pDC->SelectObject(&pen); pDC->SetBkMode(TRANSPARENT); pDC->MoveTo(rect.left, rect.top); pDC->LineTo(rect.right - 1, rect.top); pDC->LineTo(rect.right - 1, rect.bottom - 1); pDC->LineTo(rect.left, rect.bottom - 1); pDC->LineTo(rect.left, rect.top); pDC->SelectObject(penOld); ReleaseDC(pDC); // Do not call CBaseWnd::OnPaint() for painting messages }
-
Hi Guys, I am getting flicker while painting a border on control, bannerbar(its derived from CWnd only). So the case if control is getting focus , border should get paint otherwise not. I am handling OnsetFocus and OnKillfocus and calling Paintborder() in which I checked if banner got focus(by checking m_BannerHasFocus flag) i will call parent->InavlidateRect() here i passed banner rect as argument. In Onpaint I am taking PS_DOT pen (if its have focus) and PS_NULL if don' have focus. I am getting flicker while its getting/loosing focus Even i pass FALSE parameter in InvalidateRect, which will not erase background. Please help me out. I pasted source code here. Thanks void CBannerBar::OnSetFocus(CWnd* pOldWnd) { CBaseWnd::OnSetFocus(pOldWnd); // TODO: Add your message handler code here m_BannerHasFocus = true; PaintBannerBorder(); } void CBannerBar::OnKillFocus(CWnd* pNewWnd) { CBaseWnd::OnKillFocus(pNewWnd); // TODO: Add your message handler code here m_BannerHasFocus = false; PaintBannerBorder(); } void CBannerBar::PaintBannerBorder() { //Invalidate the control in order to hide the focus rectangle. CRect rect; GetWindowRect(&rect); CWnd* pParent = GetParent(); if (!rect.IsRectEmpty() && pParent != NULL) { pParent->ScreenToClient(rect); pParent->InvalidateRect(rect, FALSE); } } void CBannerBar::OnPaint() { CPaintDC dc(this); // device context for painting // create a brush of the background color and paint the window with it CBrush brush (BACK_COLOR); dc.FillRect(&dc.m_ps.rcPaint, &brush); brush.DeleteObject(); CDC* pDC = GetWindowDC(); CRect rect; GetWindowRect(&rect); rect.OffsetRect(-rect.left, -rect.top); COLORREF dColour = GetSysColor(COLOR_HIGHLIGHT); if (m_BannerHasFocus) { dColour = RGB(255, 0, 0); } CPen pen(m_BannerHasFocus ? PS_DOT : PS_NULL, 1, dColour); CPen* penOld = (CPen*)pDC->SelectObject(&pen); pDC->SetBkMode(TRANSPARENT); pDC->MoveTo(rect.left, rect.top); pDC->LineTo(rect.right - 1, rect.top); pDC->LineTo(rect.right - 1, rect.bottom - 1); pDC->LineTo(rect.left, rect.bottom - 1); pDC->LineTo(rect.left, rect.top); pDC->SelectObject(penOld); ReleaseDC(pDC); // Do not call CBaseWnd::OnPaint() for painting messages }
You may want to try this in the C / C++ / MFC forum. This is C++ / CLI.