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. Controls are flickering in MFC CView(MDI)

Controls are flickering in MFC CView(MDI)

Scheduled Pinned Locked Moved C / C++ / MFC
c++sysadminhelptutorialannouncement
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.
  • D Offline
    D Offline
    D Manivelan
    wrote on last edited by
    #1

    Dear Friends, Am developing a client server application. Am using MFC MDI. It has multiple class. One class is showing live values so i used Editbox and CListCtrl control. I was create these control in

    onCreate()

    function. It shows live in

    onDraw()

    function

    GetDlgItem(IDC_EDITBOX)->SetWindowText(sLiveValues);

    it is also updating a value but it is getting flicker. If i use

    InvalidateRect()

    function it is not flickering but not update any value. So i need to update live value in any control like EditBox,CListCtrl without flicker. How to avoid flickering. Please help me.

    F 1 Reply Last reply
    0
    • D D Manivelan

      Dear Friends, Am developing a client server application. Am using MFC MDI. It has multiple class. One class is showing live values so i used Editbox and CListCtrl control. I was create these control in

      onCreate()

      function. It shows live in

      onDraw()

      function

      GetDlgItem(IDC_EDITBOX)->SetWindowText(sLiveValues);

      it is also updating a value but it is getting flicker. If i use

      InvalidateRect()

      function it is not flickering but not update any value. So i need to update live value in any control like EditBox,CListCtrl without flicker. How to avoid flickering. Please help me.

      F Offline
      F Offline
      Freak30
      wrote on last edited by
      #2

      If I understand you correctly, you are calling SetWindowText() from onDraw(). This is a problem, because SetWindowText() invokes drawing of the control. So your apllication is permanently redrawing its GUI. I would suggest that you store the values in the receiving function in a thread-safe way (look for CRITICAL_SECTION in the documentation). Then create a timer (look for SetTimer()) and in the timer function again in a thread-safe way copy the data to a local variable and display the copy with SetWindowText(). The OnTimer function could look something like this:

      void YourDialog::OnTimer(UINT nIDEvent)
      {
      if (nIDEvent == YourTimerId)
      {
      EnterCriticalSection(&yourCriticalSection);
      CString values = sLiveValues;
      LeaveCriticalSection(&yourCriticalSection);
      GetDlgItem(IDC_EDITBOX)->SetWindowText(values);
      }
      }

      You can run the timer in any interval convenient for your users.

      The good thing about pessimism is, that you are always either right or pleasently surprised.

      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