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.

213 lines
6.1 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/functional/message.hpp
  3. *
  4. * Purpose: Window messaging function classes and predicates.
  5. *
  6. * Created: 19th January 2001
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2001-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/functional/message.hpp
  40. *
  41. * \brief [C++ only] Window messaging function classes and predicates
  42. * (\ref group__library__functional "Functional" Library).
  43. */
  44. #ifndef WINSTL_INCL_WINSTL_FUNCTIONAL_HPP_MESSAGE
  45. #define WINSTL_INCL_WINSTL_FUNCTIONAL_HPP_MESSAGE
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define WINSTL_VER_WINSTL_FUNCTIONAL_HPP_MESSAGE_MAJOR 4
  48. # define WINSTL_VER_WINSTL_FUNCTIONAL_HPP_MESSAGE_MINOR 1
  49. # define WINSTL_VER_WINSTL_FUNCTIONAL_HPP_MESSAGE_REVISION 1
  50. # define WINSTL_VER_WINSTL_FUNCTIONAL_HPP_MESSAGE_EDIT 39
  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_WINDOW_FUNCTIONALS_NO_STD
  62. # include <functional>
  63. #else /* ? _WINSTL_WINDOW_FUNCTIONALS_NO_STD */
  64. # error Now need to write that std_binary_function stuff!!
  65. #endif /* _WINSTL_WINDOW_FUNCTIONALS_NO_STD */
  66. /* /////////////////////////////////////////////////////////////////////////
  67. * Namespace
  68. */
  69. #ifndef _WINSTL_NO_NAMESPACE
  70. # if defined(_STLSOFT_NO_NAMESPACE) || \
  71. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  72. /* There is no stlsoft namespace, so must define ::winstl */
  73. namespace winstl
  74. {
  75. # else
  76. /* Define stlsoft::winstl_project */
  77. namespace stlsoft
  78. {
  79. namespace winstl_project
  80. {
  81. # endif /* _STLSOFT_NO_NAMESPACE */
  82. #endif /* !_WINSTL_NO_NAMESPACE */
  83. /* /////////////////////////////////////////////////////////////////////////
  84. * Functor classes
  85. */
  86. /** \brief Functor used to send a message to windows
  87. *
  88. * \ingroup group__library__functional
  89. *
  90. \code
  91. \endcode
  92. */
  93. // [[synesis:class:unary-functor: message_send]]
  94. struct message_send
  95. : public std::unary_function<HWND, void>
  96. {
  97. public:
  98. /// This type
  99. typedef message_send class_type;
  100. public:
  101. message_send( UINT msg
  102. , WPARAM wparam
  103. , LPARAM lparam)
  104. : m_msg(msg)
  105. , m_wparam(wparam)
  106. , m_lparam(lparam)
  107. {}
  108. public:
  109. void operator ()(HWND hwnd) const
  110. {
  111. send_(hwnd);
  112. }
  113. template <ss_typename_param_k W>
  114. void operator ()(W &wnd) const
  115. {
  116. send_(winstl_ns_qual(get_HWND)(wnd));
  117. }
  118. private:
  119. void send_(HWND hwnd) const
  120. {
  121. ::SendMessage(hwnd, m_msg, m_wparam, m_lparam);
  122. }
  123. private:
  124. const UINT m_msg;
  125. const WPARAM m_wparam;
  126. const LPARAM m_lparam;
  127. private:
  128. class_type& operator =(class_type const&);
  129. };
  130. /** \brief Functor used to post a message to windows
  131. *
  132. * \ingroup group__library__functional
  133. *
  134. \code
  135. \endcode
  136. */
  137. // [[synesis:class:unary-functor: message_post]]
  138. struct message_post
  139. : public std::unary_function<HWND, void>
  140. {
  141. public:
  142. /// This type
  143. typedef message_post class_type;
  144. public:
  145. message_post( UINT msg
  146. , WPARAM wparam
  147. , LPARAM lparam)
  148. : m_msg(msg)
  149. , m_wparam(wparam)
  150. , m_lparam(lparam)
  151. {}
  152. public:
  153. void operator ()(HWND hwnd) const
  154. {
  155. post_(hwnd);
  156. }
  157. template <ss_typename_param_k W>
  158. void operator ()(W &wnd) const
  159. {
  160. post_(winstl_ns_qual(get_HWND)(wnd));
  161. }
  162. private:
  163. void post_(HWND hwnd) const
  164. {
  165. ::PostMessage(hwnd, m_msg, m_wparam, m_lparam);
  166. }
  167. private:
  168. const UINT m_msg;
  169. const WPARAM m_wparam;
  170. const LPARAM m_lparam;
  171. private:
  172. class_type& operator =(class_type const&);
  173. };
  174. /* ////////////////////////////////////////////////////////////////////// */
  175. #ifndef _WINSTL_NO_NAMESPACE
  176. # if defined(_STLSOFT_NO_NAMESPACE) || \
  177. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  178. } // namespace winstl
  179. # else
  180. } // namespace winstl_project
  181. } // namespace stlsoft
  182. # endif /* _STLSOFT_NO_NAMESPACE */
  183. #endif /* !_WINSTL_NO_NAMESPACE */
  184. /* ////////////////////////////////////////////////////////////////////// */
  185. #endif /* WINSTL_INCL_WINSTL_FUNCTIONAL_HPP_MESSAGE */
  186. /* ///////////////////////////// end of file //////////////////////////// */