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. How to release HDC ?

How to release HDC ?

Scheduled Pinned Locked Moved C / C++ / MFC
questiongraphicshelptutorialannouncement
2 Posts 2 Posters 5 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
    uus99
    wrote on last edited by
    #1

    I have a function that performs some drawing according to the bitdepth of the screen. The function is called in a loop continuously. The problem is, after a while it crashes. I have narrowed it down the problem to the HDC not being released. How can i release it? void Plot() { //Obtain current screen depth HDC hdc = ::GetDC(NULL); int screendepth=GetDeviceCaps(hdc, BITSPIXEL); //do something here according to the current bitdepth //how to release here? }

    PJ ArendsP 1 Reply Last reply
    0
    • U uus99

      I have a function that performs some drawing according to the bitdepth of the screen. The function is called in a loop continuously. The problem is, after a while it crashes. I have narrowed it down the problem to the HDC not being released. How can i release it? void Plot() { //Obtain current screen depth HDC hdc = ::GetDC(NULL); int screendepth=GetDeviceCaps(hdc, BITSPIXEL); //do something here according to the current bitdepth //how to release here? }

      PJ ArendsP Offline
      PJ ArendsP Offline
      PJ Arends
      wrote on last edited by
      #2

      From the MSDN documentation on the GetDC function

      After painting with a common DC, the ReleaseDC function must be called to release the DC. Class and private DCs do
      not have to be released. ReleaseDC must be called from the same thread that called GetDC. The number of DCs is
      limited only by available memory.


      "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

      Within you lies the power for good; Use it!

      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