sprint 1-alpha
|
00001 /****************************************************************************** 00002 * GTL: GUI Template Library 00003 * A Cross Platform C++ Wrapper for Win32 users 00004 * Copyright (C) 2007-2011 Paolo Medici (www.pmx.it) 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 * 00020 *******************************************************************************/ 00021 00022 #ifndef _SPRINT_GTL_BRUSH_H 00023 #define _SPRINT_GTL_BRUSH_H 00024 00028 namespace sprint { 00029 namespace gtl { 00030 00032 template <bool t_bManaged> 00033 class CBrushT 00034 { 00035 public: 00036 // Data members 00037 HBRUSH m_hBrush; 00038 00039 // Constructor/destructor/operators 00040 CBrushT(HBRUSH hBrush = NULL) : m_hBrush(hBrush) 00041 { } 00042 00043 // costruttore con un COLORREF crea un pennello solido 00044 CBrushT(COLORREF col) : m_hBrush(::CreateSolidBrush(col)) 00045 { 00046 } 00047 00048 ~CBrushT() 00049 { 00050 if(t_bManaged && m_hBrush != NULL) 00051 DeleteObject(); 00052 } 00053 00054 CBrushT<t_bManaged>& operator =(HBRUSH hBrush) 00055 { 00056 Attach(hBrush); 00057 return *this; 00058 } 00059 00060 void Attach(HBRUSH hBrush) 00061 { 00062 if(t_bManaged && m_hBrush != NULL && m_hBrush != hBrush) 00063 ::DeleteObject(m_hBrush); 00064 m_hBrush = hBrush; 00065 } 00066 00067 HBRUSH Detach() 00068 { 00069 HBRUSH hBrush = m_hBrush; 00070 m_hBrush = NULL; 00071 return hBrush; 00072 } 00073 00074 operator HBRUSH() const { return m_hBrush; } 00075 00077 bool IsNull() const { return (m_hBrush == NULL); } 00078 00079 // Create methods 00080 HBRUSH CreateSolidBrush(COLORREF crColor) 00081 { 00082 m_hBrush = ::CreateSolidBrush(crColor); 00083 return m_hBrush; 00084 } 00085 00086 // Crea un Brush 00087 HBRUSH CreatePatternBrush(HBITMAP hBitmap) 00088 { 00089 m_hBrush = ::CreatePatternBrush(hBitmap); 00090 return m_hBrush; 00091 } 00092 00093 // Crea un Brush 00094 HBRUSH CreateSysColorBrush(int nIndex) 00095 { 00096 m_hBrush = ::GetSysColorBrush(nIndex); 00097 return m_hBrush; 00098 } 00099 00100 BOOL DeleteObject() 00101 { 00102 BOOL bRet = ::DeleteObject(m_hBrush); 00103 if(bRet) 00104 m_hBrush = NULL; 00105 return bRet; 00106 } 00107 00109 int GetLogBrush(LOGBRUSH* pLogBrush) const 00110 { 00111 return ::GetObject(m_hBrush, sizeof(LOGBRUSH), pLogBrush); 00112 } 00113 00115 bool GetLogBrush(LOGBRUSH& LogBrush) const 00116 { 00117 return (::GetObject(m_hBrush, sizeof(LOGBRUSH), &LogBrush) == sizeof(LOGBRUSH)); 00118 } 00119 }; 00120 00121 typedef CBrushT<false> CBrushHandle; 00122 typedef CBrushT<true> CBrush; 00123 00124 inline CBrushHandle BlackBrush() { return (HBRUSH)::GetStockObject(BLACK_BRUSH); } 00125 inline CBrushHandle WhiteBrush() { return (HBRUSH)::GetStockObject(WHITE_BRUSH); } 00126 00127 } 00128 } 00129 00130 #endif