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.

245 lines
8.1 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: atlstl/window/window.hpp
  3. *
  4. * Purpose: Enhancement of ATL's CWindow, supporting shims for common
  5. * operations.
  6. *
  7. * Created: 25th November 2006
  8. * Updated: 10th August 2009
  9. *
  10. * Home: http://stlsoft.org/
  11. *
  12. * Copyright (c) 2007-2009, Matthew Wilson and Synesis Software
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are met:
  17. *
  18. * - Redistributions of source code must retain the above copyright notice, this
  19. * list of conditions and the following disclaimer.
  20. * - Redistributions in binary form must reproduce the above copyright notice,
  21. * this list of conditions and the following disclaimer in the documentation
  22. * and/or other materials provided with the distribution.
  23. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  24. * any contributors may be used to endorse or promote products derived from
  25. * this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  28. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  30. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  31. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  33. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  34. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  35. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  36. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * ////////////////////////////////////////////////////////////////////// */
  40. /** \file atlstl/window/window.hpp
  41. * \brief [C++ only; requires ATL library] Definition of the
  42. * atlstl::Window class, which is an enhancement of ATL's CWindow,
  43. * supporting shims for common operations
  44. * (\ref group__library__windows_window "Windows Window" Library).
  45. */
  46. #ifndef ATLSTL_INCL_ATLSTL_WINDOW_HPP_WINDOW
  47. #define ATLSTL_INCL_ATLSTL_WINDOW_HPP_WINDOW
  48. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  49. # define ATLSTL_VER_ATLSTL_WINDOW_HPP_WINDOW_MAJOR 1
  50. # define ATLSTL_VER_ATLSTL_WINDOW_HPP_WINDOW_MINOR 0
  51. # define ATLSTL_VER_ATLSTL_WINDOW_HPP_WINDOW_REVISION 2
  52. # define ATLSTL_VER_ATLSTL_WINDOW_HPP_WINDOW_EDIT 7
  53. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  54. /* /////////////////////////////////////////////////////////////////////////
  55. * Includes
  56. */
  57. #ifndef ATLSTL_INCL_ATLSTL_HPP_ATLSTL
  58. # include <atlstl/atlstl.hpp>
  59. #endif /* !ATLSTL_INCL_ATLSTL_HPP_ATLSTL */
  60. #ifndef ATLSTL_INCL_ATLSTL_WINDOW_HPP_ENHANCED_WINDOW
  61. # include <atlstl/window/enhanced_window.hpp>
  62. #endif /* !ATLSTL_INCL_ATLSTL_WINDOW_HPP_ENHANCED_WINDOW */
  63. #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
  64. # include <stlsoft/shims/access/string.hpp>
  65. #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING */
  66. /* /////////////////////////////////////////////////////////////////////////
  67. * Namespace
  68. */
  69. #ifndef _ATLSTL_NO_NAMESPACE
  70. # if defined(_STLSOFT_NO_NAMESPACE) || \
  71. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  72. /* There is no stlsoft namespace, so must define ::atlstl */
  73. namespace atlstl
  74. {
  75. # else
  76. /* Define stlsoft::atlstl_project */
  77. namespace stlsoft
  78. {
  79. namespace atlstl_project
  80. {
  81. # endif /* _STLSOFT_NO_NAMESPACE */
  82. #endif /* !_ATLSTL_NO_NAMESPACE */
  83. /* /////////////////////////////////////////////////////////////////////////
  84. * Classes
  85. */
  86. /** \brief This class inherits from ATL's CWindow, and provides enhanced
  87. * string operations (using string access shims) and additional
  88. * functionality (via the EnhancedWindow mixin class template).
  89. *
  90. * \ingroup group__library__windows_window
  91. */
  92. // [[synesis:class:ui-window: atlstl::Window]]
  93. class Window
  94. : public CWindow
  95. , public EnhancedWindow<Window>
  96. {
  97. /// \name Member Types
  98. /// @{
  99. public:
  100. typedef CWindow parent_class_type;
  101. typedef Window class_type;
  102. /// @}
  103. /// \name Construction
  104. /// @{
  105. public:
  106. /// \brief Constructs an instance of Window
  107. explicit Window(HWND hwnd = NULL)
  108. : parent_class_type(hwnd)
  109. {}
  110. /// \brief Assigns a window handle to the instance
  111. class_type& operator =(HWND hwnd)
  112. {
  113. parent_class_type::operator =(hwnd);
  114. return *this;
  115. }
  116. /// \brief Creates a window.
  117. template< ss_typename_param_k S0
  118. , ss_typename_param_k S1
  119. >
  120. HWND Create(S0 const& lpstrWndClass
  121. , HWND hWndParent
  122. , RECT &rcPos
  123. , S1 const &szWindowName = NULL
  124. , DWORD dwStyle = 0
  125. , DWORD dwExStyle = 0
  126. , UINT nID = 0
  127. , LPVOID lpCreateParam = NULL)
  128. {
  129. return parent_class_type::Create(stlsoft::c_str_ptr(lpstrWndClass), hWndParent, rcPos, stlsoft::c_str_ptr(szWindowName), dwStyle, dwExStyle, nID, lpCreateParam);
  130. }
  131. /// \brief Creates a window.
  132. template< ss_typename_param_k S0
  133. , ss_typename_param_k S1
  134. >
  135. HWND Create(S0 const& lpstrWndClass
  136. , HWND hWndParent
  137. , LPRECT lpRect = NULL
  138. , S1 const& szWindowName = NULL
  139. , DWORD dwStyle = 0
  140. , DWORD dwExStyle = 0
  141. , HMENU hMenu = NULL
  142. , LPVOID lpCreateParam = NULL)
  143. {
  144. return parent_class_type::Create(stlsoft::c_str_ptr(lpstrWndClass), hWndParent, lpRect, stlsoft::c_str_ptr(szWindowName), dwStyle, dwExStyle, nID, lpCreateParam);
  145. }
  146. /// @}
  147. /// \name Operations
  148. /// @{
  149. public:
  150. // Window Text Functions
  151. /// \brief Invokes <code>CWindow::SetWindowText()</code> for an arbitrary string type.
  152. template <ss_typename_param_k S>
  153. BOOL SetWindowText(S const& lpszString)
  154. {
  155. return parent_class_type::SetWindowText(stlsoft::c_str_ptr(lpszString));
  156. }
  157. // Dialog Functions
  158. template <ss_typename_param_k S>
  159. BOOL SetDlgItemText(int nID, S const& lpszString)
  160. {
  161. return parent_class_type::SetDlgItemText(nID, stlsoft::c_str_ptr(lpszString));
  162. }
  163. // Alert Functions
  164. template <ss_typename_param_k S>
  165. int MessageBox(S const& lpszText)
  166. {
  167. return parent_class_type::MessageBox(stlsoft::c_str_ptr(lpszText));
  168. }
  169. template< ss_typename_param_k S0
  170. , ss_typename_param_k S1
  171. >
  172. int MessageBox(S0 const& lpszText, S1 const& lpszCaption)
  173. {
  174. return parent_class_type::MessageBox(stlsoft::c_str_ptr(lpszText), stlsoft::c_str_ptr(lpszCaption));
  175. }
  176. template< ss_typename_param_k S0
  177. , ss_typename_param_k S1
  178. >
  179. int MessageBox(S0 const& lpszText, S1 const& lpszCaption, UINT nType)
  180. {
  181. return parent_class_type::MessageBox(stlsoft::c_str_ptr(lpszText), stlsoft::c_str_ptr(lpszCaption), nType);
  182. }
  183. // Help Functions
  184. template <ss_typename_param_k S>
  185. BOOL WinHelp(S const& lpszHelp, UINT nCmd = HELP_CONTEXT, DWORD dwData = 0)
  186. {
  187. return parent_class_type::WinHelp(stlsoft::c_str_ptr(lpszHelp), nCmd, dwData);
  188. }
  189. /// @}
  190. /// \name Not to be implemented
  191. /// @{
  192. private:
  193. Window(class_type const&);
  194. class_type& operator =(class_type const&);
  195. /// @}
  196. };
  197. /* ////////////////////////////////////////////////////////////////////// */
  198. #ifndef _ATLSTL_NO_NAMESPACE
  199. # if defined(_STLSOFT_NO_NAMESPACE) || \
  200. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  201. } // namespace atlstl
  202. # else
  203. } // namespace atlstl_project
  204. } // namespace stlsoft
  205. # endif /* _STLSOFT_NO_NAMESPACE */
  206. #endif /* !_ATLSTL_NO_NAMESPACE */
  207. /* ////////////////////////////////////////////////////////////////////// */
  208. #endif /* ATLSTL_INCL_ATLSTL_WINDOW_HPP_SYNESIS_ABOUT_DIALOG */
  209. /* ///////////////////////////// end of file //////////////////////////// */