You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
5.3 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/window/hdc_scope.hpp (originally MWGdi.h, ::SynesisWin)
  3. *
  4. * Purpose: GDI scope class.
  5. *
  6. * Created: 20th October 1994
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 1994-2009, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file winstl/window/hdc_scope.hpp
  40. *
  41. * \brief [C++ only] Definition of the winstl::HDC_scope class
  42. * (\ref group__library__windows_window "Windows Window" Library).
  43. */
  44. #ifndef WINSTL_INCL_WINSTL_WINDOW_HPP_HDC_SCOPE
  45. #define WINSTL_INCL_WINSTL_WINDOW_HPP_HDC_SCOPE
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define WINSTL_VER_WINSTL_WINDOW_HPP_HDC_SCOPE_MAJOR 3
  48. # define WINSTL_VER_WINSTL_WINDOW_HPP_HDC_SCOPE_MINOR 0
  49. # define WINSTL_VER_WINSTL_WINDOW_HPP_HDC_SCOPE_REVISION 1
  50. # define WINSTL_VER_WINSTL_WINDOW_HPP_HDC_SCOPE_EDIT 43
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Includes
  54. */
  55. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  56. # include <winstl/winstl.h>
  57. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  58. /* /////////////////////////////////////////////////////////////////////////
  59. * Namespace
  60. */
  61. #ifndef _WINSTL_NO_NAMESPACE
  62. # if defined(_STLSOFT_NO_NAMESPACE) || \
  63. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  64. /* There is no stlsoft namespace, so must define ::winstl */
  65. namespace winstl
  66. {
  67. # else
  68. /* Define stlsoft::winstl_project */
  69. namespace stlsoft
  70. {
  71. namespace winstl_project
  72. {
  73. # endif /* _STLSOFT_NO_NAMESPACE */
  74. #endif /* !_WINSTL_NO_NAMESPACE */
  75. /* /////////////////////////////////////////////////////////////////////////
  76. * Classes
  77. */
  78. /** \brief Scopes the device context of a window
  79. *
  80. * \ingroup group__library__windows_window
  81. */
  82. class HDC_scope
  83. {
  84. /// \name Types
  85. /// @{
  86. public:
  87. typedef HDC_scope class_type;
  88. typedef HDC (WINAPI *HDC_get_fn_type)(HWND);
  89. /// @}
  90. /// \name Construction
  91. /// @{
  92. public:
  93. /// Constructor
  94. ///
  95. /// \param hdc The device context
  96. /// \param hwnd The window associated with the device context
  97. HDC_scope(HDC hdc, HWND hwnd)
  98. : m_hdc(hdc)
  99. , m_hwnd(hwnd)
  100. {
  101. WINSTL_ASSERT(NULL != hwnd);
  102. }
  103. /// Constructor
  104. ///
  105. /// \param hwnd The window associated with the device context
  106. /// \param pfn The function that will retrive the device context from the given window
  107. HDC_scope(HWND hwnd, HDC_get_fn_type pfn)
  108. : m_hdc(pfn(hwnd))
  109. , m_hwnd(hwnd)
  110. {
  111. WINSTL_ASSERT(NULL != hwnd);
  112. }
  113. /// Releases the device context associated with the window
  114. ~HDC_scope() stlsoft_throw_0()
  115. {
  116. if(NULL != m_hdc)
  117. {
  118. ::ReleaseDC(m_hwnd, m_hdc);
  119. }
  120. }
  121. /// @}
  122. /// \name Accessors
  123. /// @{
  124. public:
  125. /// The device context
  126. HDC get_hdc() const
  127. {
  128. return m_hdc;
  129. }
  130. /// The window handle
  131. HWND get_hwnd() const
  132. {
  133. return m_hwnd;
  134. }
  135. /// @}
  136. /// \name Members
  137. /// @{
  138. private:
  139. HDC m_hdc;
  140. HWND m_hwnd;
  141. /// @}
  142. // Not to be implemented
  143. private:
  144. HDC_scope(class_type const&);
  145. class_type& operator =(class_type const&);
  146. };
  147. /* ////////////////////////////////////////////////////////////////////// */
  148. #ifndef _WINSTL_NO_NAMESPACE
  149. # if defined(_STLSOFT_NO_NAMESPACE) || \
  150. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  151. } // namespace winstl
  152. # else
  153. } // namespace winstl_project
  154. } // namespace stlsoft
  155. # endif /* _STLSOFT_NO_NAMESPACE */
  156. #endif /* !_WINSTL_NO_NAMESPACE */
  157. /* ////////////////////////////////////////////////////////////////////// */
  158. #endif /* WINSTL_INCL_WINSTL_WINDOW_HPP_HDC_SCOPE */
  159. /* ///////////////////////////// end of file //////////////////////////// */