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.

240 lines
9.6 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/window/window_icon_scope.hpp (originally MWIcnScp.h; ::SynesisWin)
  3. *
  4. * Purpose: Window icon scoping class.
  5. *
  6. * Created: 30th June 1999
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 1999-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_icon_scope.hpp
  40. *
  41. * \brief [C++ only] Definition of the winstl::window_icon_scope class
  42. * (\ref group__library__windows_window "Windows Window" Library).
  43. */
  44. #ifndef WINSTL_INCL_WINSTL_WINDOW_HPP_WINDOW_ICON_SCOPE
  45. #define WINSTL_INCL_WINSTL_WINDOW_HPP_WINDOW_ICON_SCOPE
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define WINSTL_VER_WINSTL_WINDOW_HPP_WINDOW_ICON_SCOPE_MAJOR 4
  48. # define WINSTL_VER_WINSTL_WINDOW_HPP_WINDOW_ICON_SCOPE_MINOR 1
  49. # define WINSTL_VER_WINSTL_WINDOW_HPP_WINDOW_ICON_SCOPE_REVISION 1
  50. # define WINSTL_VER_WINSTL_WINDOW_HPP_WINDOW_ICON_SCOPE_EDIT 50
  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. #ifndef WINSTL_INCL_WINSTL_WINDOW_H_FUNCTIONS
  62. # include <winstl/window/functions.h>
  63. #endif /* !WINSTL_INCL_WINSTL_WINDOW_H_FUNCTIONS */
  64. /* /////////////////////////////////////////////////////////////////////////
  65. * Namespace
  66. */
  67. #ifndef _WINSTL_NO_NAMESPACE
  68. # if defined(_STLSOFT_NO_NAMESPACE) || \
  69. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  70. /* There is no stlsoft namespace, so must define ::winstl */
  71. namespace winstl
  72. {
  73. # else
  74. /* Define stlsoft::winstl_project */
  75. namespace stlsoft
  76. {
  77. namespace winstl_project
  78. {
  79. # endif /* _STLSOFT_NO_NAMESPACE */
  80. #endif /* !_WINSTL_NO_NAMESPACE */
  81. /* /////////////////////////////////////////////////////////////////////////
  82. * Classes
  83. */
  84. // window_icon_scope
  85. /** \brief Provides scoping of the icon(s) of a window.
  86. *
  87. * \ingroup group__library__windows_window
  88. *
  89. * This class provides scoping of the icon(s) of a window via the WM_SETICON
  90. * message.
  91. */
  92. class window_icon_scope
  93. {
  94. public:
  95. /// This type
  96. typedef window_icon_scope class_type;
  97. // Construction
  98. public:
  99. /// \brief Toggles the icon of a window
  100. ///
  101. /// Takes a HWND and sets its icon, which is then reset to the original in
  102. /// the destructor.
  103. ///
  104. /// \param wnd The window whose enable state is to be controlled
  105. /// \param iconType The identifier of the window's icon property to be changed. Should be either \c ICON_BIG or \c ICON_SMALL
  106. /// \param hicon The handle of the icon to associate with the given window's identified icon property
  107. window_icon_scope(HWND wnd, int iconType, HICON hicon)
  108. : m_hwnd(wnd)
  109. , m_iconId(iconType)
  110. , m_hicon(set_window_icon(m_hwnd, iconType, hicon))
  111. {}
  112. /// \brief Toggles the icon of a window
  113. ///
  114. /// Takes a HWND and sets its icon, which is then reset to the original in
  115. /// the destructor.
  116. ///
  117. /// \param wnd The window whose enable state is to be controlled
  118. /// \param iconType The identifier of the window's icon property to be changed. Should be either \c ICON_BIG or \c ICON_SMALL
  119. /// \param hinst The module from which the named icon is to be loaded
  120. /// \param iconName The name of the icon to associate with the given window's identified icon property
  121. window_icon_scope(HWND wnd, int iconType, HINSTANCE hinst, LPCTSTR iconName)
  122. : m_hwnd(wnd)
  123. , m_iconId(iconType)
  124. , m_hicon(set_window_icon(m_hwnd, iconType, hinst, iconName))
  125. {}
  126. /// \brief Toggles the icon of a window
  127. ///
  128. /// Takes a HWND and sets its icon, which is then reset to the original in
  129. /// the destructor.
  130. ///
  131. /// \param wnd The window whose enable state is to be controlled
  132. /// \param iconType The identifier of the window's icon property to be changed. Should be either \c ICON_BIG or \c ICON_SMALL
  133. /// \param hinst The module from which the named icon is to be loaded
  134. /// \param iconId The resource identifier of the icon to associate with the given window's identified icon property
  135. window_icon_scope(HWND wnd, int iconType, HINSTANCE hinst, int iconId)
  136. : m_hwnd(wnd)
  137. , m_iconId(iconType)
  138. , m_hicon(set_window_icon(m_hwnd, iconType, hinst, iconId))
  139. {}
  140. #ifdef STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
  141. /// \brief Toggles the window enable state
  142. ///
  143. /// Takes a window and sets its icon, which is then reset to the original in
  144. /// the destructor.
  145. ///
  146. /// \param wnd The window whose enable state is to be controlled
  147. /// \param iconType The identifier of the window's icon property to be changed. Should be either \c ICON_BIG or \c ICON_SMALL
  148. /// \param hicon The handle of the icon to associate with the given window's identified icon property
  149. template <ss_typename_param_k W>
  150. window_icon_scope(W &wnd, int iconType, HICON hicon)
  151. : m_hwnd(get_HWND(wnd))
  152. , m_iconId(iconType)
  153. , m_hicon(set_window_icon(m_hwnd, iconType, hicon))
  154. {}
  155. /// \brief Toggles the window enable state
  156. ///
  157. /// Takes a window and sets its icon, which is then reset to the original in
  158. /// the destructor.
  159. ///
  160. /// \param wnd The window whose enable state is to be controlled
  161. /// \param iconType The identifier of the window's icon property to be changed. Should be either \c ICON_BIG or \c ICON_SMALL
  162. /// \param hinst The module from which the named icon is to be loaded
  163. /// \param iconName The name of the icon to associate with the given window's identified icon property
  164. template <ss_typename_param_k W>
  165. window_icon_scope(W &wnd, int iconType, HINSTANCE hinst, LPCTSTR iconName)
  166. : m_hwnd(get_HWND(wnd))
  167. , m_iconId(iconType)
  168. , m_hicon(set_window_icon(m_hwnd, iconType, hinst, iconName))
  169. {}
  170. /// \brief Toggles the window enable state
  171. ///
  172. /// Takes a window and sets its icon, which is then reset to the original in
  173. /// the destructor.
  174. ///
  175. /// \param wnd The window whose enable state is to be controlled
  176. /// \param iconType The identifier of the window's icon property to be changed. Should be either \c ICON_BIG or \c ICON_SMALL
  177. /// \param hinst The module from which the named icon is to be loaded
  178. /// \param iconId The resource identifier of the icon to associate with the given window's identified icon property
  179. template <ss_typename_param_k W>
  180. window_icon_scope(W &wnd, int iconType, HINSTANCE hinst, int iconId)
  181. : m_hwnd(get_HWND(wnd))
  182. , m_iconId(iconType)
  183. , m_hicon(set_window_icon(m_hwnd, iconType, hinst, iconId))
  184. {}
  185. #endif /* STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT */
  186. /// Resets the window's original icon
  187. ~window_icon_scope() stlsoft_throw_0()
  188. {
  189. #ifdef STLSOFT_CF_USE_RAW_OFFSETOF_IN_STATIC_ASSERT
  190. WINSTL_STATIC_ASSERT(STLSOFT_RAW_OFFSETOF(class_type, m_hwnd) < STLSOFT_RAW_OFFSETOF(class_type, m_hicon));
  191. #endif /* STLSOFT_CF_USE_RAW_OFFSETOF_IN_STATIC_ASSERT */
  192. set_window_icon(m_hwnd, m_iconId, m_hicon);
  193. }
  194. // Members
  195. private:
  196. HWND m_hwnd;
  197. int m_iconId;
  198. HICON m_hicon;
  199. // Not to be implemented
  200. private:
  201. window_icon_scope(class_type const& rhs);
  202. class_type const& operator =(class_type const& rhs);
  203. };
  204. /* ////////////////////////////////////////////////////////////////////// */
  205. #ifndef _WINSTL_NO_NAMESPACE
  206. # if defined(_STLSOFT_NO_NAMESPACE) || \
  207. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  208. } // namespace winstl
  209. # else
  210. } // namespace winstl_project
  211. } // namespace stlsoft
  212. # endif /* _STLSOFT_NO_NAMESPACE */
  213. #endif /* !_WINSTL_NO_NAMESPACE */
  214. /* ////////////////////////////////////////////////////////////////////// */
  215. #endif /* WINSTL_INCL_WINSTL_WINDOW_HPP_WINDOW_ICON_SCOPE */
  216. /* ///////////////////////////// end of file //////////////////////////// */