Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. flicker issue in Onpaint

flicker issue in Onpaint

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amrit Agr
    wrote on last edited by
    #1

    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 }

    J 1 Reply Last reply
    0
    • A Amrit Agr

      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 }

      J Offline
      J Offline
      John Schroedl
      wrote on last edited by
      #2

      You may want to try this in the C / C++ / MFC forum. This is C++ / CLI.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups