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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GDI or GDI+ from worker thread safely?

GDI or GDI+ from worker thread safely?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsmobilewinformsdesigngame-dev
4 Posts 3 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.
  • G Offline
    G Offline
    Greg Ellis
    wrote on last edited by
    #1

    Hey guys, I have an application where I need to keep the UI responsive while background tasks are running. I currently have worker thread that does a PostMessage to a handler that does my GDI drawing, but the problem is that if too many things are happening the message pump gets held up and therefor my UI drawing is not smooth at times. If there was some way I could just do my GDI or GDI+ drawing directly from the worker thread I know that would solve my problems and my UI would be responsive. Is there anyway I can do my drawing directly from a woker thread safely using either GDI, GDI+, or even DirectX? any way at all?

    L 1 Reply Last reply
    0
    • G Greg Ellis

      Hey guys, I have an application where I need to keep the UI responsive while background tasks are running. I currently have worker thread that does a PostMessage to a handler that does my GDI drawing, but the problem is that if too many things are happening the message pump gets held up and therefor my UI drawing is not smooth at times. If there was some way I could just do my GDI or GDI+ drawing directly from the worker thread I know that would solve my problems and my UI would be responsive. Is there anyway I can do my drawing directly from a woker thread safely using either GDI, GDI+, or even DirectX? any way at all?

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      You can do your drawing into off screen buffers in the worker thread then signal the main thread to update the display and all it has to do is draw the buffer(s) making it much faster. But you haven't indicated what you are actually doing so I don't know if that is helpful.

      led mike

      G 1 Reply Last reply
      0
      • L led mike

        You can do your drawing into off screen buffers in the worker thread then signal the main thread to update the display and all it has to do is draw the buffer(s) making it much faster. But you haven't indicated what you are actually doing so I don't know if that is helpful.

        led mike

        G Offline
        G Offline
        Greg Ellis
        wrote on last edited by
        #3

        Oh cool, so I can actually safely use GDI calls to draw on an offscreen device context from directly within the thread so long as I dont do anything with an actual windows control? Then just update the actual windows control from the main thread?

        modified on Wednesday, February 27, 2008 11:41 AM

        M 1 Reply Last reply
        0
        • G Greg Ellis

          Oh cool, so I can actually safely use GDI calls to draw on an offscreen device context from directly within the thread so long as I dont do anything with an actual windows control? Then just update the actual windows control from the main thread?

          modified on Wednesday, February 27, 2008 11:41 AM

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

          Greg Ellis wrote:

          so I can actually safely use GDI calls to draw on the device context from directly within the thread

          Safely?  Not without synchronization.  You have to insure the user can't do anything to cause GDI ops - like dragging a window across your windows, etc. It is possible, but safely takes some work :) If you use regular thread synchronization to control all thread access to GDI then it will work pretty well. I've been doing it for a lot of years, including rendering video and graphics on windows of another process, and I've not seen or heard of any problems yet. 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