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.

168 lines
5.8 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/window/window_redraw_scope.hpp
  3. *
  4. * Purpose: Window redraw-state scoping class.
  5. *
  6. * Created: 5th January 1996
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 1996-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/window_redraw_scope.hpp
  40. *
  41. * \brief [C++ only] Definition of the winstl::window_redraw_scope class
  42. * (\ref group__library__windows_window "Windows Window" Library).
  43. */
  44. #ifndef WINSTL_INCL_WINSTL_WINDOW_HPP_WINDOW_REDRAW_SCOPE
  45. #define WINSTL_INCL_WINSTL_WINDOW_HPP_WINDOW_REDRAW_SCOPE
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define WINSTL_VER_WINSTL_WINDOW_HPP_WINDOW_REDRAW_SCOPE_MAJOR 5
  48. # define WINSTL_VER_WINSTL_WINDOW_HPP_WINDOW_REDRAW_SCOPE_MINOR 1
  49. # define WINSTL_VER_WINSTL_WINDOW_HPP_WINDOW_REDRAW_SCOPE_REVISION 1
  50. # define WINSTL_VER_WINSTL_WINDOW_HPP_WINDOW_REDRAW_SCOPE_EDIT 76
  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. #ifndef WINSTL_INCL_SHIMS_ATTRIBUTE_HPP_GET_HWND
  59. # include <winstl/shims/attribute/get_HWND.hpp>
  60. #endif /* !WINSTL_INCL_SHIMS_ATTRIBUTE_HPP_GET_HWND */
  61. /* /////////////////////////////////////////////////////////////////////////
  62. * Namespace
  63. */
  64. #ifndef _WINSTL_NO_NAMESPACE
  65. # if defined(_STLSOFT_NO_NAMESPACE) || \
  66. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  67. /* There is no stlsoft namespace, so must define ::winstl */
  68. namespace winstl
  69. {
  70. # else
  71. /* Define stlsoft::winstl_project */
  72. namespace stlsoft
  73. {
  74. namespace winstl_project
  75. {
  76. # endif /* _STLSOFT_NO_NAMESPACE */
  77. #endif /* !_WINSTL_NO_NAMESPACE */
  78. /* /////////////////////////////////////////////////////////////////////////
  79. * Classes
  80. */
  81. // window_redraw_scope
  82. /** \brief Provides scoping of the redraw status of a window.
  83. *
  84. * \ingroup group__library__windows_window
  85. *
  86. * This class provides scoping of the redraw status of a window via the
  87. * WM_SETREDRAW message.
  88. */
  89. class window_redraw_scope
  90. {
  91. public:
  92. /// This type
  93. typedef window_redraw_scope class_type;
  94. // Construction
  95. public:
  96. /// Attempts to lock the given window from redrawing.
  97. ///
  98. /// Takes a HWND and changes it's current redraw-status, which is set back to
  99. /// the original state in the destructor.
  100. ///
  101. /// \param wnd The window whose redraw state is to be controlled
  102. /// \param bInvalidateOnUnlock Determines whether the window is invalidated upon destruction
  103. #ifdef STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
  104. template <ss_typename_param_k W>
  105. ss_explicit_k window_redraw_scope(W &wnd, ws_bool_t bInvalidateOnUnlock = true)
  106. : m_hwnd(get_HWND(wnd))
  107. #else
  108. ss_explicit_k window_redraw_scope(HWND wnd, ws_bool_t bInvalidateOnUnlock = true)
  109. : m_hwnd(wnd)
  110. #endif /* STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT */
  111. , m_bInvalidateOnUnlock(bInvalidateOnUnlock)
  112. {
  113. ::SendMessage(m_hwnd, WM_SETREDRAW, false, 0L);
  114. }
  115. /// Resets the redraw status, and invalidates the window, if requested in the constructor
  116. ~window_redraw_scope() stlsoft_throw_0()
  117. {
  118. ::SendMessage(m_hwnd, WM_SETREDRAW, true, 0L);
  119. if(m_bInvalidateOnUnlock)
  120. {
  121. ::InvalidateRect(m_hwnd, NULL, true);
  122. }
  123. }
  124. // Members
  125. private:
  126. HWND m_hwnd;
  127. ws_bool_t m_bInvalidateOnUnlock;
  128. // Not to be implemented
  129. private:
  130. window_redraw_scope(class_type const& rhs);
  131. class_type const& operator =(class_type const& rhs);
  132. };
  133. /* ////////////////////////////////////////////////////////////////////// */
  134. #ifndef _WINSTL_NO_NAMESPACE
  135. # if defined(_STLSOFT_NO_NAMESPACE) || \
  136. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  137. } // namespace winstl
  138. # else
  139. } // namespace winstl_project
  140. } // namespace stlsoft
  141. # endif /* _STLSOFT_NO_NAMESPACE */
  142. #endif /* !_WINSTL_NO_NAMESPACE */
  143. /* ////////////////////////////////////////////////////////////////////// */
  144. #endif /* WINSTL_INCL_WINSTL_WINDOW_HPP_WINDOW_REDRAW_SCOPE */
  145. /* ///////////////////////////// end of file //////////////////////////// */