From: Vadim Zeitlin Date: Sun, 10 Apr 2005 11:30:37 +0000 (+0000) Subject: added HDCClipper() class which automatically unselects clipping region in its dtor X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/a1372ae2fa6471b0dbe4d37fbe09076d2ea97b89?ds=sidebyside added HDCClipper() class which automatically unselects clipping region in its dtor git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33468 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/msw/private.h b/include/wx/msw/private.h index 873855f0be..1b4729ab22 100644 --- a/include/wx/msw/private.h +++ b/include/wx/msw/private.h @@ -449,6 +449,28 @@ public: operator HRGN() const { return (HRGN)GetObject(); } }; +// class sets the specified clipping region during its life time +class HDCClipper +{ +public: + HDCClipper(HDC hdc, HRGN hrgn) + : m_hdc(hdc) + { + if ( !::SelectClipRgn(hdc, hrgn) ) + wxLogLastError(_T("SelectClipRgn")); + } + + ~HDCClipper() + { + ::SelectClipRgn(m_hdc, NULL); + } + +private: + HDC m_hdc; + + DECLARE_NO_COPY_CLASS(HDCClipper) +}; + // when working with global pointers (which is unfortunately still necessary // sometimes, e.g. for clipboard) it is important to unlock them exactly as // many times as we lock them which just asks for using a "smart lock" class