006
25.11.2007, 22:35 Uhr
xXx
Devil
|
Was gibt das denn hier für nen gejammer ^^ is mir auch zu stressig, deswegen mal der HEader der entsprechenden Lib von mir:
C++: |
#if !defined(WINDOW_H__INCLUDED) #define WINDOW_H__INCLUDED
#if (_MSC_VER >= 1300) #pragma once #endif // (_MSC_VER >= 1300)
namespace winapi { //! HWND-structure wrapper class class WINAPIPP_API Window { public: Window(); virtual ~Window();
public: operator ::HWND() const { return m_hWnd; } #pragma warning(disable: 4312) static Window* FromHandle(const ::HWND& hWnd) { return reinterpret_cast<Window*>(GetWindowLongPtr(hWnd, GWL_USERDATA)); }; #pragma warning(default: 4312) typedef LRESULT (Window::*WindowProcHandler)(WPARAM, LPARAM);
private: Window(const Window&){} Window& operator=(const Window&) { return *this; }
protected: virtual void create(unsigned long, unsigned long, unsigned long, unsigned long, const char_types::string&, unsigned long, unsigned long, const char_types::string&, const ::HINSTANCE&, const ::HMENU&, Window* pParentWnd = NULL); virtual void create(const ::WNDCLASSEX&, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, const char_types::string&, const ::HMENU&, Window* pParentWnd = NULL);
public: void register_handler(UINT message, WindowProcHandler handler) { m_WindowProcHandlers[message] = handler; }
public: template<typename r> r send_message(UINT msg) const { return static_cast<r>(send_message(msg, 0, 0)); } LRESULT send_message(UINT msg, WPARAM wParam = 0u, LPARAM lParam = 0L) const { return ::SendMessage(m_hWnd, msg, wParam, lParam); } public: virtual LRESULT _message_proc(::HWND, UINT, WPARAM, LPARAM);
private: static LRESULT CALLBACK __message_proc(::HWND, UINT, WPARAM, LPARAM);
public: ::HWND const& get_handle() const { if (m_hWnd == NULL || ::IsWindow(m_hWnd) == FALSE) throw std::invalid_argument("window handle does not exist"); return m_hWnd; }
protected: ::HWND m_hWnd; #pragma warning (disable: 4251) std::map<UINT, WindowProcHandler> m_WindowProcHandlers; #pragma warning (default: 4251) ::HINSTANCE m_hInstance; }; }; // winapi
#endif // WINDOW_H__INCLUDED
|
C++: |
void Window::create(const ::WNDCLASSEX& wc,unsigned long x, unsigned long y, unsigned long width, unsigned long height, unsigned long style, unsigned long exstyle, const char_types::string& caption, const ::HMENU& hMenu, Window* pParentWnd) { m_hWnd = ::CreateWindowEx(exstyle, wc.lpszClassName, caption.c_str(), style, x, y, width, height, (pParentWnd == NULL ? NULL : pParentWnd->get_handle()), hMenu, wc.hInstance, static_cast<LPVOID>(this));
if (m_hWnd == NULL) throw std::runtime_error("window could not be created"); }
LRESULT CALLBACK Window::__message_proc(::HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { Window* pWindow = Window::FromHandle(hWnd); #pragma warning(disable: 4311) if (message == WM_NCCREATE) { pWindow = reinterpret_cast<Window*>(reinterpret_cast<::LPCREATESTRUCT>(lParam)->lpCreateParams); SetWindowLongPtr(hWnd, GWL_USERDATA, reinterpret_cast<LONG>(pWindow)); } #pragma warning(default: 4311) return (pWindow != NULL ? pWindow->_message_proc(hWnd, message, wParam, lParam) : ::DefWindowProc(hWnd, message, wParam, lParam)); }
LRESULT Window::_message_proc(::HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { std::map<UINT, WindowProcHandler>::iterator it = m_WindowProcHandlers.find(message); return (it != m_WindowProcHandlers.end() ? (this->*(*it).second)(wParam, lParam) : ::DefWindowProc(hWnd, message, wParam, lParam)); }
|
... das sollte jetzt aber reichen ... |