\r
namespace sf \r
{\r
+\r
template <typename ProcType> \r
typename base_win32_window<ProcType>::result_t base_win32_window<ProcType>::window_proc(HWND hwnd,uint32_t message, WPARAM wParam, LPARAM lParam)\r
{\r
HICON hIconSm\r
) \r
{\r
- wnd_class_.reset(new sf::window_class_ex(menu_name,name_,HINST_THISCOMPONENT,thunk_proc_,style,cbClsExtra,cbWndExtra,hIcon,hCursor,hbrBackground,hIconSm));\r
+ wnd_class_.reset(new sf::window_class_ex(menu_name,name_,HINST_THISCOMPONENT,&start_wnd_proc,style,cbClsExtra,cbWndExtra,hIcon,hCursor,hbrBackground,hIconSm));\r
}\r
\r
/** デフォルト設定 */\r
template <typename ProcType> \r
void base_win32_window<ProcType>::register_class()\r
{\r
- wnd_class_.reset(new sf::window_class_ex(0,name_,HINST_THISCOMPONENT,thunk_proc_));\r
+ wnd_class_.reset(new sf::window_class_ex(0,name_,HINST_THISCOMPONENT,&start_wnd_proc));\r
}\r
\r
template <typename ProcType> \r
bool left_button_,middle_button_,right_button_;\r
};\r
\r
+ // ウィンドウプロシージャの識別用クラス\r
struct wndproc \r
{\r
typedef WNDPROC proc_type;\r
}\r
};\r
\r
+ // ダイアログプロシージャの識別用クラス\r
struct dlgproc\r
{\r
typedef DLGPROC proc_type;\r
virtual result_t on_notify(NMHDR* nmhdr) { return std::is_same<proc_t,wndproc>::value?0:FALSE; } \r
\r
protected:\r
+\r
+ // Window生成後呼ばれる関数\r
+ // WM_NCCREATEメッセージの時にthunkに切り替える\r
+ static result_t CALLBACK start_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)\r
+ {\r
+ if(message == WM_NCCREATE)\r
+ {\r
+ LPCREATESTRUCT param = reinterpret_cast<LPCREATESTRUCT>(lParam);\r
+ base_win32_window* ptr = reinterpret_cast<base_win32_window*>(param->lpCreateParams);\r
+ ptr->hwnd_ = hwnd;\r
+ // ウィンドウプロシージャをインスタンスと結び付けるthunkプロシージャに入れ替える\r
+ LONG_PTR r = SetWindowLongPtr(hwnd,GWLP_WNDPROC,reinterpret_cast<LONG_PTR>(ptr->thunk_proc_));\r
+ assert(r == reinterpret_cast<LONG_PTR>(&start_wnd_proc));\r
+ return ptr->window_proc(hwnd,message,wParam,lParam);\r
+ }\r
+ return ::DefWindowProcW(hwnd,message,wParam,lParam);\r
+ };\r
+\r
static result_t CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)\r
{\r
base_win32_window* ptr = reinterpret_cast<base_win32_window*>(hwnd);\r
- hwnd = ptr->hwnd_;\r
- // TODO: メッセージハンドラを拡張可能にする。\r
- return ptr->window_proc(hwnd,message,wParam,lParam);\r
+ return ptr->window_proc(ptr->hwnd_,message,wParam,lParam);\r
};\r
\r
// thisとhwndをつなぐthunkクラス\r
typename proc_t::proc_type thunk_proc_;\r
dpi dpi_;\r
WINDOWPLACEMENT wp_;\r
+\r
+ // __declspec ( thread ) static std::queue<proc_t::proc_type> ptrs_ ;// thread local storage\r
+\r
};\r
\r
typedef base_win32_window<> base_win32_window_t;\r