Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) Scoped_hdc

 

Data type to manage a handle to a device context (HDC).

 

#include <windows.h>
#include <boost/noncopyable.hpp>

//From http://www.richelbilderbeek.nl/CppScoped_hdc.htm
struct Scoped_hdc : public boost::noncopyable
{
  Scoped_hdc(const HWND hwnd)
    : m_hwnd(hwnd),
      m_hdc(GetDC(hwnd))
  {

  }
  ~Scoped_hdc()
  {
    ReleaseDC(m_hwnd,m_hdc);
  }
  const HDC Get() const { return m_hdc; }

  private:
  const HWND m_hwnd;
  const HDC m_hdc;
};

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict