From a27cbf44fcdbdea10b0f85bd97836a70c4661f6a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 2 Apr 2005 01:15:47 +0000 Subject: [PATCH] added AutoHRGN class; corrected GetHbrush[Of]() macros git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33246 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/private.h | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/include/wx/msw/private.h b/include/wx/msw/private.h index 0b87d49b20..873855f0be 100644 --- a/include/wx/msw/private.h +++ b/include/wx/msw/private.h @@ -415,25 +415,38 @@ private: DECLARE_NO_COPY_CLASS(SelectInHDC) }; +// a class which cleans up any GDI object +class AutoGDIObject +{ +protected: + AutoGDIObject(HGDIOBJ gdiobj) : m_gdiobj(gdiobj) { } + ~AutoGDIObject() { if ( m_gdiobj ) ::DeleteObject(m_gdiobj); } + + HGDIOBJ GetObject() const { return m_gdiobj; } + +private: + HGDIOBJ m_gdiobj; +}; + // a class for temporary bitmaps -class CompatibleBitmap +class CompatibleBitmap : private AutoGDIObject { public: CompatibleBitmap(HDC hdc, int w, int h) + : AutoGDIObject(::CreateCompatibleBitmap(hdc, w, h)) { - m_hbmp = ::CreateCompatibleBitmap(hdc, w, h); } - ~CompatibleBitmap() - { - if ( m_hbmp ) - ::DeleteObject(m_hbmp); - } + operator HBITMAP() const { return (HBITMAP)GetObject(); } +}; - operator HBITMAP() const { return m_hbmp; } +// class automatically destroys the region object +class AutoHRGN : private AutoGDIObject +{ +public: + AutoHRGN(HRGN hrgn) : AutoGDIObject(hrgn) { } -private: - HBITMAP m_hbmp; + operator HRGN() const { return (HRGN)GetObject(); } }; // when working with global pointers (which is unfortunately still necessary @@ -557,8 +570,8 @@ private: #define GetHaccel() ((HACCEL)GetHACCEL()) #define GetHaccelOf(table) ((HACCEL)((table).GetHACCEL())) -#define GetHbrush() ((HPEN)GetResourceHandle()) -#define GetHbrushOf(brush) ((HPEN)(brush).GetResourceHandle()) +#define GetHbrush() ((HBRUSH)GetResourceHandle()) +#define GetHbrushOf(brush) ((HBRUSH)(brush).GetResourceHandle()) #define GetHmenu() ((HMENU)GetHMenu()) #define GetHmenuOf(menu) ((HMENU)menu->GetHMenu()) @@ -740,5 +753,4 @@ inline void *wxSetWindowUserData(HWND hwnd, void *data) #endif // wxUSE_GUI -#endif - // _WX_PRIVATE_H_ +#endif // _WX_PRIVATE_H_ -- 2.49.0