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. C / C++ / MFC
  4. Why do my Controls flicker ? (src incl.)

Why do my Controls flicker ? (src incl.)

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsc++comhelpquestion
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
    abiemann
    wrote on last edited by
    #1

    In my VS8 MFC Dialog exploratory-app, the listbox and OK buttons flicker. I've tried the Double Buffer code (http://www.codeproject.com/bitmap/drawing_without_flicker.asp[^]) like this: void CFlickerTestDlg::OnPaint() { CPaintDC dc(this); // device context for painting CRect rcClient; GetClientRect(rcClient); // See Note 1 CDC MemDC,*pDC; CBitmap MemBitmap; pDC = this->GetDC(); // Get Current DC MemDC.CreateCompatibleDC(pDC); MemBitmap.CreateCompatibleBitmap(pDC,rcClient.right,rcClient.bottom); CBitmap *pOldBitmap = MemDC.SelectObject(&m_BmpTarget); //CBrush bkBrush(HS_FDIAGONAL,RGB(0,rand()%255,0)); // See Note 2 //MemDC.FillRect(rcClient,&bkBrush); pDC->BitBlt(0,0,rcClient.right,rcClient.bottom,&MemDC,0,0,SRCCOPY); //See Note 3 MemDC.SelectObject(pOldBitmap); } but that didn't help, the listbox and OK buttons still flicker. (also, I don't understand why my static image is covered up by some grey layer - but my main priority is the annoying flicker) I've uploaded my project (255KB) here in a .zip: http://www.webfilehost.com/?mode=viewupload&id=4066339[^] There's a countdown timer on the bottom-right of the page that changes to a download link (I don't have any online webspace to share files so I had to resort to one of these free sharing services) I'd be SO grateful for any help

    M 1 Reply Last reply
    0
    • A abiemann

      In my VS8 MFC Dialog exploratory-app, the listbox and OK buttons flicker. I've tried the Double Buffer code (http://www.codeproject.com/bitmap/drawing_without_flicker.asp[^]) like this: void CFlickerTestDlg::OnPaint() { CPaintDC dc(this); // device context for painting CRect rcClient; GetClientRect(rcClient); // See Note 1 CDC MemDC,*pDC; CBitmap MemBitmap; pDC = this->GetDC(); // Get Current DC MemDC.CreateCompatibleDC(pDC); MemBitmap.CreateCompatibleBitmap(pDC,rcClient.right,rcClient.bottom); CBitmap *pOldBitmap = MemDC.SelectObject(&m_BmpTarget); //CBrush bkBrush(HS_FDIAGONAL,RGB(0,rand()%255,0)); // See Note 2 //MemDC.FillRect(rcClient,&bkBrush); pDC->BitBlt(0,0,rcClient.right,rcClient.bottom,&MemDC,0,0,SRCCOPY); //See Note 3 MemDC.SelectObject(pOldBitmap); } but that didn't help, the listbox and OK buttons still flicker. (also, I don't understand why my static image is covered up by some grey layer - but my main priority is the annoying flicker) I've uploaded my project (255KB) here in a .zip: http://www.webfilehost.com/?mode=viewupload&id=4066339[^] There's a countdown timer on the bottom-right of the page that changes to a download link (I don't have any online webspace to share files so I had to resort to one of these free sharing services) I'd be SO grateful for any help

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      The code you posted does nothing to prevent flicker. I've been through your code and made some modifications to fix the flicker. Having a picture control behind all the other controls is the problem. It prevents you from clipping the other controls to prevent flicker. I added the WS_CLIPCHILDREN style to the dialog, deleted the picture control from the dialog's resource, and instead draw the bitmap to the window in response to WM_ERASEBKGND. This way, Windows automagically clips all the child controls, so you don't have to redraw them on every timer event. Shoot me an email here and I'll send the changes in a reply. BTW, the code leaks GDI resources on every timer event :) I didn't look for those leaks. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      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