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. Releasing hDC after rendering

Releasing hDC after rendering

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsgame-devquestionannouncement
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.
  • C Offline
    C Offline
    ComboController
    wrote on last edited by
    #1

    ;)This is my OpenGL window OnPaint function: void COGLWnd::OnPaint() { CPaintDC dc(this); HDC hdc = ::GetDC(m_hWnd); if (!SetGLContext(hdc)) return; RenderScene(); SwapBuffers(hdc); ::ReleaseDC(m_hWnd, hdc) ; } 1. Do I need to release the hdc at the end of the function? 2. And would using the 'dc.m_hDC' of the CPaintDC class as the device context instead of the retrieved from ::GetHDC(m_hWmd) make any difference. Are they both the same thing?

    S 1 Reply Last reply
    0
    • C ComboController

      ;)This is my OpenGL window OnPaint function: void COGLWnd::OnPaint() { CPaintDC dc(this); HDC hdc = ::GetDC(m_hWnd); if (!SetGLContext(hdc)) return; RenderScene(); SwapBuffers(hdc); ::ReleaseDC(m_hWnd, hdc) ; } 1. Do I need to release the hdc at the end of the function? 2. And would using the 'dc.m_hDC' of the CPaintDC class as the device context instead of the retrieved from ::GetHDC(m_hWmd) make any difference. Are they both the same thing?

      S Offline
      S Offline
      Stefan Pedersen
      wrote on last edited by
      #2

      1. Yes 2. If I remember correctly (haven't done painting stuff for a while) the CPaintDC class prepares the window dc for painting (calling BeginPaint on creation and calls EndPaint when destroyed). So, I guess you should skip the GetDC and ReleaseDC calls alltogether and only use the CPaintDC (which, if I remember correctly has a HDC operator).

      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