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