windows_message_handler.hpp
Go to the documentation of this file.
00001 /* 00002 Copyright 2005-2007 Adobe Systems Incorporated 00003 Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt 00004 or a copy at http://stlab.adobe.com/licenses.html) 00005 */ 00006 00007 /**************************************************************************************************/ 00008 00009 #ifndef ADOBE_WINDOWS_MESSAGE_HANDLER_HPP 00010 #define ADOBE_WINDOWS_MESSAGE_HANDLER_HPP 00011 00012 /**************************************************************************************************/ 00013 00014 #include <adobe/config.hpp> 00015 00016 #include <boost/function.hpp> 00017 #include <boost/noncopyable.hpp> 00018 00019 #include <windows.h> 00020 00021 /**************************************************************************************************/ 00022 00023 namespace adobe { 00024 00025 /**************************************************************************************************/ 00026 00030 class message_handler_t : boost::noncopyable 00031 { 00032 public: 00043 typedef boost::function<LRESULT (HWND window, UINT message, WPARAM wparam, LPARAM lparam, WNDPROC next_proc)> callback_t; 00044 00045 message_handler_t(callback_t callback = callback_t()); 00046 00047 ~message_handler_t(); 00048 00065 template <const char* ProcName> 00066 inline void install(HWND window) 00067 { install_implementation(window, ProcName, &win_proc<ProcName>); } 00068 00069 void uninstall(); 00070 00071 inline bool is_installed() const 00072 { return NULL != property_m; } 00073 00074 inline void set_callback(callback_t callback) 00075 { callback_m = callback; } 00076 00077 private: 00078 struct property_t 00079 { 00080 message_handler_t* handler_m; 00081 WNDPROC next_proc_m; 00082 }; 00083 00084 property_t* property_m; 00085 callback_t callback_m; 00086 00087 void install_implementation(HWND window, const char* proc_name, WNDPROC win_proc); 00088 00089 static void set_handler_property(HWND window, const char* proc_name, property_t* property); 00090 00091 static void remove_handler_property(HWND window, const char* proc_name); 00092 00093 static property_t* get_handler_property(HWND window, const char* proc_name); 00094 00095 static LRESULT win_proc_implementation(HWND window, UINT message, WPARAM wparam, LPARAM lparam, const char* proc_name); 00096 00097 template <const char* ProcName> 00098 static LRESULT CALLBACK win_proc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) 00099 { 00100 return win_proc_implementation(window, message, wparam, lparam, ProcName); 00101 } 00102 }; 00103 00104 /**************************************************************************************************/ 00105 00106 } // namespace adobe 00107 00108 /**************************************************************************************************/ 00109 00110 #endif 00111 00112 /**************************************************************************************************/ |