00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00047 #ifndef WINSTL_INCL_WINSTL_SYSTEM_HPP_CONSOLE_COLOUR_SCOPE
00048 #define WINSTL_INCL_WINSTL_SYSTEM_HPP_CONSOLE_COLOUR_SCOPE
00049
00050 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00051 # define WINSTL_VER_WINSTL_SYSTEM_HPP_CONSOLE_COLOUR_SCOPE_MAJOR 1
00052 # define WINSTL_VER_WINSTL_SYSTEM_HPP_CONSOLE_COLOUR_SCOPE_MINOR 0
00053 # define WINSTL_VER_WINSTL_SYSTEM_HPP_CONSOLE_COLOUR_SCOPE_REVISION 5
00054 # define WINSTL_VER_WINSTL_SYSTEM_HPP_CONSOLE_COLOUR_SCOPE_EDIT 9
00055 #endif
00056
00057
00058
00059
00060
00061 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00062 # include <winstl/winstl.h>
00063 #endif
00064 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00065 # ifndef WINSTL_INCL_WINSTL_ERROR_HPP_EXCEPTIONS
00066 # include <winstl/error/exceptions.hpp>
00067 # endif
00068 #endif
00069
00070
00071
00072
00073
00074 #ifndef _WINSTL_NO_NAMESPACE
00075 # if defined(_STLSOFT_NO_NAMESPACE) || \
00076 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00077
00078 namespace winstl
00079 {
00080 # else
00081
00082
00083 namespace stlsoft
00084 {
00085
00086 namespace winstl_project
00087 {
00088
00089 # endif
00090 #endif
00091
00092
00093
00094
00095
00104 class console_colour_scope
00105 {
00106 public:
00108 typedef console_colour_scope class_type;
00109
00110
00111 public:
00128 ss_explicit_k console_colour_scope(HANDLE hBuffer, WORD textAttributes)
00129 : m_hBuffer(hBuffer)
00130 , m_attributes(init_(hBuffer, textAttributes))
00131 {}
00132
00134 ~console_colour_scope() stlsoft_throw_0()
00135 {
00136 #ifndef STLSOFT_CF_EXCEPTION_SUPPORT
00137 if(0xffffffff != m_attributes)
00138 #endif
00139 {
00140 ::SetConsoleTextAttribute(m_hBuffer, static_cast<WORD>(m_attributes));
00141 }
00142 }
00143
00146 private:
00147 static ws_uint32_t init_(HANDLE hBuffer, WORD textAttributes)
00148 {
00149 ws_uint32_t attr = 0xffffffff;
00150 CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
00151
00152 if(!::GetConsoleScreenBufferInfo(hBuffer, &bufferInfo))
00153 {
00154 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00155 STLSOFT_THROW_X(windows_exception("Could not retrieve console buffer information", ::GetLastError()));
00156 #endif
00157 }
00158 else
00159 {
00160 if(!::SetConsoleTextAttribute(hBuffer, textAttributes))
00161 {
00162 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00163 STLSOFT_THROW_X(windows_exception("Could not set console text attributes", ::GetLastError()));
00164 #endif
00165 }
00166 else
00167 {
00168 attr = bufferInfo.wAttributes;
00169 }
00170 }
00171
00172 return attr;
00173 }
00175
00178 private:
00179 HANDLE m_hBuffer;
00180 ws_uint32_t m_attributes;
00182
00185 private:
00186 console_colour_scope(class_type const& rhs);
00187 class_type const& operator =(class_type const& rhs);
00189 };
00190
00191
00192
00193 #ifndef _WINSTL_NO_NAMESPACE
00194 # if defined(_STLSOFT_NO_NAMESPACE) || \
00195 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00196 }
00197 # else
00198 }
00199 }
00200 # endif
00201 #endif
00202
00203
00204
00205 #endif
00206
00207