Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 628835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:40:47+00:00 2026-05-13T19:40:47+00:00

I have a MFC document/view C++ graphics application that does all its drawing to

  • 0

I have a MFC document/view C++ graphics application that does all its drawing to an off screen bitmap, and then copys that to the supplied CDC pointer in the OnDraw method. Over the last couple of days I’ve been looking to place the drawing component in a seperate worker thread, so it doesn’t stall the GUI. I seem to get a fair number of MFC GDI related asserts firing when I do this, e,g,

VERIFY(::MoveToEx(m_hAttribDC, x, y, &point)

So a few questions;

  • Are there any problems with using worker threads with MFC & GDI?
  • Are there issues using MFC GDI objects across threads?
  • Do GDI objects have to be declared locally to a thread?

While it is possible the issue is resource/locking related, the drawing thread has its own provate CDC and CBitmap that it uses for all the drawing, and only copies the bitmap back to the main thread when it hasz excludive access via a mutex. The code has also been tested by direct calling rather than as a seperate thread to prove the problem does relate to threading.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:40:47+00:00Added an answer on May 13, 2026 at 7:40 pm

    Device contexts can be used by any thread (the only thing you must be aware of is that the thread which did the GetDC should also call ReleaseDC), but are not inherently thread safe. You have to ensure that only one caller is accessing the DC at any given point in time, but you seem to have taken care of that, from what you write.

    What do you mean by Do GDI thread have to be declared locally to a thread ? They must be allocated and freed in the same thread, but they can be created/used in any thread. Once again, you are responsible not to use such a resource from two threads simultaneously.

    You should probably check the series of posts from Raymond Chen on the subject:

    • Thread affinity of user interface objects, part 1: Window handles
    • Thread affinity of user interface objects, part 2: Device contexts
    • Thread affinity of user interface objects, part 3: Menus, icons, cursors, and accelerator tables
    • Thread affinity of user interface objects, part 4: GDI objects and other notes on affinity
    • Thread affinity of user interface objects, part 5: Object clean-up

    and be sure that you don’t link to the single threaded versions of the C/MFC libraries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 352k
  • Answers 352k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think to some extent it was probably an arbitrary… May 14, 2026 at 7:37 am
  • Editorial Team
    Editorial Team added an answer I solved the issue. As described here I changed the… May 14, 2026 at 7:37 am
  • Editorial Team
    Editorial Team added an answer It's to show the parent relationship. In Git, a particular… May 14, 2026 at 7:37 am

Related Questions

I have a very large app, 1.5 million lines of C++, which is currently
I'm writing a routine to provide user definable keyboard short-cuts for any menu item
I have developed a quite large application using MFC. Naturaly, I used GDI for
I maintain an MFC (VC6) MDI application that uses Frame Windows as views for
I have previously asked about the proper way of accessing member variables present in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.