OSDN Git Service

ラッパ部分の改良
authorSFPGMR <sfpg@git.sourceforge.jp>
Sun, 29 Jan 2012 08:04:28 +0000 (17:04 +0900)
committerSFPGMR <sfpg@git.sourceforge.jp>
Sun, 29 Jan 2012 08:04:28 +0000 (17:04 +0900)
winwrapper/application.cpp
winwrapper/sf_windows.cpp
winwrapper/sf_windows.h

index 23f9990..f7f6554 100644 (file)
@@ -119,8 +119,6 @@ namespace sf {
     // ウィンドウの作成\r
     window_.reset(new sf::test_window(\r
       std::wstring(L"Windowラッパライブラリ"),std::wstring(L"Windowラッパライブラリ"),false,640,480));\r
-    //window_->create();\r
-\r
     // メッセージループ\r
     WPARAM ret = sf::run_message_loop()();\r
 \r
index 837bb9e..71318f7 100644 (file)
@@ -27,6 +27,7 @@ using namespace std;
 \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
@@ -117,14 +118,14 @@ namespace sf
     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
index 851f73e..6b8364a 100644 (file)
@@ -310,6 +310,7 @@ namespace sf{
     bool left_button_,middle_button_,right_button_;\r
   };\r
 \r
+  // ウィンドウプロシージャの識別用クラス\r
   struct wndproc \r
   {\r
     typedef WNDPROC proc_type;\r
@@ -320,6 +321,7 @@ namespace sf{
   }\r
   };\r
 \r
+  // ダイアログプロシージャの識別用クラス\r
   struct dlgproc\r
   {\r
     typedef DLGPROC proc_type;\r
@@ -489,12 +491,28 @@ namespace sf{
     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
@@ -522,6 +540,9 @@ namespace sf{
     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