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. Passing cdc across threads

Passing cdc across threads

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 4 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.
  • U Offline
    U Offline
    User 513823
    wrote on last edited by
    #1

    Hi pals, I am facing a difficulty with CDC across threads. Actually, i spawn a secondary thread to calculate the display coordinates of the strings. So i am calculating the height and width of the strings based on the font selected in the CDC. It works fine with the scroll view but the calculation goes wrong with the PrintPreview. Bcos ,SelectObject(pMyFont) is always returning NULL. How do i solve this problem. Help me out friends. Thanks in advance. Kumari

    P S 2 Replies Last reply
    0
    • U User 513823

      Hi pals, I am facing a difficulty with CDC across threads. Actually, i spawn a secondary thread to calculate the display coordinates of the strings. So i am calculating the height and width of the strings based on the font selected in the CDC. It works fine with the scroll view but the calculation goes wrong with the PrintPreview. Bcos ,SelectObject(pMyFont) is always returning NULL. How do i solve this problem. Help me out friends. Thanks in advance. Kumari

      P Offline
      P Offline
      palbano
      wrote on last edited by
      #2

      MFC objects do not operate well across threads. There are some Knowledge base articles on MSDN that explain why. Basically they use thread local storage to map the resource handle to the C++ object pointer. So in another thread the mapping does not exist. So always pass the resource HANDLE rather than an MFC C++ class pointer across threads. then if you want to use MFC classes in the thread you can attach the HANDLE to a thread local scope MFC object.

      "No matter where you go, there your are." - Buckaroo Banzai

      -pete

      1 Reply Last reply
      0
      • U User 513823

        Hi pals, I am facing a difficulty with CDC across threads. Actually, i spawn a secondary thread to calculate the display coordinates of the strings. So i am calculating the height and width of the strings based on the font selected in the CDC. It works fine with the scroll view but the calculation goes wrong with the PrintPreview. Bcos ,SelectObject(pMyFont) is always returning NULL. How do i solve this problem. Help me out friends. Thanks in advance. Kumari

        S Offline
        S Offline
        suiram40
        wrote on last edited by
        #3

        Pass the HDC. Make sure the CDC is retreived by GetDC. Make thet window class has CS_OWNDC. you get it on WM_CREATE. you can set the GDI objects into this context once and thay persistent couse to CS_OWNDC.

        A U 2 Replies Last reply
        0
        • S suiram40

          Pass the HDC. Make sure the CDC is retreived by GetDC. Make thet window class has CS_OWNDC. you get it on WM_CREATE. you can set the GDI objects into this context once and thay persistent couse to CS_OWNDC.

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          Hi suiram Thanks for your response. Yes i am passing hdc to the thread. I tried with CS_OWNDC, But of no improvement. My problem is with the CDC of PrintPreview. What should i do now. Please, do help me. kumari

          1 Reply Last reply
          0
          • S suiram40

            Pass the HDC. Make sure the CDC is retreived by GetDC. Make thet window class has CS_OWNDC. you get it on WM_CREATE. you can set the GDI objects into this context once and thay persistent couse to CS_OWNDC.

            U Offline
            U Offline
            User 513823
            wrote on last edited by
            #5

            Hi suiram Thanks for your response. Yes i am passing hdc to the thread. I tried with CS_OWNDC, But of no improvement. My problem is with the CDC of PrintPreview. What should i do now. Please, do help me. kumari

            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