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_PEN_H 00023 #define _SPRINT_PEN_H 00024 00027 namespace sprint { 00028 namespace gtl { 00029 00031 template <bool t_bManaged> 00032 class CPenT 00033 { 00034 public: 00035 // Data members 00036 HPEN m_hPen; 00037 00038 // Constructor/destructor/operators 00039 CPenT(HPEN hPen = NULL) : m_hPen(hPen) 00040 { } 00041 00042 ~CPenT() 00043 { 00044 if(t_bManaged && m_hPen != NULL) 00045 DeleteObject(); 00046 } 00047 00048 CPenT<t_bManaged>& operator =(HPEN hPen) 00049 { 00050 Attach(hPen); 00051 return *this; 00052 } 00053 00054 void Attach(HPEN hPen) 00055 { 00056 if(t_bManaged && m_hPen != NULL && m_hPen != hPen) 00057 ::DeleteObject(m_hPen); 00058 m_hPen = hPen; 00059 } 00060 00061 HPEN Detach() 00062 { 00063 HPEN hPen = m_hPen; 00064 m_hPen = NULL; 00065 return hPen; 00066 } 00067 00068 operator HPEN() const { return m_hPen; } 00069 00070 bool IsNull() const { return (m_hPen == NULL); } 00071 00072 // Create methods 00073 HPEN CreatePen(int nPenStyle, int nWidth, COLORREF crColor) 00074 { 00075 m_hPen = ::CreatePen(nPenStyle, nWidth, crColor); 00076 return m_hPen; 00077 } 00078 00079 HPEN CreateSolidPen(int nWidth, COLORREF crColor) 00080 { 00081 return CreatePen(PS_SOLID, nWidth, crColor); 00082 } 00083 00084 #ifndef _WIN32_WCE 00085 HPEN CreatePen(int nPenStyle, int nWidth, const LOGBRUSH* pLogBrush, int nStyleCount = 0, const DWORD* lpStyle = NULL) 00086 { 00087 m_hPen = ::ExtCreatePen(nPenStyle, nWidth, pLogBrush, nStyleCount, lpStyle); 00088 return m_hPen; 00089 } 00090 #endif // !_WIN32_WCE 00091 00092 HPEN CreatePenIndirect(LPLOGPEN lpLogPen) 00093 { 00094 m_hPen = ::CreatePenIndirect(lpLogPen); 00095 return m_hPen; 00096 } 00097 00098 BOOL DeleteObject() 00099 { 00100 BOOL bRet = ::DeleteObject(m_hPen); 00101 if(bRet) 00102 m_hPen = NULL; 00103 return bRet; 00104 } 00105 00106 // Attributes 00107 int GetLogPen(LOGPEN* pLogPen) const 00108 { 00109 return ::GetObject(m_hPen, sizeof(LOGPEN), pLogPen); 00110 } 00111 00112 bool GetLogPen(LOGPEN& LogPen) const 00113 { 00114 return (::GetObject(m_hPen, sizeof(LOGPEN), &LogPen) == sizeof(LOGPEN)); 00115 } 00116 00117 #ifndef _WIN32_WCE 00118 int GetExtLogPen(EXTLOGPEN* pLogPen) const 00119 { 00120 return ::GetObject(m_hPen, sizeof(EXTLOGPEN), pLogPen); 00121 } 00122 00123 bool GetExtLogPen(EXTLOGPEN& ExtLogPen) const 00124 { 00125 return (::GetObject(m_hPen, sizeof(EXTLOGPEN), &ExtLogPen) == sizeof(EXTLOGPEN)); 00126 } 00127 #endif // !_WIN32_WCE 00128 }; 00129 00131 typedef CPenT<false> CPenHandle; 00133 typedef CPenT<true> CPen; 00134 00135 } // gtl 00136 } // sprint 00137 00138 #endif