OSDN Git Service

最初のコミット
authorsfpg <sfpg@users.sourceforge.jp>
Fri, 25 Jan 2013 21:15:56 +0000 (06:15 +0900)
committersfpg <sfpg@users.sourceforge.jp>
Fri, 25 Jan 2013 21:15:56 +0000 (06:15 +0900)
48 files changed:
.gitignore [new file with mode: 0644]
SF.props [new file with mode: 0644]
mfsample.sln [new file with mode: 0644]
mfsample/application.cpp [new file with mode: 0644]
mfsample/application.h [new file with mode: 0644]
mfsample/base_window.cpp [new file with mode: 0644]
mfsample/base_window.h [new file with mode: 0644]
mfsample/code_converter.cpp [new file with mode: 0644]
mfsample/code_converter.h [new file with mode: 0644]
mfsample/directx.ico [new file with mode: 0644]
mfsample/dout.h [new file with mode: 0644]
mfsample/dpi.cpp [new file with mode: 0644]
mfsample/dpi.h [new file with mode: 0644]
mfsample/exception.cpp [new file with mode: 0644]
mfsample/exception.h [new file with mode: 0644]
mfsample/icon.cpp [new file with mode: 0644]
mfsample/icon.h [new file with mode: 0644]
mfsample/info_tab_dialog.cpp [new file with mode: 0644]
mfsample/info_tab_dialog.h [new file with mode: 0644]
mfsample/jumplist.cpp [new file with mode: 0644]
mfsample/jumplist.h [new file with mode: 0644]
mfsample/logger.cpp [new file with mode: 0644]
mfsample/logger.h [new file with mode: 0644]
mfsample/message_loop.h [new file with mode: 0644]
mfsample/mfsample.manifest [new file with mode: 0644]
mfsample/mfsample.vcxproj [new file with mode: 0644]
mfsample/player.cpp [new file with mode: 0644]
mfsample/player.h [new file with mode: 0644]
mfsample/player.rc [new file with mode: 0644]
mfsample/resource.h [new file with mode: 0644]
mfsample/sf_com.cpp [new file with mode: 0644]
mfsample/sf_com.h [new file with mode: 0644]
mfsample/sf_memory.h [new file with mode: 0644]
mfsample/sf_windows.cpp [new file with mode: 0644]
mfsample/sf_windows.h [new file with mode: 0644]
mfsample/singleton.h [new file with mode: 0644]
mfsample/stdafx.cpp [new file with mode: 0644]
mfsample/stdafx.h [new file with mode: 0644]
mfsample/tab_dialog.cpp [new file with mode: 0644]
mfsample/tab_dialog.h [new file with mode: 0644]
mfsample/taskbar.cpp [new file with mode: 0644]
mfsample/taskbar.h [new file with mode: 0644]
mfsample/timer.cpp [new file with mode: 0644]
mfsample/timer.h [new file with mode: 0644]
mfsample/toplevel_window.cpp [new file with mode: 0644]
mfsample/toplevel_window.h [new file with mode: 0644]
mfsample/wasapi2.rc [new file with mode: 0644]
mfsample/winmain.cpp [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..74b789a
--- /dev/null
@@ -0,0 +1,15 @@
+_UpgradeReport_Files/
+*.vcxproj.*
+*.old
+*.xml
+*.sdf
+*.suo
+*.dsp
+*.dsw
+*.vcproj
+unix/
+Debug/
+Release/
+ipch/
+sidplay2/
+backup/
\ No newline at end of file
diff --git a/SF.props b/SF.props
new file mode 100644 (file)
index 0000000..34bcf5b
--- /dev/null
+++ b/SF.props
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ImportGroup Label="PropertySheets" />
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup>
+    <IncludePath>H:\libs\DirectXTK\Inc;H:\libs\boost\include\boost-1_52;H:\libs\xbyak\xbyak;H:\libs\zlib125\zlib-1.2.5;H:\libs\lpng150\lpng150;$(IncludePath)</IncludePath>
+  </PropertyGroup>
+  <PropertyGroup>
+    <LibraryPath>H:\libs\zlib125\zlib-1.2.5;H:\libs\boost\lib;$(LibraryPath)</LibraryPath>
+  </PropertyGroup>
+  <ItemDefinitionGroup>
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>
+      <PrecompiledHeader>Use</PrecompiledHeader>
+      <RuntimeTypeInfo>true</RuntimeTypeInfo>
+      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+      <StructMemberAlignment>16Bytes</StructMemberAlignment>
+      <EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>
+      <PreprocessorDefinitions>_UNICODE;UNICODE;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <CompileAsWinRT>true</CompileAsWinRT>
+      <AdditionalUsingDirectories>C:\Program Files %28x86%29\Microsoft SDKs\Windows\v8.0\ExtensionSDKs\Microsoft.VCLibs\11.0\References\CommonConfiguration\neutral;C:\Program Files %28x86%29\Windows Kits\8.0\References\CommonConfiguration\Neutral;%(AdditionalUsingDirectories)</AdditionalUsingDirectories>
+    </ClCompile>
+  </ItemDefinitionGroup>
+  <ItemGroup />
+</Project>
\ No newline at end of file
diff --git a/mfsample.sln b/mfsample.sln
new file mode 100644 (file)
index 0000000..8b4c8b6
--- /dev/null
@@ -0,0 +1,26 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Express 2012 for Windows Desktop
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mfsample", "mfsample\mfsample.vcxproj", "{4489213E-E01F-4AB3-9193-B00756D27BB1}"
+EndProject
+Global
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|Win32 = Debug|Win32
+               Debug|x64 = Debug|x64
+               Release|Win32 = Release|Win32
+               Release|x64 = Release|x64
+       EndGlobalSection
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {4489213E-E01F-4AB3-9193-B00756D27BB1}.Debug|Win32.ActiveCfg = Debug|Win32
+               {4489213E-E01F-4AB3-9193-B00756D27BB1}.Debug|Win32.Build.0 = Debug|Win32
+               {4489213E-E01F-4AB3-9193-B00756D27BB1}.Debug|x64.ActiveCfg = Debug|x64
+               {4489213E-E01F-4AB3-9193-B00756D27BB1}.Debug|x64.Build.0 = Debug|x64
+               {4489213E-E01F-4AB3-9193-B00756D27BB1}.Release|Win32.ActiveCfg = Release|Win32
+               {4489213E-E01F-4AB3-9193-B00756D27BB1}.Release|Win32.Build.0 = Release|Win32
+               {4489213E-E01F-4AB3-9193-B00756D27BB1}.Release|x64.ActiveCfg = Release|x64
+               {4489213E-E01F-4AB3-9193-B00756D27BB1}.Release|x64.Build.0 = Release|x64
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
+       EndGlobalSection
+EndGlobal
diff --git a/mfsample/application.cpp b/mfsample/application.cpp
new file mode 100644 (file)
index 0000000..6332d5f
--- /dev/null
@@ -0,0 +1,150 @@
+/*\r
+==============================================================================\r
+\r
+This file is part of the async\r
+Copyright 2005-10 by Satoshi Fujiwara.\r
+\r
+async can be redistributed and/or modified under the terms of the\r
+GNU General Public License, as published by the Free Software Foundation;\r
+either version 2 of the License, or (at your option) any later version.\r
+\r
+async is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+GNU General Public License for more details.\r
+\r
+You should have received a copy of the GNU General Public License\r
+along with async; if not, visit www.gnu.org/licenses or write to the\r
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, \r
+Boston, MA 02111-1307 USA\r
+\r
+==============================================================================\r
+*/\r
+#include "StdAfx.h"\r
+#include <commctrl.h>\r
+\r
+\r
+#include "message_loop.h"\r
+#include "sf_com.h"\r
+#include "application.h"\r
+#include "dout.h"\r
+\r
+#if _DEBUG\r
+#define _CRTDBG_MAP_ALLOC\r
+#include <crtdbg.h>\r
+#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)\r
+#endif\r
+\r
+#ifndef HINST_THISCOMPONENT\r
+EXTERN_C IMAGE_DOS_HEADER __ImageBase;\r
+#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase)\r
+#endif\r
+\r
+\r
+using namespace std;\r
+\r
+namespace sf {\r
+#ifdef _DEBUG\r
+  std::wstring application::app_id_(L"SF.async_debug");\r
+#else\r
+  std::wstring application::app_id_(L"SF.async");\r
+#endif\r
+\r
+  application::application()\r
+  {\r
+    instance_handle_ = HINST_THISCOMPONENT;\r
+    // ベースディレクトリの取得\r
+    wchar_t dir[MAX_PATH];\r
+    ::GetCurrentDirectoryW(MAX_PATH,dir);\r
+    base_directory_.assign(dir);\r
+  }\r
+\r
+  application::~application()\r
+  {\r
+  };\r
+\r
+  // アプリケーションを実行する\r
+  int application::execute(HINSTANCE hInstance,\r
+    HINSTANCE hPrevInstance,\r
+    LPTSTR    lpCmdLine,\r
+    int       nCmdShow)\r
+  {\r
+#ifdef _DEBUG\r
+    ::_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF);\r
+#endif\r
+    UNREFERENCED_PARAMETER(hPrevInstance);\r
+    UNREFERENCED_PARAMETER(lpCmdLine);\r
+\r
+    // wcoutで文字化けしないように、ロケールをデフォルト言語に設定する\r
+    std::wcout.imbue(std::locale(""));\r
+\r
+    // 2重起動の防止処理\r
+    SECURITY_DESCRIPTOR sd;\r
+    InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);\r
+    SetSecurityDescriptorDacl(&sd, TRUE, 0, FALSE);        \r
+    SECURITY_ATTRIBUTES sec_attr;\r
+    sec_attr.nLength = sizeof (sec_attr);\r
+    sec_attr.lpSecurityDescriptor = &sd;\r
+    sec_attr.bInheritHandle = TRUE; \r
+#ifdef _DEBUG \r
+    sf::handle_holder handle(::CreateMutex(&sec_attr, FALSE, _T("async_mutex_debug")));\r
+#else\r
+    sf::handle_holder handle(::CreateMutex(&sec_attr, FALSE, _T("async_mutex")));\r
+#endif\r
+    if(NULL == handle.get() || ::GetLastError() == ERROR_ALREADY_EXISTS)\r
+    {\r
+      return 0;\r
+    }\r
+\r
+    // プロセスの優先度を高に設定する\r
+    SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);\r
+\r
+    // コモンコントロールの初期化 \r
+    static const INITCOMMONCONTROLSEX common_ctrls =\r
+    {\r
+      sizeof(INITCOMMONCONTROLSEX),\r
+      ICC_STANDARD_CLASSES | ICC_BAR_CLASSES\r
+    };\r
+    InitCommonControlsEx(&common_ctrls);\r
+\r
+    // Win RTの初期化\r
+    RoInitialize(RO_INIT_MULTITHREADED);\r
+\r
+    // COMをマルチスレッドで初期化\r
+    sf::com_initialize init(0,multi_threaded);\r
+\r
+    // プロセスの優先順位をPro Audioに変更する\r
+    sf::av_mm_thread_characteristics avmm(wstring(L"Pro Audio"));\r
+    avmm.set_priority(AVRT_PRIORITY_HIGH);\r
+\r
+    // アプリケーションIDの登録\r
+    sf::throw_if_err<application::exception>()(SetCurrentProcessExplicitAppUserModelID(app_id_.c_str()));\r
+\r
+    // マルチメディアタイマの精度を1msに設定する\r
+    timeBeginPeriod(1);\r
+\r
+    // ダイアログウィンドウを作成する\r
+    window_ = sf::create_toplevel_window(\r
+      std::wstring(L"Media Player サンプル"),std::wstring(L"Media Player サンプル"));\r
+\r
+    // メッセージ処理ループ\r
+    WPARAM ret = sf::dialog_message_loop(reinterpret_cast<HWND>(window_->raw_handle()))();\r
+\r
+    // マルチメディアタイマの粒度を元に戻す。\r
+    timeEndPeriod(1);\r
+\r
+    // プレイヤーのシャットダウン処理を行いリソースを解放する\r
+    player_->process_event(sf::player::ev::Close());\r
+\r
+    return ret;\r
+  }\r
+\r
+  // Playerを初期化する。\r
+  void application::init_player(HWND vhwnd,HWND hwnd)\r
+  {\r
+    player_ = player::CreatePlayer(vhwnd,hwnd);\r
+    player_init_ok_();\r
+  }\r
+  \r
+}\r
+\r
diff --git a/mfsample/application.h b/mfsample/application.h
new file mode 100644 (file)
index 0000000..e8fb90a
--- /dev/null
@@ -0,0 +1,96 @@
+#pragma once\r
+/*\r
+  ==============================================================================\r
+\r
+   This file is part of the async\r
+   Copyright 2005-10 by Satoshi Fujiwara.\r
+\r
+   async can be redistributed and/or modified under the terms of the\r
+   GNU General Public License, as published by the Free Software Foundation;\r
+   either version 2 of the License, or (at your option) any later version.\r
+\r
+   async is distributed in the hope that it will be useful,\r
+   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+   GNU General Public License for more details.\r
+\r
+   You should have received a copy of the GNU General Public License\r
+   along with async; if not, visit www.gnu.org/licenses or write to the\r
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, \r
+   Boston, MA 02111-1307 USA\r
+\r
+  ==============================================================================\r
+*/\r
+#include "singleton.h"\r
+#include "exception.h"\r
+//#include "ring_buffer.h"\r
+//#include "wasapi.h"\r
+//#include "async_reader.h"\r
+#include "sf_memory.h"\r
+#include "toplevel_window.h"\r
+#include "Player.h"\r
+//#include "reader_agent.h"\r
+//#include "output_agent.h"\r
+//#include "input_agent.h"\r
+//#include "mixer_agent.h"\r
+//#include "sequencer.h"\r
+\r
+namespace sf {\r
+class application : public singleton<application>\r
+{\r
+\r
+  typedef boost::signals2::signal<void ()> player_init_ok_t;\r
+\r
+  static const size_t Q_SIZE = 8;\r
+public:\r
+  struct exception\r
+    : public sf::win32_error_exception \r
+  {\r
+    exception(uint32_t hr) : win32_error_exception(hr) {};\r
+    exception() : win32_error_exception() {} ;\r
+  };\r
+\r
\r
+  application();\r
+  ~application();\r
+  \r
+  int execute(HINSTANCE hInstance,\r
+                     HINSTANCE hPrevInstance,\r
+                     LPTSTR    lpCmdLine,\r
+                     int       nCmdShow);\r
+  \r
+\r
+  std::wstring& app_id(){return app_id_;};\r
+  HINSTANCE instance_handle() {return instance_handle_;};\r
+  \r
+  // アプリケーションのカレントディレクトリを返す\r
+  const std::wstring& base_directory() const { return base_directory_; }\r
+\r
\r
+// ----------------------------------------\r
+// Player\r
+// ----------------------------------------\r
+  player_init_ok_t& player_init_ok(){return player_init_ok_;};\r
+  void init_player(HWND vhwnd,HWND hwnd);\r
+  sf::player::PlayerPtr& Player(){return player_;}\r
+  void release_player(){player_.Reset();}\r
+private:\r
+  player_init_ok_t player_init_ok_;\r
+  player::PlayerPtr player_;\r
+  //void wasapi_setup();\r
+  HINSTANCE instance_handle_;\r
+  int return_code_;\r
+  \r
+// -----------------------------  \r
+// その他\r
+// -----------------------------  \r
+\r
+  std::wstring base_directory_;\r
+  sf::toplevel_window_ptr window_;\r
+\r
+  static std::wstring app_id_;\r
+  static const int WAIT_TIMEOUT_DEFAULT = 100; \r
+\r
+};\r
+}\r
+\r
diff --git a/mfsample/base_window.cpp b/mfsample/base_window.cpp
new file mode 100644 (file)
index 0000000..ca9ceaa
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+  ==============================================================================
+
+   This file is part of the async
+   Copyright 2005-10 by Satoshi Fujiwara.
+
+   async can be redistributed and/or modified under the terms of the
+   GNU General Public License, as published by the Free Software Foundation;
+   either version 2 of the License, or (at your option) any later version.
+
+   async is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with async; if not, visit www.gnu.org/licenses or write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
+   Boston, MA 02111-1307 USA
+
+  ==============================================================================
+*/
+#include "StdAfx.h"
+#include "base_window.h"
+
+namespace sf {
+}
\ No newline at end of file
diff --git a/mfsample/base_window.h b/mfsample/base_window.h
new file mode 100644 (file)
index 0000000..12655e1
--- /dev/null
@@ -0,0 +1,67 @@
+#pragma once\r
+/*\r
+  ==============================================================================\r
+\r
+   This file is part of the async\r
+   Copyright 2005-10 by Satoshi Fujiwara.\r
+\r
+   async can be redistributed and/or modified under the terms of the\r
+   GNU General Public License, as published by the Free Software Foundation;\r
+   either version 2 of the License, or (at your option) any later version.\r
+\r
+   async is distributed in the hope that it will be useful,\r
+   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+   GNU General Public License for more details.\r
+\r
+   You should have received a copy of the GNU General Public License\r
+   along with async; if not, visit www.gnu.org/licenses or write to the\r
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, \r
+   Boston, MA 02111-1307 USA\r
+\r
+  ==============================================================================\r
+*/\r
+namespace sf {\r
+/** window \83x\81[\83X\83N\83\89\83X */\r
+\r
+struct rect {\r
+  uint32_t width;\r
+  uint32_t height;\r
+};\r
+\r
+struct base_window : boost::noncopyable\r
+{\r
+  typedef boost::signals2::signal<void ()> on_render_type;\r
+\r
+  on_render_type on_render;\r
+  \r
+  // \90\82ÌWindow\83n\83\93\83h\83\8b\82ð\95Ô\82·\81B\r
+  virtual void * raw_handle() const = 0;\r
+  // \83E\83B\83\93\83h\83E\82ð\90\90¬\82·\82é\r
+  virtual void create() = 0;\r
+//  virtual void show(uint32_t show_flag) = 0;\r
+  // \83E\83B\83\93\83h\83E\82ð\95\\8e¦\82·\82é\r
+  virtual void show() = 0;\r
+  // \83E\83B\83\93\83h\83E\82ª\8d¡\95\\8e¦\82³\82ê\82Ä\82¢\82é\82©\82ð\95Ô\82·\r
+  virtual bool is_show() = 0;\r
+  // \83E\83B\83\93\83h\83E\82ð\89B\82·\r
+  virtual void hide() = 0;\r
+  //virtual void activate() = 0;\r
+  //virtual bool is_activate() = 0;\r
+  //virtual void deactivate() = 0;\r
+  //virtual void \r
+  //virtual void size(uint32_t width,uint32_t height); \r
+  //virtual rect size(); \r
+\r
+  virtual void text(std::wstring& text) = 0;\r
+  //virtual std::wstring text() = 0;\r
+\r
+  virtual void update() = 0;\r
+\r
+protected:\r
+  virtual ~base_window() {};\r
+\r
+};\r
+\r
+}\r
+\r
diff --git a/mfsample/code_converter.cpp b/mfsample/code_converter.cpp
new file mode 100644 (file)
index 0000000..5de5e82
--- /dev/null
@@ -0,0 +1,34 @@
+#include "stdafx.h"
+
+namespace sf 
+{
+
+  code_converter<char,wchar_t>::code_converter(const char*p)
+  {
+    int len = ::MultiByteToWideChar(CP_ACP,0,p,-1,NULL,0);
+    m_dest.reset(new wchar_t[len]);
+    ::MultiByteToWideChar(CP_ACP,0,p,-1,&m_dest[0],len);
+  };
+
+  code_converter<char,wchar_t>::code_converter(const std::string& p)
+  {
+    int len = ::MultiByteToWideChar(CP_ACP,0,p.c_str(),-1,NULL,0);
+    m_dest.reset(new wchar_t[len]);
+    ::MultiByteToWideChar(CP_ACP,0,p.c_str(),-1,&m_dest[0],len);
+  };
+
+  code_converter<wchar_t,char>::code_converter(const wchar_t*p)
+  {
+    int len = ::WideCharToMultiByte(CP_ACP,0,p,-1,NULL,0,NULL,NULL);
+    m_dest.reset(new char[len]);
+    ::WideCharToMultiByte(CP_ACP,0,p,-1,&m_dest[0],len,NULL,NULL);
+  };
+
+  code_converter<wchar_t,char>::code_converter(const std::wstring & p)
+  {
+    int len = ::WideCharToMultiByte(CP_ACP,0,p.c_str(),-1,NULL,0,NULL,NULL);
+    m_dest.reset(new char[len]);
+    ::WideCharToMultiByte(CP_ACP,0,p.c_str(),-1,&m_dest[0],len,NULL,NULL);
+  };
+
+};
\ No newline at end of file
diff --git a/mfsample/code_converter.h b/mfsample/code_converter.h
new file mode 100644 (file)
index 0000000..9ee1cc2
--- /dev/null
@@ -0,0 +1,79 @@
+#pragma once\r
+\r
+\r
+/** @file\r
+ *  @author S.F. (Satoshi Fujiwara)\r
+ *  @brief wchar_t <--> char の変換ユーティリティ\r
+ *  引数として文字列を引き渡す際、変換が必要な場合、下記のようにアダプタ的に使用することを想定している。\r
+ *  std::wstring a(L"abcd");\r
+ *  std::wstring b((sf::code_converter<wcha_t,char>(a)));\r
+ *\r
+ * 後、ATLコード差し替え用のtypedefも用意している。\r
+ *  これは、アダプタとしての利用のみに限定される。\r
+ *  sf::ct2a hoge_(L"abcef"); // 想定していない(動作する場合もあるし、ダメな場合もある)\r
+ */\r
+\r
+namespace sf \r
+{\r
+    /** 雛形 */\r
+    template <typename SrcChar,typename DestChar>\r
+    struct code_converter\r
+    {\r
+    public:\r
+        explicit code_converter(SrcChar* p);\r
+        explicit code_converter(std::basic_string<SrcChar> & p);\r
+        operator DestChar*();\r
+    };\r
+\r
+    /** char -> wchar_tへの変換 */\r
+    template <>\r
+    struct code_converter<char,wchar_t>\r
+    {\r
+        explicit code_converter(const char* p);\r
+        explicit code_converter(const std::string& p);\r
+\r
+        operator wchar_t*() const {return m_dest.get();}\r
+    private:\r
+        boost::scoped_array<wchar_t> m_dest;\r
+    };\r
+\r
+    /** wchar_t -> char */\r
+    template <>\r
+    struct code_converter<wchar_t,char>\r
+    {\r
+        explicit code_converter(const wchar_t* p);\r
+        explicit code_converter(const std::wstring& p);\r
+        operator char* () const {return m_dest.get();}\r
+    private:\r
+        boost::scoped_array<char> m_dest;\r
+    };\r
+\r
+    /** ATLコード差し替えのためのエイリアス */\r
+    typedef sf::code_converter<char,wchar_t> ca2w;\r
+\r
+    /** ATLコード差し替えのためのエイリアス */\r
+    typedef sf::code_converter<wchar_t,char> cw2a;\r
+\r
+    #ifdef _UNICODE\r
+\r
+        /** ATLコード差し替えのためのエイリアス */\r
+        typedef sf::code_converter<char,wchar_t> ca2t;\r
+        /** ATLコード差し替えのためのエイリアス */\r
+        typedef sf::code_converter<wchar_t,char> ct2a;\r
+\r
+        /** ATLコード差し替えのためのエイリアス */\r
+        inline const wchar_t* ct2w(const wchar_t* p) { return p;};\r
+        /** ATLコード差し替えのためのエイリアス */\r
+        inline const wchar_t* cw2t(const wchar_t* p) { return p;};\r
+\r
+    #else\r
+\r
+        /** ATLコード差し替えのためのエイリアス */\r
+        inline const char* ct2a(const char* p) { return p;};\r
+        /** ATLコード差し替えのためのエイリアス */\r
+        inline const char* ca2t(const char* p) { return p;};\r
+\r
+    #endif\r
+}\r
+\r
+\r
diff --git a/mfsample/directx.ico b/mfsample/directx.ico
new file mode 100644 (file)
index 0000000..bc43c1b
Binary files /dev/null and b/mfsample/directx.ico differ
diff --git a/mfsample/dout.h b/mfsample/dout.h
new file mode 100644 (file)
index 0000000..360a1a5
--- /dev/null
@@ -0,0 +1,148 @@
+#pragma once\r
+\r
+/* http://vision.kuee.kyoto-u.ac.jp/~nob/doc/win32/win32.html#doc1_42 \r
+       \82æ\82è\94q\8eØ\r
+*/\r
+\r
+\r
+#ifndef STDX_DSTREAM_H\r
+\r
+#define STDX_DSTREAM_H\r
+\r
+namespace sf\r
+{\r
+\r
+#ifdef _DEBUG\r
+  \r
+// VC++ \82Å STLport \82¾\82Æ using std::char_traits; \82Ý\82½\82¢\82È\82Ì\82ª\95K\97v\82©\82à\r
+template <typename Ch_T, typename Tr_T = std::char_traits<Ch_T> >\r
+class basic_dbg_streambuf: public std::basic_stringbuf<Ch_T, Tr_T>\r
+{\r
+public:\r
+  basic_dbg_streambuf()\r
+    {\r
+#ifndef STDX_DSTREAM_BUFFERING\r
+      setbuf(0,0);\r
+#endif\r
+    }\r
+\r
+  virtual ~basic_dbg_streambuf()\r
+    {\r
+      sync();\r
+    }\r
+\r
+protected:\r
+  int sync(void)\r
+    {\r
+      dbg_out(str().c_str());\r
+      pbump(static_cast<int>(pbase() - pptr()));\r
+      return 0;\r
+    }\r
+\r
+  void dbg_out(const Ch_T*);\r
+};\r
+\r
+template <>\r
+inline void basic_dbg_streambuf<char>::dbg_out(const char *str)\r
+{\r
+  ::OutputDebugStringA(str);\r
+}\r
+\r
+template <>\r
+inline void basic_dbg_streambuf<wchar_t>::dbg_out(const wchar_t *str)\r
+{\r
+  ::OutputDebugStringW(str);\r
+}\r
+\r
+template <typename Ch_T, typename Tr_T = std::char_traits<Ch_T> >\r
+class basic_dbg_ostream: public std::basic_ostream<Ch_T, Tr_T>\r
+{\r
+public:\r
+  basic_dbg_ostream() : std::basic_ostream<Ch_T, Tr_T>(new basic_dbg_streambuf<Ch_T, Tr_T>())\r
+    {\r
+    }\r
+\r
+  virtual ~basic_dbg_ostream()\r
+    {\r
+      // flush(); // \95s\97v\82ç\82µ\82¢\81Dhttp://www.tietew.jp/cppll/archive/607\r
+      delete rdbuf();\r
+    }\r
+};\r
+\r
+typedef basic_dbg_streambuf<wchar_t>  wdbg_streambuf;\r
+typedef basic_dbg_ostream<wchar_t> wdstream;\r
+\r
+// \82±\82ê\82ð\92è\8b`\82µ\82Ä\82¨\82­\82Æ\81C dout \82Ì\90é\8c¾\82ª\82¢\82ç\82È\82­\82È\82é\81D\r
+\r
+static wdstream wdout;\r
+#define DOUT(x) wdout << x \r
+}\r
+#else\r
+#define DOUT(x) \r
+#define wdout //\r
+//  struct dummy_wdout {\r
+//    //template <typename R>\r
+//    //inline dummy_wdout& operator<<(const R v) {return *this;};\r
+//\r
+//    //template <typename R>\r
+//    //inline dummy_wdout& operator<<(const R* v) {return *this;};\r
+//\r
+//    //template <typename R>\r
+//    //inline dummy_wdout& operator<<(const R& v) {return *this;};\r
+//\r
+//    //template <typename R>\r
+//    //inline dummy_wdout& operator<<(const R&& v) {return *this;};\r
+//\r
+//    ////template <typename R,int N>\r
+//    ////inline dummy_wdout& operator<<(const R(&a)[N]) {return *this;};\r
+//\r
+//  };\r
+//\r
+//  static dummy_wdout wdout;\r
+//}\r
+//\r
+//template <typename L>\r
+//inline sf::dummy_wdout& operator<<(sf::dummy_wdout& p,const L v) {return p;};\r
+//\r
+//template <typename L>\r
+//inline sf::dummy_wdout& operator<<(sf::dummy_wdout& p,const L& v) {return p;};\r
+//\r
+//template <typename L>\r
+//inline sf::dummy_wdout& operator<<(sf::dummy_wdout& p,const L&& v) {return p;};\r
+//\r
+////template <typename L>\r
+////inline sf::dummy_wdout& operator<<(sf::dummy_wdout& p,const L* v) {return p;};\r
+//\r
+//template <typename L,int N>\r
+//inline sf::dummy_wdout& operator<<(sf::dummy_wdout& p,const L(&a)[N]) {return p;};\r
+//\r
+//template <typename L>\r
+//inline L& operator<<(const L v,sf::dummy_wdout& p) {return v;};\r
+//\r
+//template <typename L>\r
+//inline L& operator<<(sf::dummy_wdout& p,L v) {return v;};\r
+//\r
+//\r
+//template <typename L>\r
+//inline sf::dummy_wdout& operator<<(const L v,sf::dummy_wdout& p) {return p;};\r
+//\r
+//template <typename L>\r
+//inline sf::dummy_wdout& operator<<(const L& v,sf::dummy_wdout& p) {return p;};\r
+//\r
+////template <typename L>\r
+////inline sf::dummy_wdout& operator<<(const L* v,sf::dummy_wdout& p) {return p;};\r
+//\r
+//template <typename L>\r
+//inline sf::dummy_wdout& operator<<(const L&& v,sf::dummy_wdout& p) {return p;};\r
+//\r
+//\r
+//template <typename L,int N>\r
+//inline sf::dummy_wdout& operator<<(const L(&a)[N],sf::dummy_wdout& p) {return p;};\r
+////\r
+//template <typename L>\r
+//inline sf::dummy_wdout& operator<<(sf::dummy_wdout& p , const L *v) {return p;};\r
+\r
+//\r
+}\r
+#endif\r
+#endif // STDX_DSTREAM_
\ No newline at end of file
diff --git a/mfsample/dpi.cpp b/mfsample/dpi.cpp
new file mode 100644 (file)
index 0000000..7a3f56c
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+  ==============================================================================
+
+   This file is part of the async
+   Copyright 2005-10 by Satoshi Fujiwara.
+
+   async can be redistributed and/or modified under the terms of the
+   GNU General Public License, as published by the Free Software Foundation;
+   either version 2 of the License, or (at your option) any later version.
+
+   async is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with async; if not, visit www.gnu.org/licenses or write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
+   Boston, MA 02111-1307 USA
+
+  ==============================================================================
+*/
+
+#include "StdAfx.h"
+#if _DEBUG
+#define _CRTDBG_MAP_ALLOC
+#include <crtdbg.h>
+#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
+#endif
+#include "sf_windows.h"
+#include "dpi.h"
+
+namespace sf {
+  void dpi::init()
+  {
+    if (!init_)
+    {
+      sf::get_dc hdc(0);
+      if (hdc.get())
+      {
+        dpi_x_ = GetDeviceCaps(hdc.get(), LOGPIXELSX);
+        dpi_y_ = GetDeviceCaps(hdc.get(), LOGPIXELSY);
+        ReleaseDC(NULL, hdc.get());
+      }
+      init_ = true;
+    }
+  }
+
+}
\ No newline at end of file
diff --git a/mfsample/dpi.h b/mfsample/dpi.h
new file mode 100644 (file)
index 0000000..b37a814
--- /dev/null
@@ -0,0 +1,86 @@
+#pragma once\r
+/*\r
+  ==============================================================================\r
+\r
+   This file is part of the async\r
+   Copyright 2005-10 by Satoshi Fujiwara.\r
+\r
+   async can be redistributed and/or modified under the terms of the\r
+   GNU General Public License, as published by the Free Software Foundation;\r
+   either version 2 of the License, or (at your option) any later version.\r
+\r
+   async is distributed in the hope that it will be useful,\r
+   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+   GNU General Public License for more details.\r
+\r
+   You should have received a copy of the GNU General Public License\r
+   along with async; if not, visit www.gnu.org/licenses or write to the\r
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, \r
+   Boston, MA 02111-1307 USA\r
+\r
+  ==============================================================================\r
+*/\r
+\r
+namespace sf{\r
+  template <typename T>\r
+  class dpi_t\r
+  {\r
+  public:\r
+    dpi_t() : init_(false), dpi_x_(96), dpi_y_(96) { }\r
+    // \89æ\96Ê\82Ì DPI \82ð\8eæ\93¾\82µ\82Ü\82·\81B\r
+    T dpix() { init(); return dpi_x_; }\r
+    T dpiy() { init(); return dpi_y_; }\r
+\r
+    // \90â\91Î\83s\83N\83Z\83\8b\82Æ\91\8a\91Î\83s\83N\83Z\83\8b\8aÔ\82Ì\95Ï\8a·\82ð\8ds\82¢\82Ü\82·\81B\r
+    T scale_x(T x) { init(); return MulDiv(x, dpi_x_, 96); }\r
+    T scale_y(T y) { init(); return MulDiv(y, dpi_y_, 96); }\r
+    T unscale_x(T x) { init(); return MulDiv(x, 96, dpi_x_); }\r
+    T unscale_y(T y) { init(); return MulDiv(y, 96, dpi_y_); }\r
+\r
+    // \89æ\96Ê\83T\83C\83Y (\91\8a\91Î\83s\83N\83Z\83\8b\92P\88Ê) \82ð\8b\81\82ß\82Ü\82·\81B\r
+    T scaled_screen_width() { return scaled_system_metrix_x(SM_CXSCREEN); }\r
+    T scaled_screen_height() { return scaled_system_metrix_y(SM_CYSCREEN); }\r
+\r
+    // \8el\8ap\8c`\82Ì\83T\83C\83Y\82ð\90â\91Î\83s\83N\83Z\83\8b\82©\82ç\91\8a\91Î\83s\83N\83Z\83\8b\82É\95Ï\8dX\82µ\82Ü\82·\81B\r
+    void scale_rect(RECT *rect_ptr)\r
+    {\r
+      rect_ptr->left = scale_x(rect_ptr->left);\r
+      rect_ptr->right = scale_x(rect_ptr->right);\r
+      rect_ptr->top = scale_y(rect_ptr->top);\r
+      rect_ptr->bottom = scale_y(rect_ptr->bottom);\r
+    }\r
+\r
+    // \89æ\96Ê\89ð\91\9c\93x\82ª\8dÅ\92á\92l (\91\8a\91Î\83s\83N\83Z\83\8b\92P\88Ê) \82ð\96\9e\82½\82µ\82Ä\82¢\82é\82©\82Ç\82¤\82©\82ð\r
+    // \8am\94F\82µ\82Ü\82·\81B\r
+    bool is_resolution_at_least(T xmin, T ymin) \r
+    { \r
+      return (scaled_screen_width() >= xmin) && (scaled_screen_height() >= ymin); \r
+    }\r
+    // \83|\83C\83\93\83\83T\83C\83Y (1/72 \83C\83\93\83`) \82ð\90â\91Î\83s\83N\83Z\83\8b\82É\95Ï\8a·\82µ\82Ü\82·\81B\r
+    T point_to_pixels(int pt) { return MulDiv(pt, dpi_y_, 72); }\r
+    // \83L\83\83\83b\83V\83\85\82³\82ê\82½\83\81\83g\83\8a\83b\83N\82ð\82·\82×\82Ä\96³\8cø\82É\82µ\82Ü\82·\81B\r
+    void invalidate() { init_ = false; }\r
+  private:\r
+    void init();\r
+\r
+    T scaled_system_metrix_x(int nIndex) \r
+    { \r
+      init(); \r
+      return MulDiv(GetSystemMetrics(nIndex), 96, dpi_x_); \r
+    }\r
+\r
+    T scaled_system_metrix_y(int nIndex) \r
+    { \r
+      init(); \r
+      return MulDiv(GetSystemMetrics(nIndex), 96, dpi_y_); \r
+    }\r
+\r
+  private:\r
+    bool init_;\r
+    T dpi_x_;\r
+    T dpi_y_;\r
+  };\r
+\r
+  typedef dpi_t<int> dpi;\r
+}\r
diff --git a/mfsample/exception.cpp b/mfsample/exception.cpp
new file mode 100644 (file)
index 0000000..5425c47
--- /dev/null
@@ -0,0 +1,124 @@
+#include "stdafx.h"
+#include "exception.h"
+#include <objbase.h>
+#include <wtypes.h>
+#include <winerror.h>
+#include <avrt.h>
+#include <strsafe.h>
+#include <audioclient.h>
+#include <audiopolicy.h>
+
+
+
+#define BOOST_ASSIGN_MAX_PARAMS 7
+#include <boost/assign.hpp>
+#include <boost/assign/ptr_list_of.hpp>
+#include <boost/assign/ptr_list_inserter.hpp>
+#include <boost/foreach.hpp>
+
+#if _DEBUG
+#define _CRTDBG_MAP_ALLOC
+#include <crtdbg.h>
+#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
+#endif
+
+#include "sf_memory.h"
+
+using namespace boost;
+
+namespace sf
+{
+//typedef CComPtr<IAudioClient> IAudioClientPtr;
+std::map<HRESULT,std::wstring> com_error_  = boost::assign::list_of<std::pair<HRESULT,std::wstring> >
+    (E_POINTER,L"E_POINTER")
+    (E_INVALIDARG,L"E_INVALIDARG")
+    (DWRITE_E_FILEFORMAT,L"DWRITE_E_FILEFORMAT")
+    (DWRITE_E_UNEXPECTED,L"DWRITE_E_UNEXPECTED")
+    (DWRITE_E_NOFONT,L"DWRITE_E_NOFONT")
+    (DWRITE_E_FILENOTFOUND,L"DWRITE_E_FILENOTFOUND")
+    (DWRITE_E_FILEACCESS,L"DWRITE_E_FILEACCESS")
+    (DWRITE_E_FONTCOLLECTIONOBSOLETE,L"DWRITE_E_FONTCOLLECTIONOBSOLETE")
+    (DWRITE_E_ALREADYREGISTERED,L"DWRITE_E_ALREADYREGISTERED")
+       (AUDCLNT_E_NOT_INITIALIZED,L"AUDCLNT_E_NOT_INITIALIZED")
+       (AUDCLNT_E_ALREADY_INITIALIZED,L"AUDCLNT_E_ALREADY_INITIALIZED")
+    (AUDCLNT_E_WRONG_ENDPOINT_TYPE,L"AUDCLNT_E_WRONG_ENDPOINT_TYPE")
+       (AUDCLNT_E_DEVICE_INVALIDATED,L"AUDCLNT_E_DEVICE_INVALIDATED")
+       (AUDCLNT_E_NOT_STOPPED,L"AUDCLNT_E_NOT_STOPPED")
+       (AUDCLNT_E_BUFFER_TOO_LARGE,L"AUDCLNT_E_BUFFER_TOO_LARGE")
+       (AUDCLNT_E_OUT_OF_ORDER,L"AUDCLNT_E_OUT_OF_ORDER")
+       (AUDCLNT_E_UNSUPPORTED_FORMAT,L"AUDCLNT_E_UNSUPPORTED_FORMAT")
+       (AUDCLNT_E_INVALID_SIZE,L"AUDCLNT_E_INVALID_SIZE")
+       (AUDCLNT_E_DEVICE_IN_USE,L"AUDCLNT_E_DEVICE_IN_USE")
+       (AUDCLNT_E_BUFFER_OPERATION_PENDING,L"AUDCLNT_E_BUFFER_OPERATION_PENDING")
+       (AUDCLNT_E_THREAD_NOT_REGISTERED,L"AUDCLNT_E_THREAD_NOT_REGISTERED")
+       (AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED,L"AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED")
+       (AUDCLNT_E_ENDPOINT_CREATE_FAILED,L"AUDCLNT_E_ENDPOINT_CREATE_FAILED")
+       (AUDCLNT_E_SERVICE_NOT_RUNNING,L"AUDCLNT_E_SERVICE_NOT_RUNNING")
+       (AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED,L"AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED")
+       (AUDCLNT_E_EXCLUSIVE_MODE_ONLY,L"AUDCLNT_E_EXCLUSIVE_MODE_ONLY")
+       (AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL,L"AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL")
+       (AUDCLNT_E_EVENTHANDLE_NOT_SET,L"AUDCLNT_E_EVENTHANDLE_NOT_SET")
+       (AUDCLNT_E_INCORRECT_BUFFER_SIZE,L"AUDCLNT_E_INCORRECT_BUFFER_SIZE")
+  (AUDCLNT_E_CPUUSAGE_EXCEEDED,L"AUDCLNT_E_CPUUSAGE_EXCEEDED")
+  (AUDCLNT_E_BUFFER_ERROR,L"AUDCLNT_E_BUFFER_ERROR")
+  (AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED,L"AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED")
+  (AUDCLNT_E_BUFFER_SIZE_ERROR,L"AUDCLNT_E_BUFFER_SIZE_ERROR")
+  (AUDCLNT_E_INVALID_DEVICE_PERIOD,L"AUDCLNT_E_INVALID_DEVICE_PERIOD")
+       (AUDCLNT_S_BUFFER_EMPTY,L"AUDCLNT_S_BUFFER_EMPTY")
+       (AUDCLNT_S_THREAD_ALREADY_REGISTERED,L"AUDCLNT_S_THREAD_ALREADY_REGISTERED")
+  (AUDCLNT_S_POSITION_STALLED,L"AUDCLNT_S_POSITION_STALLED")
+  (DXGI_ERROR_UNSUPPORTED,L"DXGI_ERROR_UNSUPPORTED ")
+  (DXGI_STATUS_OCCLUDED,L"DXGI_STATUS_OCCLUDED")
+  (DXGI_STATUS_CLIPPED,L"DXGI_STATUS_CLIPPED")
+  ;
+       
+
+win32_error_exception::win32_error_exception(uint32_t hr)
+: std::exception("HRESULT ERROR"),hresult_(hr)
+{
+       local_memory<wchar_t> mem;
+       DWORD 結果 = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,0,hr,0,(LPWSTR)&mem,0,0);
+       if(結果 != 0){
+               error_ = mem.get();
+       } else {
+               std::map<HRESULT,std::wstring>::iterator it = com_error_.find(hr);
+               if(it != com_error_.end())
+               {
+                       error_ = it->second;
+               } else {
+                       error_ = (boost::wformat(L"0x%x 不明なCOMエラー") % hr).str();
+               }
+#ifdef _DEBUG
+  wdout << L"#### Exception Occured ####" << error_ << std::endl; 
+#endif
+       }
+
+};
+
+win32_error_exception::win32_error_exception()
+{
+       hresult_ = ::GetLastError();
+       local_memory<wchar_t> mem;
+       DWORD rv =  FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,0,hresult_,0,(LPWSTR)&mem,0,0);
+       error_ = mem.get();
+#ifdef _DEBUG
+  wdout << L"#### Exception Occured ####" << error_ << std::endl; 
+#endif
+
+  //Logger::outputDebugPrintf(L"Win32 Error %x %s",hresult_,mem.Get() );
+};
+
+std::wstring win32_error_exception::get_last_error_str(uint32_t err)
+{
+//     DWORD err = ::GetLastError();
+  std::wstring err_str;
+       local_memory<wchar_t> mem;
+       DWORD rv =  FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,0,err,0,(LPWSTR)&mem,0,0);
+       err_str = mem.get();
+#ifdef _DEBUG
+  wdout << L"#### Exception Occured ####" << err_str << std::endl; 
+#endif
+  return err_str;
+}
+
+}
\ No newline at end of file
diff --git a/mfsample/exception.h b/mfsample/exception.h
new file mode 100644 (file)
index 0000000..e6c124d
--- /dev/null
@@ -0,0 +1,45 @@
+#pragma once
+
+namespace sf
+{
+///Exception
+       class exception : public std::exception
+       {
+       public:
+               explicit exception(const std::wstring& reason)
+               {
+                       m_reason = reason;
+               };
+               const wchar_t * what() {return m_reason.c_str();};
+               const std::wstring& what_str() { return m_reason;};
+       protected:
+               std::wstring m_reason;
+       };
+
+       class win32_error_exception : std::exception 
+       {
+       public:
+               win32_error_exception(uint32_t hr);
+               win32_error_exception();
+
+               virtual ~win32_error_exception() {};
+               uint32_t hresult() {return hresult_;}
+               std::wstring& error() {return error_;}
+    static std::wstring get_last_error_str(uint32_t err = ::GetLastError());
+  private:
+               uint32_t hresult_;
+               std::wstring error_;
+       };
+
+  template <class Exc = win32_error_exception> struct throw_if_err
+  {
+    inline void operator()(HRESULT hr) {
+      if(hr != S_OK)
+      {throw Exc(hr);}
+    }
+    inline void operator()(bool v) {if(!v){throw Exc();}}
+  };
+
+}
+
+#define THROW_IF_ERR(x) sf::throw_if_err<>()(x)
diff --git a/mfsample/icon.cpp b/mfsample/icon.cpp
new file mode 100644 (file)
index 0000000..89542d0
--- /dev/null
@@ -0,0 +1,264 @@
+/*\r
+  ==============================================================================\r
+\r
+   This file is part of the async\r
+   Copyright 2005-11 by Satoshi Fujiwara.\r
+\r
+   async can be redistributed and/or modified under the terms of the\r
+   GNU General Public License, as published by the Free Software Foundation;\r
+   either version 2 of the License, or (at your option) any later version.\r
+\r
+   async is distributed in the hope that it will be useful,\r
+   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+   GNU General Public License for more details.\r
+\r
+   You should have received a copy of the GNU General Public License\r
+   along with async; if not, visit www.gnu.org/licenses or write to the\r
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, \r
+   Boston, MA 02111-1307 USA\r
+\r
+  ==============================================================================\r
+*/\r
+\r
+#include "StdAfx.h"\r
+\r
+#if _DEBUG\r
+#define _CRTDBG_MAP_ALLOC\r
+#include <crtdbg.h>\r
+#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)\r
+#endif\r
+\r
+#include "sf_windows.h"\r
+#include "icon.h"\r
+#include "application.h"\r
+\r
+namespace sf {\r
+  bitmap_holder icon::default_mono_bitmap(CreateBitmap(32,32,1,1,NULL));\r
+\r
+  icon::icon(uint32_t id) \r
+    : icon_((HICON)::LoadImageW(application::instance()->instance_handle(),MAKEINTRESOURCE(id),IMAGE_ICON,0,0,LR_DEFAULTCOLOR))\r
+  {\r
+\r
+  };\r
+\r
+  icon::icon(icon_holder& ic)\r
+  {\r
+    icon_.reset(::CopyIcon(ic.get()));\r
+    analyze();\r
+  }\r
+\r
+  icon::icon(icon_holder&& ic)\r
+  {\r
+    std::swap(ic,icon_);\r
+    analyze();\r
+  }\r
+\r
+  icon::icon(bitmap_holder& bmp_color,int width,int height) \r
+    : width_(width),height_(height)\r
+  {\r
+    BITMAP bmp;\r
+    ICONINFO ii;\r
+    ::GetObjectW(bmp_color.get(),sizeof(BITMAP),&bmp);\r
+    bits_per_pixel_ = bmp.bmBitsPixel;\r
+\r
+    ii.fIcon = TRUE;\r
+    ii.xHotspot = 0;\r
+    ii.yHotspot = 0;\r
+    ii.hbmColor = bmp_color.get();\r
+\r
+    if(width == 32 && height == 32){\r
+      ii.hbmMask = default_mono_bitmap.get();\r
+      icon_.reset(::CreateIconIndirect(&ii));\r
+    } else {\r
+      bitmap_holder hmb(::CreateBitmap(width,height,1,1,NULL));\r
+      ii.hbmMask = hmb.get();\r
+      icon_.reset(::CreateIconIndirect(&ii));\r
+    }\r
+\r
+  }\r
+\r
+  icon::icon(ID2D1BitmapPtr& ptr)\r
+  {\r
+    ID2D1FactoryPtr factory;\r
+    ptr->GetFactory(&factory);\r
+\r
+    D2D1_SIZE_U size(ptr->GetPixelSize());\r
+    // ビットマップヘッダのセットアップ\r
+    BITMAPV5HEADER bi = {0};\r
+    bi.bV5Size           = sizeof(BITMAPV5HEADER);\r
+    bi.bV5Width           = size.width;\r
+    bi.bV5Height          = size.height;\r
+    bi.bV5Planes = 1;\r
+    bi.bV5BitCount = 32;\r
+    bi.bV5Compression = BI_BITFIELDS;\r
+    bi.bV5RedMask   =  0x00FF0000;\r
+    bi.bV5GreenMask =  0x0000FF00;\r
+    bi.bV5BlueMask  =  0x000000FF;\r
+    bi.bV5AlphaMask =  0xFF000000; \r
+\r
+    // デスクトップHDCの取得\r
+    get_dc dc(NULL);\r
+    \r
+    // DIBセクションの作成\r
+    void *bits;// 得られるビットマップ\r
+    bitmap_holder bmp(\r
+      ::CreateDIBSection(\r
+        dc.get(),reinterpret_cast<BITMAPINFO *>(&bi),DIB_RGB_COLORS,&bits,NULL,0));\r
+    { \r
+      // 互換DCの作成\r
+      compatible_dc cdc(dc.get());\r
+      {\r
+        // 描画先への切り替え\r
+        select_object s(cdc.get(),bmp.get());\r
+\r
+        // DC互換レンダーターゲットのセットアップ\r
+        D2D1_RENDER_TARGET_PROPERTIES \r
+          props = D2D1::RenderTargetProperties(\r
+          D2D1_RENDER_TARGET_TYPE_DEFAULT,\r
+          D2D1::PixelFormat(\r
+              DXGI_FORMAT_B8G8R8A8_UNORM,\r
+              D2D1_ALPHA_MODE_PREMULTIPLIED),\r
+          0,\r
+          0,\r
+          D2D1_RENDER_TARGET_USAGE_NONE,\r
+          D2D1_FEATURE_LEVEL_DEFAULT\r
+        );\r
+\r
+        ID2D1DCRenderTargetPtr dcr;\r
+        throw_if_err<>()(factory->CreateDCRenderTarget(&props,dcr.GetAddressOf()));\r
+        RECT rect = {0,0,size.width,size.height};\r
+        // 互換DCへのバインド\r
+        throw_if_err<>()(dcr->BindDC(cdc.get(),&rect));\r
+        dcr->DrawBitmap(ptr.Get());\r
+      }\r
+    }\r
+    icon(bmp,size.width,size.height);\r
+  };\r
+\r
+\r
+  icon::icon(boost::filesystem::wpath& path)\r
+  {\r
+    icon_.reset(\r
+      reinterpret_cast<HICON>(\r
+        LoadImageW(NULL,path.native().c_str(),IMAGE_ICON,0,0,LR_DEFAULTSIZE | LR_LOADFROMFILE)));\r
+  }\r
+\r
+  icon::~icon()\r
+  {\r
+\r
+  }\r
+\r
+  void icon::analyze()\r
+  {\r
+    ::ICONINFOEXW info;\r
+    ::GetIconInfoExW(icon_.get(),&info);\r
+    BITMAP bmp;\r
+    ::GetObjectW(info.hbmColor,sizeof(BITMAP),&bmp);\r
+    width_ = bmp.bmWidth;\r
+    height_ = bmp.bmHeight;\r
+    bits_per_pixel_ = bmp.bmBitsPixel;\r
+  }\r
+\r
+  icon& icon::operator= (icon& i)\r
+  {\r
+    BOOST_ASSERT(icon_ != i.icon_);\r
+    if(icon_ == i.icon_) return *this;\r
+    icon_.reset(::CopyIcon(i.icon_.get()));\r
+    width_ = i.width_;\r
+    height_ = i.height_;\r
+    bits_per_pixel_ = i.bits_per_pixel_;\r
+    return *this;\r
+  }\r
+\r
+  //icon_ptr icon::create_icon()\r
+  //{\r
\r
+  //  // ビットマップヘッダのセットアップ\r
+  //  BITMAPV5HEADER bi = {0};\r
+  //  bi.bV5Size           = sizeof(BITMAPV5HEADER);\r
+  //  bi.bV5Width           = width_;\r
+  //  bi.bV5Height          = height_;\r
+  //  bi.bV5Planes = 1;\r
+  //  bi.bV5BitCount = 32;\r
+  //  bi.bV5Compression = BI_BITFIELDS;\r
+  //  bi.bV5RedMask   =  0x00FF0000;\r
+  //  bi.bV5GreenMask =  0x0000FF00;\r
+  //  bi.bV5BlueMask  =  0x000000FF;\r
+  //  bi.bV5AlphaMask =  0xFF000000; \r
+\r
+  //  // デスクトップHDCの取得\r
+  //  get_dc dc(NULL);\r
+\r
+  //  // DIBセクションの作成\r
+  //  void *bits;// 得られるビットマップ\r
+  //  gdi_object<HBITMAP> bmp(\r
+  //    ::CreateDIBSection(\r
+  //      dc.get(),reinterpret_cast<BITMAPINFO *>(&bi),DIB_RGB_COLORS,&bits,NULL,0));\r
+  //  { \r
+  //    // 互換DCの作成\r
+  //    compatible_dc cdc(dc.get());\r
+  //    {\r
+  //      // 描画先への切り替え\r
+  //      select_object s(cdc.get(),bmp);\r
+\r
+  //      // DC互換レンダーターゲットのセットアップ\r
+  //      D2D1_RENDER_TARGET_PROPERTIES \r
+  //        props = D2D1::RenderTargetProperties(\r
+  //        D2D1_RENDER_TARGET_TYPE_DEFAULT,\r
+  //        D2D1::PixelFormat(\r
+  //            DXGI_FORMAT_B8G8R8A8_UNORM,\r
+  //            D2D1_ALPHA_MODE_PREMULTIPLIED),\r
+  //        0,\r
+  //        0,\r
+  //        D2D1_RENDER_TARGET_USAGE_NONE,\r
+  //        D2D1_FEATURE_LEVEL_DEFAULT\r
+  //      );\r
+\r
+  //      ID2D1DCRenderTargetPtr dcr;\r
+  //      throw_if_err<>()(factory_->CreateDCRenderTarget(&props,&dcr));\r
+  //      RECT rect = {0,0,w,h};\r
+  //      // 互換DCへのバインド\r
+  //      throw_if_err<>()(dcr->BindDC(cdc.get(),&rect));\r
+\r
+  //      // ブラシのセットアップ(背景の赤丸)\r
+  //      ID2D1SolidColorBrushPtr brush_e;\r
+  //      throw_if_err<>()(\r
+  //        dcr->CreateSolidColorBrush(\r
+  //          D2D1::ColorF(D2D1::ColorF::Red,0.8f), &brush_e));\r
+\r
+  //      // アイコンに描画する文字の生成\r
+  //      std::wstring t(L"S.F.\nTimer");\r
+  //      D2D1_RECT_F l = D2D1::RectF(0.0f,0.0f,width_,height_);\r
+  //      // Text Formatの作成\r
+  //      IDWriteTextFormatPtr f;\r
+  //      write_factory_->CreateTextFormat(\r
+  //      L"メイリオ",                // Font family name.\r
+  //      NULL,                       // Font collection (NULL sets it to use the system font collection).\r
+  //      DWRITE_FONT_WEIGHT_REGULAR,\r
+  //      DWRITE_FONT_STYLE_NORMAL,\r
+  //      DWRITE_FONT_STRETCH_NORMAL,\r
+  //      10.0f,\r
+  //      L"ja-jp",\r
+  //      &f\r
+  //      );\r
+  //      f->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);\r
+  //      f->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);\r
+\r
+  //      // 文字描画用ブラシのセットアップ\r
+  //      ID2D1SolidColorBrushPtr brush;\r
+  //      dcr->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &brush);\r
+  //      // 描画開始\r
+  //      dcr->BeginDraw();\r
+  //      // ビットマップクリア\r
+  //      dcr->Clear(D2D1::ColorF(D2D1::ColorF::Black,0.0f));\r
+  //      // 赤丸を描く\r
+  //      dcr->FillEllipse(D2D1::Ellipse(D2D1::Point2F(16.0f,16.0f),14,14),brush_e);\r
+  //      // テキストを表示する\r
+  //      dcr->DrawTextW(t.c_str(),t.size(),f,&l,brush);\r
+  //      // 描画終了\r
+  //      dcr->EndDraw();\r
+  //    }\r
+  //  }\r
+  //}\r
+}\r
diff --git a/mfsample/icon.h b/mfsample/icon.h
new file mode 100644 (file)
index 0000000..6addf7e
--- /dev/null
@@ -0,0 +1,100 @@
+#pragma once\r
+/*\r
+==============================================================================\r
+\r
+This file is part of the async\r
+Copyright 2005-11 by Satoshi Fujiwara.\r
+\r
+async can be redistributed and/or modified under the terms of the\r
+GNU General Public License, as published by the Free Software Foundation;\r
+either version 2 of the License, or (at your option) any later version.\r
+\r
+async is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+GNU General Public License for more details.\r
+\r
+You should have received a copy of the GNU General Public License\r
+along with async; if not, visit www.gnu.org/licenses or write to the\r
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, \r
+Boston, MA 02111-1307 USA\r
+\r
+==============================================================================\r
+*/\r
+\r
+namespace sf {\r
+\r
+  struct icon_deleter {\r
+    typedef HICON pointer;\r
+    void operator ()(HICON handle) {\r
+      if (handle) {\r
+        ::DestroyIcon(handle);\r
+      }\r
+    }\r
+  };\r
+\r
+  /** icon\83n\83\93\83h\83\8b\82Ì\89ð\95ú\82µ\96Y\82ê\82ð\97\\96h\82·\82é */\r
+  typedef std::unique_ptr<HICON,icon_deleter> icon_holder;\r
+\r
+  /** \r
+  \81@icon\8aÇ\97\9d\83N\83\89\83X\r
+  */\r
+  struct icon\r
+  {\r
+  public:\r
+    icon(){};\r
+    explicit icon(uint32_t id);/// \83\8a\83\\81[\83XID\82©\82ç\83A\83C\83R\83\93\82ð\8dì\90¬\82·\82é\r
+    explicit icon(icon_holder& ic);/// \83A\83C\83R\83\93\83t\83H\83\8b\83_\82©\82ç\83A\83C\83R\83\93\82ð\8dì\90¬\82·\82é\r
+    explicit icon(icon_holder&& ic);/// \89E\95Ó\92l\8eQ\8fÆ\82©\82ç\83A\83C\83R\83\93\82ð\8dì\90¬\82·\82é\r
+    icon(bitmap_holder& bmp_color,int width = ::GetSystemMetrics(SM_CXICON),int height = ::GetSystemMetrics(SM_CYICON));\r
+    icon(ID2D1BitmapPtr& ptr);\r
+    icon(boost::filesystem::wpath& path);\r
+\r
+    virtual ~icon();\r
+\r
+    HICON get() const {return icon_.get();};\r
+\r
+    icon(icon& i) : width_(i.width_),height_(i.height_),bits_per_pixel_(i.bits_per_pixel_)\r
+    {\r
+      icon_.reset(::CopyIcon(i.icon_.get()));\r
+    }\r
+\r
+    icon(icon&& i) : width_(i.width_),height_(i.height_),bits_per_pixel_(i.bits_per_pixel_)\r
+    {\r
+      std::swap(icon_,i.icon_);\r
+    }\r
+\r
+    icon& operator= (icon&& i) \r
+    {\r
+      BOOST_ASSERT(icon_ != i.icon_);\r
+      if(icon_ == i.icon_) return *this;\r
+      std::swap(icon_,i.icon_);\r
+      width_ = i.width_;\r
+      height_ = i.height_;\r
+      bits_per_pixel_ = i.bits_per_pixel_;\r
+      return *this;\r
+    }\r
+\r
+    icon& operator= (icon& i);\r
+\r
+    void swap(icon& i)\r
+    {\r
+      std::swap(icon_,i.icon_);\r
+      std::swap(width_,i.width_);\r
+      std::swap(height_,i.height_);\r
+      std::swap(bits_per_pixel_,i.bits_per_pixel_);\r
+    }\r
+\r
+  private:\r
+\r
+    void analyze();\r
+    //ID2D1DCRenderTargetPtr dcr_;\r
+    //ID2D1BitmapPtr bitmap_;\r
+    int width_;\r
+    int height_;\r
+    int bits_per_pixel_;\r
+    icon_holder icon_;\r
+    static bitmap_holder default_mono_bitmap; \r
+  };\r
+}\r
+\r
diff --git a/mfsample/info_tab_dialog.cpp b/mfsample/info_tab_dialog.cpp
new file mode 100644 (file)
index 0000000..8c2bf68
--- /dev/null
@@ -0,0 +1,253 @@
+/*
+==============================================================================
+
+Copyright 2005-11 by Satoshi Fujiwara.
+
+async can be redistributed and/or modified under the terms of the
+GNU General Public License, as published by the Free Software Foundation;
+either version 2 of the License, or (at your option) any later version.
+
+async is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with async; if not, visit www.gnu.org/licenses or write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
+Boston, MA 02111-1307 USA
+
+==============================================================================
+*/
+/* ToDo
+
+TODO: リサイズに対応する
+
+*/
+
+#include "stdafx.h"
+#include "resource.h"
+#define BOOST_ASSIGN_MAX_PARAMS 7
+#include <boost/assign.hpp>
+#include <boost/assign/ptr_list_of.hpp>
+#include <boost/assign/ptr_list_inserter.hpp>
+#include <boost/foreach.hpp>
+
+#if _DEBUG
+#define _CRTDBG_MAP_ALLOC
+#include <crtdbg.h>
+#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
+#endif
+
+#include "sf_windows.h"
+#include "CommDlg.h"
+#include "icon.h"
+#include "timer.h"
+#include "exception.h"
+#include "application.h"
+#include "info_tab_dialog.h"
+
+#define THROW_IFERR(hres) \
+  if (FAILED(hres)) { throw sf::win32_error_exception(hres); }
+
+#ifndef HINST_THISCOMPONENT
+EXTERN_C IMAGE_DOS_HEADER __ImageBase;
+#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase)
+#endif
+
+namespace sf 
+{
+    info_tab_dialog::info_tab_dialog(base_window& parent_window,HWND tab_hwnd,int tab_id,const std::wstring& menu_name,const std::wstring& name,HINSTANCE inst,LPCTSTR temp)
+      : tab_dialog_base(parent_window,tab_hwnd,tab_id,menu_name,name,inst,temp)
+    {
+      create_device_independent_resources();
+      create();
+      hide();
+    }
+
+    info_tab_dialog::~info_tab_dialog()
+    {
+      discard_device();
+      safe_release(factory_);
+      safe_release(write_factory_);
+    };
+
+    LRESULT info_tab_dialog::window_proc(HWND hwnd,uint32_t message, WPARAM wParam, LPARAM lParam)
+    {
+      switch(message)
+      {
+      case WM_INITDIALOG:
+        create_device();
+        application::instance()->init_player(GetDlgItem(hwnd,IDC_VIDEO),(HWND)parent_window_.raw_handle());
+        break;
+      case WM_CTLCOLORDLG:
+      case WM_CTLCOLORSTATIC:
+      case WM_CTLCOLOREDIT:
+      case WM_CTLCOLORLISTBOX:
+      case WM_CTLCOLORBTN:
+        SetBkMode((HDC)wParam,TRANSPARENT);
+        return  (LRESULT)GetStockObject( NULL_BRUSH ); ;
+      case WM_ERASEBKGND:
+        return FALSE;
+      case WM_PAINT:
+        {
+          //create_device();
+
+          { 
+            paint_struct begin_paint(hwnd);
+            //CloseHandle(cb);
+            // 描画コードの呼び出し
+            render();
+
+          }
+        }
+        break;
+      case WM_DESTROY:
+        discard_device();
+        return FALSE;
+      }
+      return FALSE;
+
+    };
+
+    void info_tab_dialog::create_device_independent_resources()
+    {
+      // Direct2DFactory の生成
+      if(!factory_){
+#if defined(DEBUG) || defined(_DEBUG)
+        D2D1_FACTORY_OPTIONS options;
+        options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION ;
+        THROW_IFERR(D2D1CreateFactory(
+          D2D1_FACTORY_TYPE_SINGLE_THREADED,
+          options,
+          factory_.GetAddressOf()
+          ));
+#else
+        THROW_IFERR(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &factory_));
+#endif
+
+      }
+
+      if(!write_factory_){
+        THROW_IFERR(::DWriteCreateFactory(
+          DWRITE_FACTORY_TYPE_SHARED,
+          __uuidof(IDWriteFactory),
+          reinterpret_cast<IUnknown**>(write_factory_.GetAddressOf())
+          ));
+      }
+
+
+      //wic_imaging_factory_.CreateInstance(CLSID_WICImagingFactory);
+
+      //thunk_proc_ = (WNDPROC)thunk_.getCode();
+      layout_rect_ = D2D1::RectF(0.0f,100.0f,400.0f,100.0f);
+      // Text Formatの作成
+      THROW_IFERR(write_factory_->CreateTextFormat(
+        L"メイリオ",                // Font family name.
+        NULL,                       // Font collection (NULL sets it to use the system font collection).
+        DWRITE_FONT_WEIGHT_REGULAR,
+        DWRITE_FONT_STYLE_NORMAL,
+        DWRITE_FONT_STRETCH_NORMAL,
+        24.0f,
+        L"ja-jp",
+        &write_text_format_
+        ));
+
+    }
+
+    void info_tab_dialog::create_device()
+    {
+      if(!render_target_)
+      {
+
+        HWND waveform_hwnd = GetDlgItem(hwnd_,IDC_WAVEFORM);
+        RECT rc;
+        GetClientRect(waveform_hwnd, &rc);
+        //  GetClientRect(hwnd_, &rc);
+
+        D2D1_SIZE_U size = D2D1::SizeU(
+          rc.right - rc.left,
+          rc.bottom - rc.top
+          );
+
+        const D2D1_PIXEL_FORMAT format =
+          D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM,
+          D2D1_ALPHA_MODE_PREMULTIPLIED);
+
+        const D2D1_RENDER_TARGET_PROPERTIES target_prop = 
+          D2D1::RenderTargetProperties(D2D1_RENDER_TARGET_TYPE_DEFAULT,format);
+
+        THROW_IFERR(factory_->CreateHwndRenderTarget(
+          target_prop,
+          D2D1::HwndRenderTargetProperties(waveform_hwnd, size,D2D1_PRESENT_OPTIONS_IMMEDIATELY),
+          &render_target_
+          ));
+        //D2D1::HwndRenderTargetProperties(hwnd_, size,D2D1_PRESENT_OPTIONS_IMMEDIATELY),
+        //&render_target_
+        //));
+      }
+    }
+
+    void info_tab_dialog::discard_device()
+    {
+    //safe_release(sampler_state_);
+    //safe_release(shader_res_view_);
+    //safe_release(cb_changes_every_frame_);
+    //safe_release(cb_change_on_resize_);
+    //safe_release(cb_never_changes_);
+    //safe_release(i_buffer_);
+    //safe_release(v_buffer_);
+    //safe_release(p_shader_);
+    //safe_release(input_layout_);
+    //safe_release(v_shader_);
+    // discard_swap_chain_dependent_resources();
+    safe_release(render_target_);
+ /*   safe_release(swap_chain_);
+    safe_release(d3d_context_);
+    safe_release(d3d_device_);
+    safe_release(adapter_);
+ */ 
+    }
+
+    void info_tab_dialog::render()
+    {
+    if (render_target_)
+    {
+      // Retrieve the size of the render target.
+      D2D1_SIZE_F renderTargetSize = render_target_->GetSize();
+      try {
+        render_target_->BeginDraw();
+//        render_target_->PushAxisAlignedClip(layout_rect_,D2D1_ANTIALIAS_MODE_ALIASED);
+      //  render_target_->Clear(D2D1::ColorF(D2D1::ColorF::AliceBlue));
+        //render_target_->FillRectangle(D2D1::RectF(0.0f,0.0f,renderTargetSize.width,renderTargetSize.height),);
+        render_target_->SetTransform(D2D1::Matrix3x2F::Identity());
+        ID2D1SolidColorBrushPtr brush;
+        render_target_->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::OrangeRed), &brush);
+
+        std::wstring m(L"WAVE FORMを描くところ!");
+        render_target_->DrawTextW(
+          m.c_str(),
+          m.size(),
+          write_text_format_.Get(),
+          layout_rect_, 
+          brush.Get());
+ //       render_target_->PopAxisAlignedClip();
+        THROW_IFERR(render_target_->EndDraw());
+
+      } catch(sf::win32_error_exception& err)
+      {
+        if(err.hresult() == D2DERR_RECREATE_TARGET)
+        {
+          discard_device();
+          create_device();
+        } else {
+          throw;
+        }
+      } catch(...) {
+        throw;
+      }
+    }
+    }
+
+}
+
diff --git a/mfsample/info_tab_dialog.h b/mfsample/info_tab_dialog.h
new file mode 100644 (file)
index 0000000..1e7b1ab
--- /dev/null
@@ -0,0 +1,43 @@
+#pragma once
+/*
+*/
+// Windows Header Files:
+#include "base_window.h"
+#include "sf_windows.h"
+#include "icon.h"
+#include "taskbar.h"
+#include "tab_dialog.h"
+
+namespace sf
+{
+
+  struct info_tab_dialog : public tab_dialog_base
+  {
+    info_tab_dialog(
+      sf::base_window& parent_window,
+      HWND tab_hwnd,
+      int tab_id,
+      const std::wstring& menu_name,
+      const std::wstring& name,
+      HINSTANCE inst,
+      LPCTSTR temp);
+    virtual ~info_tab_dialog();
+    virtual LRESULT window_proc(HWND hwnd,uint32_t message, WPARAM wParam, LPARAM lParam);
+    virtual void enable(){};
+    virtual void disable(){};
+  private:
+
+    void create_device_independent_resources();
+    void create_device();
+    void discard_device();
+    void render();
+
+    ID2D1FactoryPtr factory_;
+    ID2D1HwndRenderTargetPtr render_target_;
+    IDWriteFactoryPtr write_factory_;
+    IWICImagingFactoryPtr wic_imaging_factory_;
+    IDWriteTextFormatPtr write_text_format_;
+    D2D1_RECT_F layout_rect_;
+
+  };
+}
\ No newline at end of file
diff --git a/mfsample/jumplist.cpp b/mfsample/jumplist.cpp
new file mode 100644 (file)
index 0000000..3103f21
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+  ==============================================================================
+
+   This file is part of the async
+   Copyright 2005-10 by Satoshi Fujiwara.
+
+   async can be redistributed and/or modified under the terms of the
+   GNU General Public License, as published by the Free Software Foundation;
+   either version 2 of the License, or (at your option) any later version.
+
+   async is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with async; if not, visit www.gnu.org/licenses or write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
+   Boston, MA 02111-1307 USA
+
+  ==============================================================================
+*/
+#include "StdAfx.h"
+#include "jumplist.h"
+
+
diff --git a/mfsample/jumplist.h b/mfsample/jumplist.h
new file mode 100644 (file)
index 0000000..ae76867
--- /dev/null
@@ -0,0 +1,32 @@
+#pragma once
+/*
+  ==============================================================================
+
+   This file is part of the async
+   Copyright 2005-10 by Satoshi Fujiwara.
+
+   async can be redistributed and/or modified under the terms of the
+   GNU General Public License, as published by the Free Software Foundation;
+   either version 2 of the License, or (at your option) any later version.
+
+   async is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with async; if not, visit www.gnu.org/licenses or write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
+   Boston, MA 02111-1307 USA
+
+  ==============================================================================
+*/
+namespace sf{
+struct jumplist
+{
+public:
+  jumplist(){};
+  virtual ~jumplist(){};
+};
+}
+
diff --git a/mfsample/logger.cpp b/mfsample/logger.cpp
new file mode 100644 (file)
index 0000000..01e33b7
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+==============================================================================
+
+This file is part of the S.F.Tracker
+Copyright 2005-7 by Satoshi Fujiwara.
+
+S.F.Tracker can be redistributed and/or modified under the terms of the
+GNU General Public License, as published by the Free Software Foundation;
+either version 2 of the License, or (at your option) any later version.
+
+S.F.Tracker is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with S.F.Tracker; if not, visit www.gnu.org/licenses or write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
+Boston, MA 02111-1307 USA
+
+==============================================================================
+*/
+/** @file
+*  @author S.F. (Satoshi Fujiwara)
+*/
+
+#include "stdafx.h"
+#if _DEBUG
+#define _CRTDBG_MAP_ALLOC
+#include <crtdbg.h>
+#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
+#endif
+namespace sf {
+
+  struct logger::impl 
+  {
+    impl() : m_log_file("sftracker.log",std::ios_base::out | std::ios_base::trunc ){};
+    ~impl() {m_log_file.close();}
+
+    void write(const boost::wformat & fmt)
+    {
+      write(fmt.str());
+    };
+
+    void write(const std::wistream & st)
+    {
+      {   
+        //mutex_type::scoped_lock lock_(m_mutex);
+        m_log_file << st << std::endl;
+      }
+      boost::gregorian::date dt = boost::gregorian::day_clock::local_day();
+
+    };
+
+    void write(const std::wstring & mes) 
+    {   
+      write(mes.c_str());
+    }
+
+    void write(const TCHAR * mes) 
+    {   
+      //mutex_type::scoped_lock lock_(m_mutex);
+      m_log_file << mes << std::endl;
+      m_log_file.flush();
+    }   
+  private:
+    std::wofstream m_log_file;
+    //mutex_type m_mutex;
+  };
+
+  logger::logger() : m_impl(new logger::impl())
+  {
+  }
+  void logger::write(const boost::wformat & fmt)
+  {
+    m_impl->write(fmt);
+  };
+
+  void logger::write(const std::wstring & mes) 
+  {   
+    m_impl->write(mes);
+  }
+
+  void logger::write(const TCHAR * mes) 
+  {   
+    m_impl->write(mes);
+  }   
+
+  void logger::write(const std::wistream & st)
+  {
+    m_impl->write(st);
+  }
+
+  logger::~logger()
+  {
+
+  }
+
+  void debug_out(const char * file_name,const int line,boost::wformat& fmt)
+  {
+    OutputDebugString((boost::wformat(_T("%s(%d) %s \n")) % std::wstring(sf::code_converter<char,wchar_t>(file_name)) % line % fmt).str().c_str());
+  };
+
+  void debug_out(const char * file_name,const int line,const std::wstring& str)
+  {
+    OutputDebugString((boost::wformat(_T("%s(%d) %s \n")) % std::wstring(sf::code_converter<char,wchar_t>(file_name)) % line % str).str().c_str());
+  };
+
+  void debug_out(const char * file_name,const int line,const char* str)
+  {
+    OutputDebugString((boost::wformat(_T("%s(%d) %s \n")) % std::wstring(sf::code_converter<char,wchar_t>(file_name)) %  line % sf::code_converter<char,wchar_t>(str)).str().c_str());
+  }
+
+  void debug_outW(const char * file_name,const int line,const wchar_t* str)
+  {
+    OutputDebugString((boost::wformat(_T("%s(%d) %s \n")) % std::wstring(sf::code_converter<char,wchar_t>(file_name)) % line % str).str().c_str());
+  };
+
+}
diff --git a/mfsample/logger.h b/mfsample/logger.h
new file mode 100644 (file)
index 0000000..dd0b08c
--- /dev/null
@@ -0,0 +1,37 @@
+#pragma once
+
+#include "boost/date_time/gregorian/gregorian.hpp"
+#include "boost/date_time/posix_time/posix_time.hpp"
+#include "singleton.h"
+
+namespace sf {
+
+  struct logger : public singleton<logger>
+  {
+  public:
+    logger();
+    ~logger();
+    void write(const boost::wformat & fmt);
+    void write(const std::wstring & mes);
+    void write(const TCHAR * mes);
+    void write(const std::wistream & st);
+  private:
+    struct impl;
+    std::shared_ptr<impl> m_impl;
+  };
+
+  void debug_out(const char * file_name,const int line,boost::wformat& fmt);
+  void debug_out(const char * file_name,const int line,const std::wstring& str);
+  void debug_out(const char * file_name,const int line,const char* str);
+  void debug_out(const char * file_name,const int line,const wchar_t* str);
+}
+
+#define WRITE_LOG(s) \
+  sf::logger::instance()->write(boost::wformat(_T("%s %s %6d %s")) % boost::posix_time::second_clock::local_time() % (TCHAR*)sf::ca2t(__FILE__) % __LINE__ % (s))
+
+#ifdef _DEBUG
+#define SFTRACE(x) sf::debug_out(__FILE__,__LINE__,(x))
+#else 
+#define SFTRACE(x) 
+#endif
+
diff --git a/mfsample/message_loop.h b/mfsample/message_loop.h
new file mode 100644 (file)
index 0000000..37c3b90
--- /dev/null
@@ -0,0 +1,92 @@
+#pragma once
+/*
+  ==============================================================================
+
+   This file is part of the S.F.Tracker
+   Copyright 2005-7 by Satoshi Fujiwara.
+
+   S.F.Tracker can be redistributed and/or modified under the terms of the
+   GNU General Public License, as published by the Free Software Foundation;
+   either version 2 of the License, or (at your option) any later version.
+
+   S.F.Tracker is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with S.F.Tracker; if not, visit www.gnu.org/licenses or write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
+   Boston, MA 02111-1307 USA
+
+  ==============================================================================
+*/
+/** @file
+ *  @brief 
+ *  @author S.F. (Satoshi Fujiwara)
+ */
+namespace sf {
+       struct run_message_loop
+       {
+               run_message_loop(){};
+               inline WPARAM operator()()
+               {
+                       MSG msg;
+                       while (GetMessage(&msg, NULL, 0, 0))
+                       {
+                               TranslateMessage(&msg);
+                               DispatchMessage(&msg);
+                       }
+      return msg.wParam;
+               }
+
+               ~run_message_loop(void){};
+       };
+
+       struct peek_message_loop
+       {
+               typedef boost::function<void ()> func_type;
+               explicit peek_message_loop(func_type func)  {func_ =  func;};
+               inline WPARAM operator()()
+               {
+                       MSG msg = {0};
+                       while( WM_QUIT != msg.message )
+                       {
+                               if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
+                               {
+                                       TranslateMessage( &msg );
+                                       DispatchMessage( &msg );
+                               }
+                               else
+                               {
+                                       func_();  // Do some rendering
+                               }
+                       }
+      return msg.wParam;
+               };
+       private:
+               func_type func_;
+       };
+
+  struct dialog_message_loop
+       {
+               dialog_message_loop(HWND dialog) : dialog_(dialog) {};
+               inline WPARAM operator()()
+               {
+                       MSG msg;
+                       while (GetMessage(&msg, NULL, 0, 0))
+                       {
+        if(IsDialogMessage(dialog_,&msg) == FALSE)
+        {
+                                 TranslateMessage(&msg);
+                                 DispatchMessage(&msg);
+        }
+                       }
+      return msg.wParam;
+               }
+               ~dialog_message_loop(){};
+  private:
+    HWND dialog_;
+
+       };
+}
diff --git a/mfsample/mfsample.manifest b/mfsample/mfsample.manifest
new file mode 100644 (file)
index 0000000..47189d1
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>\r
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">\r
+\r
+  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">\r
+    <application>\r
+      <!--Windows 7-->\r
+      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />\r
+    </application>\r
+  </compatibility>\r
+  <dependency>\r
+      <dependentAssembly>\r
+          <assemblyIdentity type="win32"\r
+                name="Microsoft.Windows.Common-Controls"\r
+                version="6.0.0.0"\r
+                processorArchitecture="amd64"\r
+                publicKeyToken="6595b64144ccf1df"\r
+                language="*" />\r
+        \r
+    </dependentAssembly>\r
+  </dependency>\r
+</assembly>\r
diff --git a/mfsample/mfsample.vcxproj b/mfsample/mfsample.vcxproj
new file mode 100644 (file)
index 0000000..20902e6
--- /dev/null
@@ -0,0 +1,204 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{4489213E-E01F-4AB3-9193-B00756D27BB1}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>mfsample</RootNamespace>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v110</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v120_CTP_Nov2012</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v110</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v120_CTP_Nov2012</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="..\SF.props" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="..\SF.props" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <LinkIncremental>true</LinkIncremental>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <LinkIncremental>true</LinkIncremental>
+    <LibraryPath>H:\libs\DirectXTK\Bin\Desktop\x64\Debug;$(LibraryPath)</LibraryPath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <LinkIncremental>false</LinkIncremental>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PrecompiledHeader>Use</PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+      <MinimalRebuild>false</MinimalRebuild>
+      <AdditionalOptions>/Zm200  /D_SCL_SECURE_NO_WARNINGS %(AdditionalOptions)</AdditionalOptions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>Comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
+    <Manifest>
+      <AdditionalManifestFiles>mfsample.manifest</AdditionalManifestFiles>
+    </Manifest>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <AdditionalOptions>/Zm200 %(AdditionalOptions)</AdditionalOptions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="application.cpp" />
+    <ClCompile Include="base_window.cpp" />
+    <ClCompile Include="code_converter.cpp" />
+    <ClCompile Include="dpi.cpp" />
+    <ClCompile Include="exception.cpp" />
+    <ClCompile Include="icon.cpp" />
+    <ClCompile Include="info_tab_dialog.cpp" />
+    <ClCompile Include="jumplist.cpp" />
+    <ClCompile Include="logger.cpp" />
+    <ClCompile Include="player.cpp" />
+    <ClCompile Include="sf_com.cpp" />
+    <ClCompile Include="sf_windows.cpp" />
+    <ClCompile Include="stdafx.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="tab_dialog.cpp" />
+    <ClCompile Include="taskbar.cpp" />
+    <ClCompile Include="timer.cpp" />
+    <ClCompile Include="toplevel_window.cpp" />
+    <ClCompile Include="winmain.cpp" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="application.h" />
+    <ClInclude Include="code_converter.h" />
+    <ClInclude Include="dout.h" />
+    <ClInclude Include="dpi.h" />
+    <ClInclude Include="exception.h" />
+    <ClInclude Include="icon.h" />
+    <ClInclude Include="info_tab_dialog.h" />
+    <ClInclude Include="jumplist.h" />
+    <ClInclude Include="logger.h" />
+    <ClInclude Include="message_loop.h" />
+    <ClInclude Include="player.h" />
+    <ClInclude Include="resource.h" />
+    <ClInclude Include="sf_com.h" />
+    <ClInclude Include="sf_memory.h" />
+    <ClInclude Include="sf_windows.h" />
+    <ClInclude Include="singleton.h" />
+    <ClInclude Include="stdafx.h" />
+    <ClInclude Include="tab_dialog.h" />
+    <ClInclude Include="taskbar.h" />
+    <ClInclude Include="timer.h" />
+    <ClInclude Include="toplevel_window.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ResourceCompile Include="wasapi2.rc" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file
diff --git a/mfsample/player.cpp b/mfsample/player.cpp
new file mode 100644 (file)
index 0000000..8a2f885
--- /dev/null
@@ -0,0 +1,682 @@
+
+// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+// PARTICULAR PURPOSE.
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+#include "stdafx.h"
+#include "Player.h"
+#include <assert.h>
+
+#if _DEBUG
+#define _CRTDBG_MAP_ALLOC
+#include <crtdbg.h>
+#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
+#endif
+
+#pragma comment(lib, "shlwapi")
+#pragma comment(lib,"Mfplat.lib")
+#pragma comment(lib,"Mf.lib")
+#pragma comment(lib,"Mfuuid.lib")
+#pragma comment(lib,"Strmiids.lib")
+
+//Mf.lib Mfidl.h
+namespace sf {
+  namespace player {
+    template <class Q>
+    HRESULT GetEventObject(IMFMediaEvent *pEvent, Q **ppObject)
+    {
+      *ppObject = NULL;   // zero output
+
+      PROPVARIANT var;
+      HRESULT hr = pEvent->GetValue(&var);
+      if (SUCCEEDED(hr))
+      {
+        if (var.vt == VT_UNKNOWN)
+        {
+          hr = var.punkVal->QueryInterface(ppObject);
+        }
+        else
+        {
+          hr = MF_E_INVALIDTYPE;
+        }
+        PropVariantClear(&var);
+      }
+      return hr;
+    }
+
+    IMFMediaSourcePtr CreateMediaSource(const std::wstring& pszURL);
+
+    IMFTopologyPtr CreatePlaybackTopology(IMFMediaSourcePtr pSource, 
+      IMFPresentationDescriptorPtr pPD, HWND hVideoWnd);
+
+    //  Player_\83I\83u\83W\83F\83N\83g\82ð\90\90¬\82·\82é\83t\83\8a\81[\8aÖ\90\94
+    PlayerPtr CreatePlayer(
+      HWND hVideo,                  // Video window.
+      HWND hEvent                  // Window to receive notifications.
+      )           
+    {
+
+      PlayerPtr p(new Player(hVideo, hEvent));
+
+      if (!p)
+      {
+        throw win32_error_exception(E_OUTOFMEMORY);
+      }
+      p->process_event(ev::Init());
+//      p->processInitialize();
+      return p;
+    }
+
+    void Player_::initialize(const ev::Init& ev)
+    {
+      // Start up Media Foundation platform.
+      THROW_IF_ERR(MFStartup(MF_VERSION));
+      m_hCloseEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+      THROW_IF_ERR(HRESULT_FROM_WIN32(GetLastError()));
+    }
+
+    Player_::Player_(HWND hVideo, HWND hEvent) : 
+      m_hwndVideo(hVideo),
+      m_hwndEvent(hEvent),
+//      m_state(Closed),
+      m_hCloseEvent(NULL),
+      m_nRefCount(0)
+    {
+    }
+
+    Player_::~Player_()
+    {
+      assert(m_pSession.Get() == NULL);  
+      // If FALSE, the app did not call Shutdown().
+
+      // When Player_ calls IMediaEventGenerator::BeginGetEvent on the
+      // media session, it causes the media session to hold a reference 
+      // count on the Player_. 
+
+      // This creates a circular reference count between Player_ and the 
+      // media session. Calling Shutdown breaks the circular reference 
+      // count.
+
+      // If CreateInstance fails, the application will not call 
+      // Shutdown. To handle that case, call Shutdown in the destructor. 
+
+      shutdown(ev::Close());
+    }
+
+    // IUnknown methods
+
+    HRESULT Player_::QueryInterface(REFIID riid, void** ppv)
+    {
+      static const QITAB qit[] = 
+      {
+        QITABENT(Player_, IMFAsyncCallback),
+        { 0 }
+      };
+      return QISearch(this, qit, riid, ppv);
+    }
+
+    ULONG Player_::AddRef()
+    {
+      return InterlockedIncrement(&m_nRefCount);
+    }
+
+    ULONG Player_::Release()
+    {
+      ULONG uCount = InterlockedDecrement(&m_nRefCount);
+      if (uCount == 0)
+      {
+        delete this;
+      }
+      return uCount;
+    }
+
+    //  Open a URL for playback.
+    void Player_::open_url( ev::OpenURL const& openurl)
+    {
+      // 1. Create a new media session.
+      // 2. Create the media source.
+      // 3. Create the topology.
+      // 4. Queue the topology [asynchronous]
+      // 5. Start playback [asynchronous - does not happen in this method.]
+
+      IMFTopologyPtr pTopology;
+      IMFPresentationDescriptorPtr pSourcePD;
+
+      // Create the media session.
+      CreateSession();
+
+      // Create the media source.
+      m_pSource = CreateMediaSource(openurl.url());
+
+      // Create the presentation descriptor for the media source.
+      THROW_IF_ERR(m_pSource->CreatePresentationDescriptor(&pSourcePD));
+
+      // Create a partial topology.
+      pTopology = CreatePlaybackTopology(m_pSource, pSourcePD, m_hwndVideo);
+
+      // Set the topology on the media session.
+      THROW_IF_ERR(m_pSession->SetTopology(0, pTopology.Get()));
+
+//      OnOpenURL_();
+
+      // m_state = OpenPending;
+
+      // If SetTopology succeeds, the media session will queue an 
+      // MESessionTopologySet event.
+    }
+
+    //  Pause playback.
+    void Player_::pause( ev::Pause const& ev)    
+    {
+//      if (m_state != Started)
+//      {
+//        throw win32_error_exception(MF_E_INVALIDREQUEST);
+//      }
+//
+//      if (!m_pSession  || !m_pSource)
+//      {
+//       throw win32_error_exception(E_UNEXPECTED);
+//      }
+
+      THROW_IF_ERR(m_pSession->Pause());
+      OnPause()(static_cast<this_type&>(*this));
+      
+      //m_state = Paused;
+    }
+
+    // Stop playback.
+    void Player_::stop( ev::Stop const& ev)
+    {
+      //if (m_state != Started && m_state != Paused)
+      //{
+      //  throw win32_error_exception( MF_E_INVALIDREQUEST );
+      //}
+      //if (!m_pSession)
+      //{
+      //  throw win32_error_exception( E_UNEXPECTED);
+      //}
+
+      THROW_IF_ERR(m_pSession->Stop());
+      OnStop()(static_cast<this_type&>(*this));
+    }
+
+    //  Repaint the video window. Call this method on WM_PAINT.
+    void Player_::Repaint()
+    {
+      if (m_pVideoDisplay)
+      {
+        m_pVideoDisplay->RepaintVideo();
+      }
+    }
+
+    //  Resize the video rectangle.
+    //
+    //  Call this method if the size of the video window changes.
+
+    void Player_::ResizeVideo(WORD width, WORD height)
+    {
+      if (m_pVideoDisplay)
+      {
+        // Set the destination rectangle.
+        // Leave the default source rectangle (0,0,1,1).
+
+        RECT rcDest = { 0, 0, width, height };
+
+        THROW_IF_ERR(m_pVideoDisplay->SetVideoPosition(NULL, &rcDest));
+      }
+    }
+
+    //  Callback for the asynchronous BeginGetEvent method.
+
+    HRESULT Player_::Invoke(IMFAsyncResult *pResult)
+    {
+      MediaEventType meType = MEUnknown;  // Event type
+
+      IMFMediaEventPtr pEvent;
+
+      try {
+        // Get the event from the event queue.
+        THROW_IF_ERR(m_pSession->EndGetEvent(pResult, pEvent.GetAddressOf()));
+
+        // Get the event type. 
+        THROW_IF_ERR(pEvent->GetType(&meType));
+
+        if (meType == MESessionClosed)
+        {
+          // The session was closed. 
+          // The application is waiting on the m_hCloseEvent event handle. 
+          SetEvent(m_hCloseEvent);
+        }
+        else
+        {
+          // For all other events, get the next event in the queue.
+          THROW_IF_ERR(m_pSession->BeginGetEvent(this, NULL));
+        }
+
+        // Check the application state. 
+
+        // If a call to IMFMediaSession::Close is pending, it means the 
+        // application is waiting on the m_hCloseEvent event and
+        // the application's message loop is blocked. 
+
+        // Otherwise, post a private window message to the application. 
+
+        //if (m_state != Closing)
+        //{
+        //  // Leave a reference count on the event.
+
+        //  //PostMessage(m_hwndEvent, WM_APP_PLAYER_EVENT, 
+        //  //  (WPARAM) pEvent.Detach(), (LPARAM)meType);
+        //}
+
+        HandleEvent((UINT_PTR)pEvent.Detach());
+
+        return S_OK;
+      } catch (win32_error_exception& e) 
+      {
+        return e.hresult();
+      }
+    }
+
+    void Player_::HandleEvent(UINT_PTR pEventPtr)
+    {
+      MediaEventType meType = MEUnknown;  
+
+      IMFMediaEventPtr pEvent;
+      //    pEvent.Attach((IMFMediaEvent*)pEventPtr);
+      pEvent.Attach(reinterpret_cast<IMFMediaEvent*>(pEventPtr));
+
+      if (!pEvent)
+      {
+        throw win32_error_exception(E_POINTER);
+      }
+
+      // Get the event type.
+      THROW_IF_ERR(pEvent->GetType(&meType));
+
+      // Get the event status. If the operation that triggered the event 
+      // did not succeed, the status is a failure code.
+      HRESULT hrStatus = S_OK;
+      THROW_IF_ERR(pEvent->GetStatus(&hrStatus));
+      // Check if the async operation succeeded.
+      THROW_IF_ERR(hrStatus);
+
+      switch(meType)
+      {
+      case MESessionTopologyStatus:
+        OnTopologyStatus(pEvent);
+        break;
+
+      case MEEndOfPresentation:
+        OnPresentationEnded(pEvent);
+        break;
+
+      case MENewPresentation:
+        OnNewPresentation(pEvent);
+        break;
+
+      default:
+        OnSessionEvent(pEvent, meType);
+        break;
+      }
+    }
+
+    //  Release all resources held by this object.
+    void Player_::shutdown( ev::Close const& ev)
+    {
+      // Close the session
+      CloseSession();
+
+      // Shutdown the Media Foundation platform
+      MFShutdown();
+
+      if (m_hCloseEvent)
+      {
+        CloseHandle(m_hCloseEvent);
+        m_hCloseEvent = NULL;
+      }
+    }
+
+    /// Protected methods
+
+    void Player_::OnTopologyStatus(IMFMediaEventPtr pEvent)
+    {
+      UINT32 status; 
+
+      THROW_IF_ERR(pEvent->GetUINT32(MF_EVENT_TOPOLOGY_STATUS, &status));
+      if (status == MF_TOPOSTATUS_READY)
+      {
+        safe_release(m_pVideoDisplay);
+
+        // Get the IMFVideoDisplayControl interface from EVR. This call is
+        // expected to fail if the media file does not have a video stream.
+
+        (void)MFGetService(m_pSession.Get(), MR_VIDEO_RENDER_SERVICE, 
+          IID_PPV_ARGS(m_pVideoDisplay.GetAddressOf()));
+        static_cast<this_type&>(*this).process_event(ev::OpenComplete());
+        //StartPlayback();
+      }
+    }
+
+
+    //  Handler for MEEndOfPresentation event.
+    void Player_::OnPresentationEnded(IMFMediaEventPtr pEvent)
+    {
+      // The session puts itself into the stopped state automatically.
+      // m_state = Stopped;
+      static_cast<this_type&>(*this).process_event(ev::Stop());
+    }
+
+    //  Handler for MENewPresentation event.
+    //
+    //  This event is sent if the media source has a new presentation, which 
+    //  requires a new topology. 
+
+    void Player_::OnNewPresentation(IMFMediaEventPtr pEvent)
+    {
+      IMFPresentationDescriptorPtr pPD;
+      IMFTopologyPtr pTopology;
+
+      // Get the presentation descriptor from the event.
+      THROW_IF_ERR(GetEventObject(pEvent.Get(), pPD.GetAddressOf()));
+
+      // Create a partial topology.
+      pTopology = CreatePlaybackTopology(m_pSource, pPD,  m_hwndVideo);
+
+      // Set the topology on the media session.
+      THROW_IF_ERR(m_pSession->SetTopology(0, pTopology.Get()));
+
+      // m_state = OpenPending;
+
+    }
+
+    //  Create a new instance of the media session.
+    void Player_::CreateSession()
+    {
+      // Close the old session, if any.
+      CloseSession();
+
+      // assert(m_state == Closed);
+
+      // Create the media session.
+      THROW_IF_ERR(MFCreateMediaSession(NULL, &m_pSession));
+
+      // Start pulling events from the media session
+      THROW_IF_ERR(m_pSession->BeginGetEvent((IMFAsyncCallback*)this, NULL));
+      // m_state = Ready;
+    }
+
+    //  Close the media session. 
+    void Player_::CloseSession()
+    {
+      //  The IMFMediaSession::Close method is asynchronous, but the 
+      //  Player_::CloseSession method waits on the MESessionClosed event.
+      //  
+      //  MESessionClosed is guaranteed to be the last event that the 
+      //  media session fires.
+
+      m_pVideoDisplay.Reset();
+
+      // First close the media session.
+      if (m_pSession)
+      {
+        DWORD dwWaitResult = 0;
+
+        //m_state = Closing;
+
+        THROW_IF_ERR(m_pSession->Close());
+        // Wait for the close operation to complete
+        dwWaitResult = WaitForSingleObject(m_hCloseEvent, 5000);
+        if (dwWaitResult == WAIT_TIMEOUT)
+        {
+          assert(FALSE);
+        }
+        // Now there will be no more events from this session.
+      }
+
+      if (m_pSource)
+      {
+        m_pSource->Shutdown();
+      }
+      // Shut down the media session. (Synchronous operation, no events.)
+      if (m_pSession)
+      {
+        m_pSession->Shutdown();
+      }
+
+      m_pSource.Reset();
+      m_pSession.Reset();
+      //m_state = Closed;
+    }
+
+    //  Start playback from the current position. 
+    void Player_::StartPlayback()
+    {
+      assert(m_pSession != NULL);
+
+      prop_variant varStart;
+      //    PROPVARIANT varStart;
+      //    PropVariantInit(&varStart);
+
+      THROW_IF_ERR(m_pSession->Start(&GUID_NULL, &varStart));
+      // Note: Start is an asynchronous operation. However, we
+      // can treat our state as being already started. If Start
+      // fails later, we'll get an MESessionStarted event with
+      // an error code, and we will update our state then.
+      //m_state = Started;
+    }
+
+    //  Start playback from paused or stopped.
+    void Player_::play( ev::Play const& ev)
+    {
+ /*     if (m_state != Paused && m_state != Stopped)
+      {
+        THROW_IF_ERR(MF_E_INVALIDREQUEST);
+      }*/
+      if (!m_pSession || !m_pSource)
+      {
+        THROW_IF_ERR(E_UNEXPECTED);
+      }
+      StartPlayback();
+      OnStart()(static_cast<this_type&>(*this));
+    }
+
+
+    //  Create a media source from a URL.
+    IMFMediaSourcePtr CreateMediaSource(const std::wstring& sURL)
+    {
+      MF_OBJECT_TYPE ObjectType = MF_OBJECT_INVALID;
+
+      IMFSourceResolverPtr pSourceResolver;
+      Microsoft::WRL::ComPtr<IUnknown> pSource;
+      IMFMediaSourcePtr pSourceReturn;
+      // Create the source resolver.
+      THROW_IF_ERR(MFCreateSourceResolver(pSourceResolver.GetAddressOf()));
+
+      // Use the source resolver to create the media source.
+
+      // Note: For simplicity this sample uses the synchronous method to create 
+      // the media source. However, creating a media source can take a noticeable
+      // amount of time, especially for a network source. For a more responsive 
+      // UI, use the asynchronous BeginCreateObjectFromURL method.
+
+      THROW_IF_ERR(pSourceResolver->CreateObjectFromURL(
+        sURL.c_str(),                       // URL of the source.
+        MF_RESOLUTION_MEDIASOURCE,  // Create a source object.
+        NULL,                       // Optional property store.
+        &ObjectType,        // Receives the created object type. 
+        &pSource            // Receives a pointer to the media source.
+        ));
+
+      // Get the IMFMediaSource interface from the media source.
+      THROW_IF_ERR(pSource.As<IMFMediaSource>(&pSourceReturn));
+      return pSourceReturn;
+    }
+
+    //  Create an activation object for a renderer, based on the stream media type.
+
+    IMFActivatePtr CreateMediaSinkActivate(
+      IMFStreamDescriptor* pSourceSD,     // Pointer to the stream descriptor.
+      HWND hVideoWindow                 // Handle to the video clipping window.
+      )
+    {
+      IMFMediaTypeHandlerPtr pHandler;
+      IMFActivatePtr pActivate;
+
+      // Get the media type handler for the stream.
+      THROW_IF_ERR(pSourceSD->GetMediaTypeHandler(pHandler.GetAddressOf()));
+
+      // Get the major media type.
+      GUID guidMajorType;
+      THROW_IF_ERR(pHandler->GetMajorType(&guidMajorType));
+
+      // Create an IMFActivate object for the renderer, based on the media type.
+      if (MFMediaType_Audio == guidMajorType)
+      {
+        // Create the audio renderer.
+        THROW_IF_ERR(MFCreateAudioRendererActivate(pActivate.GetAddressOf()));
+      }
+      else if (MFMediaType_Video == guidMajorType)
+      {
+        // Create the video renderer.
+        THROW_IF_ERR(MFCreateVideoRendererActivate(hVideoWindow, pActivate.GetAddressOf()));
+      }
+      else
+      {
+        // Unknown stream type. 
+        THROW_IF_ERR(E_FAIL);
+        // Optionally, you could deselect this stream instead of failing.
+      }
+
+      // Return IMFActivate pointer to caller.
+      return pActivate;
+    }
+
+    // Add a source node to a topology.
+    IMFTopologyNodePtr AddSourceNode(
+      IMFTopologyPtr pTopology,           // Topology.
+      IMFMediaSourcePtr pSource,          // Media source.
+      IMFPresentationDescriptorPtr pPD,   // Presentation descriptor.
+      IMFStreamDescriptorPtr pSD)         // Stream descriptor.
+    {
+      IMFTopologyNodePtr pNode;
+
+      // Create the node.
+      THROW_IF_ERR(MFCreateTopologyNode(MF_TOPOLOGY_SOURCESTREAM_NODE, pNode.GetAddressOf()));
+
+      // Set the attributes.
+      THROW_IF_ERR(pNode->SetUnknown(MF_TOPONODE_SOURCE, pSource.Get()));
+
+      THROW_IF_ERR(pNode->SetUnknown(MF_TOPONODE_PRESENTATION_DESCRIPTOR, pPD.Get()));
+
+      THROW_IF_ERR(pNode->SetUnknown(MF_TOPONODE_STREAM_DESCRIPTOR, pSD.Get()));
+
+      // Add the node to the topology.
+      THROW_IF_ERR(pTopology->AddNode(pNode.Get()));
+
+      // Return the pointer to the caller.
+      return pNode;
+    }
+
+    // Add an output node to a topology.
+    IMFTopologyNodePtr AddOutputNode(
+      IMFTopologyPtr pTopology,     // Topology.
+      IMFActivatePtr pActivate,     // Media sink activation object.
+      DWORD dwId                 // Identifier of the stream sink.
+      ) 
+    {
+      IMFTopologyNodePtr pNode;
+
+      // Create the node.
+      THROW_IF_ERR(MFCreateTopologyNode(MF_TOPOLOGY_OUTPUT_NODE, &pNode));
+
+      // Set the object pointer.
+      THROW_IF_ERR(pNode->SetObject(pActivate.Get()));
+
+      // Set the stream sink ID attribute.
+      THROW_IF_ERR(pNode->SetUINT32(MF_TOPONODE_STREAMID, dwId));
+
+      THROW_IF_ERR(pNode->SetUINT32(MF_TOPONODE_NOSHUTDOWN_ON_REMOVE, FALSE));
+
+      // Add the node to the topology.
+      THROW_IF_ERR(pTopology->AddNode(pNode.Get()));
+
+      return pNode;
+
+    }
+    //</SnippetPlayer.cpp>
+
+    //  Add a topology branch for one stream.
+    //
+    //  For each stream, this function does the following:
+    //
+    //    1. Creates a source node associated with the stream. 
+    //    2. Creates an output node for the renderer. 
+    //    3. Connects the two nodes.
+    //
+    //  The media session will add any decoders that are needed.
+
+    void AddBranchToPartialTopology(
+      IMFTopologyPtr pTopology,         // Topology.
+      IMFMediaSourcePtr pSource,        // Media source.
+      IMFPresentationDescriptorPtr pPD, // Presentation descriptor.
+      DWORD iStream,                  // Stream index.
+      HWND hVideoWnd)                 // Window for video playback.
+    {
+      IMFStreamDescriptorPtr pSD;
+      IMFActivatePtr         pSinkActivate;
+      IMFTopologyNodePtr     pSourceNode;
+      IMFTopologyNodePtr     pOutputNode;
+
+      BOOL fSelected = FALSE;
+
+      THROW_IF_ERR(pPD->GetStreamDescriptorByIndex(iStream, &fSelected, &pSD));
+
+      if (fSelected)
+      {
+        // Create the media sink activation object.
+        pSinkActivate = CreateMediaSinkActivate(pSD.Get(), hVideoWnd);
+
+        // Add a source node for this stream.
+        pSourceNode = AddSourceNode(pTopology, pSource, pPD, pSD);
+
+        // Create the output node for the renderer.
+        pOutputNode = AddOutputNode(pTopology, pSinkActivate, 0);
+
+        // Connect the source node to the output node.
+        THROW_IF_ERR(pSourceNode->ConnectOutput(0, pOutputNode.Get(), 0));
+      }
+      // else: If not selected, don't add the branch. 
+    }
+
+    //  Create a playback topology from a media source.
+    // Receives a pointer to the topology.
+    IMFTopologyPtr CreatePlaybackTopology(
+      IMFMediaSourcePtr pSource,          // Media source.
+      IMFPresentationDescriptorPtr pPD,   // Presentation descriptor.
+      HWND hVideoWnd                   // Video window.
+      )        
+    {
+      IMFTopologyPtr pTopology;
+      DWORD cSourceStreams = 0;
+
+      // Create a new topology.
+      THROW_IF_ERR(MFCreateTopology(&pTopology));
+
+      // Get the number of streams in the media source.
+      THROW_IF_ERR(pPD->GetStreamDescriptorCount(&cSourceStreams));
+
+      // For each stream, create the topology nodes and add them to the topology.
+      for (DWORD i = 0; i < cSourceStreams; i++)
+      {
+        AddBranchToPartialTopology(pTopology, pSource, pPD, i, hVideoWnd);
+      }
+
+      // Return the IMFTopology pointer to the caller.
+      return pTopology;
+    }
+  }
+}
\ No newline at end of file
diff --git a/mfsample/player.h b/mfsample/player.h
new file mode 100644 (file)
index 0000000..6bf1051
--- /dev/null
@@ -0,0 +1,248 @@
+\r
+\r
+#ifndef PLAYER_H\r
+#define PLAYER_H\r
+\r
+#include <new>\r
+#include <windows.h>\r
+#include <shobjidl.h> \r
+#include <shlwapi.h>\r
+#include <assert.h>\r
+#include <strsafe.h>\r
+\r
+// Media Foundation headers\r
+#include <mfapi.h>\r
+#include <mfidl.h>\r
+#include <mferror.h>\r
+#include <evr.h>\r
+\r
+#include "resource.h"\r
+\r
+#include <boost/msm/back/state_machine.hpp>\r
+#include <boost/msm/front/state_machine_def.hpp>\r
+\r
+_WRL_PTR_TYPEDEF(IMFMediaSession);\r
+_WRL_PTR_TYPEDEF(IMFMediaSource);\r
+_WRL_PTR_TYPEDEF(IMFVideoDisplayControl);\r
+_WRL_PTR_TYPEDEF(IMFTopology);\r
+_WRL_PTR_TYPEDEF(IMFPresentationDescriptor);\r
+_WRL_PTR_TYPEDEF(IMFMediaEvent);\r
+_WRL_PTR_TYPEDEF(IMFSourceResolver);\r
+_WRL_PTR_TYPEDEF(IMFStreamDescriptor);\r
+_WRL_PTR_TYPEDEF(IMFTopologyNode);\r
+_WRL_PTR_TYPEDEF(IMFActivate);\r
+_WRL_PTR_TYPEDEF(IMFMediaTypeHandler);\r
+//_WRL_PTR_TYPEDEF();\r
+//_WRL_PTR_TYPEDEF();\r
+\r
+namespace sf {\r
+  namespace player {\r
+    namespace msmf = boost::msm::front;\r
+\r
+    // const UINT WM_APP_PLAYER_EVENT = WM_APP + 1;   \r
+    // WPARAM = IMFMediaEvent*, WPARAM = MediaEventType\r
+\r
+    enum struct PlayerState\r
+    {\r
+        Closed = 0,     // No session.\r
+        Ready,          // Session was created, ready to open a file. \r
+        OpenPending,    // Session is opening a file.\r
+        Started,        // Session is playing a file.\r
+        Paused,         // Session is paused.\r
+        Stopped,        // Session is stopped (ready to play). \r
+        Closing         // Application has closed the session, but is waiting for MESessionClosed.\r
+    };\r
+\r
+    // \8fó\91Ô\83N\83\89\83X\92è\8b`\r
+    struct Closed : msmf::state<> {}; // \83Z\83b\83V\83\87\83\93\82È\82µ\r
+    struct Ready : msmf::state<> {}; // \83Z\83b\83V\83\87\83\93\82ª\8dì\90¬\82³\82ê\81A\83t\83@\83C\83\8b\82ð\8aJ\82­\8f\80\94õ\82ª\82Å\82«\82Ä\82¢\82é\81B\r
+    struct OpenPending :msmf::state<> {};// \83Z\83b\83V\83\87\83\93\82Í\83t\83@\83C\83\8b\82ð\83I\81[\83v\83\93\82µ\82Ä\82¢\82é\r
+    struct Started : msmf::state<> {};// \83Z\83b\83V\83\87\83\93\82Í\89\89\91t\82µ\82Ä\82¢\82é\81B\r
+    struct Paused : msmf::state<> {};// \83Z\83b\83V\83\87\83\93\82Í\88ê\8e\9e\92â\8e~\82µ\82Ä\82¢\82é\81B\r
+    struct Stopped : msmf::state<> {};// \83Z\83b\83V\83\87\83\93\82Í\92â\8e~\82µ\82Ä\82¢\82é\81i\89\89\91t\89Â\94\\8fó\91Ô\82Å\82 \82é\81j\81B\r
+    struct Closing : msmf::state<> {};// \83A\83v\83\8a\83P\81[\83V\83\87\83\93\82Í\83Z\83b\83V\83\87\83\93\82ð\95Â\82\82½\82ª\81AMESessionClosed\8fó\91Ô\82ð\91Ò\82Á\82Ä\82¢\82é\81B\r
+\r
+    // \83v\83\8d\83p\83e\83B\97p\83o\83\8a\83A\83\93\83g\82Ì\83\89\83b\83p\r
+    struct prop_variant \r
+    {\r
+      prop_variant()\r
+      {\r
+        PropVariantInit(&value_);// \r
+      }\r
+\r
+      ~prop_variant()\r
+      {\r
+        PropVariantClear(&value_);\r
+      }\r
+\r
+      PROPVARIANT* get(){ return &value_;};\r
+\r
+      PROPVARIANT* operator &(){return get();}\r
+\r
+      operator PROPVARIANT*() {return get();}\r
+\r
+    private:\r
+      PROPVARIANT value_;\r
+    };\r
+\r
+\r
+    namespace ev \r
+    {\r
+      struct Init {}; // \8f\89\8aú\89»\83C\83x\83\93\83g\r
+      struct OpenURL  // \83t\83@\83C\83\8b\82ð\8aJ\82­\83C\83x\83\93\83g\r
+      {\r
+        OpenURL() {};\r
+        OpenURL(const OpenURL& s) : url_(s.url()) {}\r
+        explicit OpenURL(const std::wstring& u) : url_(u) {}\r
+        const std::wstring& url() const {return url_;}\r
+      private:\r
+        std::wstring url_;\r
+      };\r
+      struct OpenComplete {};// \83t\83@\83C\83\8b\83I\81[\83v\83\93\8a®\97¹\r
+      struct Play {};// \89\89\91t\8aJ\8en\r
+      struct End {};// \8fI\97¹\r
+      struct Pause {};// \88ê\8e\9e\92â\8e~\r
+      struct Stop {};// \92â\8e~\r
+      struct Close {};// \95Â\82\82é\r
+    }\r
+\r
+    struct Player_ : public IMFAsyncCallback,public boost::msm::front::state_machine_def<sf::player::Player_>\r
+    {\r
+      typedef boost::msm::back::state_machine< Player_ > this_type;\r
+      typedef Microsoft::WRL::ComPtr<this_type> ptr_type;\r
+      friend ptr_type CreatePlayer(HWND hVideo, HWND hEvent);\r
+      friend struct transition_table;\r
+      typedef boost::signals2::signal<void( this_type &)> signal_t;\r
+\r
+\r
+      // IUnknown methods\r
+      STDMETHODIMP QueryInterface(REFIID iid, void** ppv);\r
+      STDMETHODIMP_(ULONG) AddRef();\r
+      STDMETHODIMP_(ULONG) Release();\r
+\r
+      // IMFAsyncCallback methods\r
+      STDMETHODIMP  GetParameters(DWORD*, DWORD*)\r
+      {\r
+        // Implementation of this method is optional.\r
+        return E_NOTIMPL;\r
+      }\r
+      STDMETHODIMP  Invoke(IMFAsyncResult* pAsyncResult);\r
+\r
+      void       HandleEvent(UINT_PTR pUnkPtr);\r
+ //     PlayerState   GetState() const { return m_state; }\r
+\r
+      // Video functionality\r
+      void       Repaint();\r
+      void       ResizeVideo(WORD width, WORD height);\r
+\r
+      BOOL          HasVideo() const { return (m_pVideoDisplay != NULL);  }\r
+\r
+      signal_t& OnReady(){return OnReady_;}\r
+      signal_t& OnOpenURL() {return OnOpenURL_;}\r
+      signal_t& OnStart(){return OnStart_;}\r
+      signal_t& OnEnd(){return OnEnd_;}\r
+      signal_t& OnPause(){return OnPause_;}\r
+      signal_t& OnStop(){return OnStop_;}\r
+      signal_t& OnOpenComplete(){return OnOpenComplete_;}\r
+\r
+      void OpenComplete()\r
+      {\r
+        OnOpenComplete_(static_cast<this_type&>(*this));\r
+      }\r
+\r
+\r
+    protected:\r
+\r
+\r
+      // Constructor is private. Use static CreateInstance method to instantiate.\r
+      Player_(HWND hVideo, HWND hEvent);\r
+\r
+      // Destructor is private. Caller should call Release.\r
+      virtual ~Player_(); \r
+\r
+      void CreateSession();\r
+      void CloseSession();\r
+      void StartPlayback();\r
+\r
+      // Playback\r
+      void initialize( ev::Init const& ev);\r
+      void       open_url( ev::OpenURL const& openurl);\r
+      void       play( ev::Play const& ev);\r
+      void       pause( ev::Pause const& ev);\r
+      void       stop( ev::Stop const& ev);\r
+      void       shutdown( ev::Close const& ev);\r
+      void  open_complete(ev::OpenComplete const&)\r
+      {\r
+        OnOpenComplete()(static_cast<this_type&>(*this));\r
+      }\r
+\r
+      // Media event handlers\r
+      virtual void OnTopologyStatus(IMFMediaEventPtr pEvent);\r
+      virtual void OnPresentationEnded(IMFMediaEventPtr pEvent);\r
+      virtual void OnNewPresentation(IMFMediaEventPtr pEvent);\r
+\r
+      // Override to handle additional session events.\r
+      virtual void OnSessionEvent(IMFMediaEventPtr, MediaEventType) \r
+      { \r
+        //return S_OK; \r
+      }\r
+\r
+\r
+      long                    m_nRefCount;        // Reference count.\r
+\r
+      IMFMediaSessionPtr         m_pSession;\r
+      IMFMediaSourcePtr          m_pSource;\r
+      IMFVideoDisplayControlPtr  m_pVideoDisplay;\r
+\r
+      HWND                    m_hwndVideo;        // Video window.\r
+      HWND                    m_hwndEvent;        // App window to receive events.\r
+     // PlayerState             m_state;            // Current state of the media session.\r
+      HANDLE                  m_hCloseEvent;      // Event to wait on while closing.\r
+\r
+    private:\r
+\r
+      // \8aO\95\94\82É\83C\83x\83\93\83g\82ð\94ò\82Î\82·\82½\82ß\82Ì\83V\83O\83i\83\8b\r
+      signal_t OnReady_;\r
+      signal_t OnOpenURL_;\r
+      signal_t OnOpenComplete_;\r
+      signal_t OnStart_;\r
+      signal_t OnEnd_;\r
+      signal_t OnPause_;\r
+      signal_t OnStop_;\r
+\r
+    public:\r
+// \8fó\91Ô\91J\88Ú\83e\81[\83u\83\8b\r
+struct transition_table : boost::mpl::vector\r
+  //            \8c»\8dÝ\8fó\91Ô      ,\83C\83x\83\93\83g           , \8e\9f\82Ì\8fó\91Ô      , \83A\83N\83V\83\87\83\93               , \83K\81[\83\r
+  < a_row       <Closed        ,ev::Init          ,Ready          ,&sf::player::Player_::initialize      >,\r
+    a_row       <Ready         ,ev::OpenURL       ,OpenPending    ,&sf::player::Player_::open_url         >,\r
+    a_row        <OpenPending   ,ev::OpenComplete  ,Stopped        ,&sf::player::Player_::open_complete>,\r
+    a_row       <Started       ,ev::Pause         ,Paused         ,&sf::player::Player_::pause           >,\r
+    a_row       <Started       ,ev::Stop          ,Stopped        ,&sf::player::Player_::stop            >,\r
+    _row        <Started       ,ev::End           ,Stopped        >,\r
+    a_row       <Paused        ,ev::Play          ,Started        ,&sf::player::Player_::play            >,\r
+    a_row       <Paused        ,ev::Stop          ,Stopped        ,&sf::player::Player_::stop            >,\r
+    a_row       <Stopped       ,ev::Play          ,Started        ,&sf::player::Player_::play            >,\r
+    a_row       <Stopped       ,ev::OpenURL       ,OpenPending    ,&sf::player::Player_::open_url        >//,\r
+ //   a_row       <msmf::none    ,ev::Close         ,Closed         ,&Player_::shutdown>\r
+  >\r
+{};\r
+      typedef Closed initial_state;\r
+\r
+\r
+      template <class FSM,class Event>\r
+      void no_transition(Event const& e, FSM&,int state)\r
+      {\r
+        throw exception(L"No Transition");\r
+      }\r
+\r
+    };\r
+\r
+    typedef boost::msm::back::state_machine< Player_ > Player;\r
+\r
+    typedef Microsoft::WRL::ComPtr<Player> PlayerPtr;\r
+    PlayerPtr CreatePlayer(HWND hVideo, HWND hEvent);\r
+\r
+  }\r
+}\r
+#endif PLAYER_H\r
diff --git a/mfsample/player.rc b/mfsample/player.rc
new file mode 100644 (file)
index 0000000..eb444b0
--- /dev/null
@@ -0,0 +1,54 @@
+
+// Microsoft Visual C++ generated resource script.
+//
+#include "resource.h"
+
+#include "windows.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// English (U.S.) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+#ifdef _WIN32
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+#pragma code_page(1252)
+#endif //_WIN32
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Menu
+//
+
+IDC_MFPLAYBACK MENU 
+BEGIN
+    POPUP "&File"
+    BEGIN
+        MENUITEM "&Open File",                  ID_FILE_OPENFILE
+        MENUITEM "Open &Url",                   ID_FILE_OPENURL
+        MENUITEM SEPARATOR
+        MENUITEM "E&xit",                       IDM_EXIT
+    END
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+IDD_OPENURL DIALOGEX 0, 0, 186, 90
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Open URL"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+    DEFPUSHBUTTON   "OK",IDOK,75,69,50,14
+    PUSHBUTTON      "Cancel",IDCANCEL,129,69,50,14
+    EDITTEXT        IDC_EDIT_URL,7,21,172,14,ES_AUTOHSCROLL
+    LTEXT           "Enter the URL to open:",IDC_STATIC,7,7,104,8
+END
+
+#endif    // English (U.S.) resources
+/////////////////////////////////////////////////////////////////////////////
diff --git a/mfsample/resource.h b/mfsample/resource.h
new file mode 100644 (file)
index 0000000..82d0c61
--- /dev/null
@@ -0,0 +1,46 @@
+#ifndef IDC_STATIC
+#define IDC_STATIC (-1)
+#endif
+
+#define IDI_ICON1                               100
+#define IDD_MAINDIALOG                          102
+#define IDD_INFO                                104
+#define IDD_CONFIG                              106
+#define IDD_SEQ                                 108
+#define IDC_EDIT1                               1000
+#define IDC_FILE                                1000
+#define IDC_MIN_MAX_LATENCY                     1000
+#define IDC_VIDEO                               1000
+#define IDC_LATENCY                             1001
+#define IDC_SCROLLBAR1                          1001
+#define IDC_SLIDER                              1001
+#define IDC_CHANNEL                             1002
+#define IDC_EDIT2                               1002
+#define IDC_WAVEFORM                            1002
+#define IDC_APPLY                               1003
+#define IDC_EDIT3                               1003
+#define IDC_INFO                                1003
+#define IDC_EDIT4                               1004
+#define IDC_INPUT_CHANNEL                       1004
+#define IDC_EVENT_MODE                          1005
+#define IDC_PLAY                                1005
+#define IDC_SEQ_AREA                            1005
+#define IDC_REPEAT_CHECK                        1006
+#define IDC_PAUSE                               1007
+#define IDC_EXC_MODE                            1008
+#define IDC_STOP                                1009
+#define IDC_TAB                                 1011
+#define IDC_ENDPOINT_DEVICE                     1017
+#define IDC_SAMPLE_BIT                          1018
+#define IDC_VALID_SAMPLE_BITS                   1019
+#define IDC_SAMPLE_RATE                         1020
+#define IDC_CANCEL                              40000
+#define IDS_STRING1                             40000
+#define IDC_INPUT_ENDPOINT_DEVICE               40010
+#define IDC_INPUT_SAMPLE_BIT                    40011
+#define IDC_INPUT_VALID_SAMPLE_BITS             40012
+#define IDC_INPUT_EXC_MODE                      40014
+#define IDC_INPUT_EVENT_MODE                    40015
+#define IDC_INPUT_SAMPLE_RATE                   40017
+#define IDC_INPUT_LATENCY                       40018
+#define IDC_INPUT_MIN_MAX_LATENCY               40019
diff --git a/mfsample/sf_com.cpp b/mfsample/sf_com.cpp
new file mode 100644 (file)
index 0000000..f547713
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+  ==============================================================================
+
+   This file is part of the S.F.Tracker
+   Copyright 2005-7 by Satoshi Fujiwara.
+
+   S.F.Tracker can be redistributed and/or modified under the terms of the
+   GNU General Public License, as published by the Free Software Foundation;
+   either version 2 of the License, or (at your option) any later version.
+
+   S.F.Tracker is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with S.F.Tracker; if not, visit www.gnu.org/licenses or write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
+   Boston, MA 02111-1307 USA
+
+  ==============================================================================
+*/
+/** @file
+ *  @brief util
+ *  @author S.F. (Satoshi Fujiwara)
+ */
+
+#include "stdafx.h"
+#include <objbase.h>
+#include "sf_com.h"
+namespace sf {
+
+    struct com_initialize::impl
+    {
+               impl(void * reserved,unsigned int init) : hr(::CoInitializeEx(reserved,init))
+        {
+        }
+
+        ~impl()
+        {
+                       if(hr == S_OK){
+                   ::CoUninitialize();
+                       }
+        }
+       private:
+               HRESULT hr;
+    };
+
+    com_initialize::com_initialize(void * reserved,unsigned int  init)
+        : m_impl(new com_initialize::impl(reserved,init))
+    {
+    };
+
+       //template <typename ComClass,typename ComInterface> boost::intrusive_ptr<ComInterface> com_creator<ComClass,ComInterface>::create_instance()
+       //{
+       //      ComClass * com_ptr;
+       //      CoCreateInstance( __uuidof(ComClass), NULL,
+       //                       CLSCTX_ALL, __uuidof(ComInterface),
+       //                       (void**)&com_ptr);
+       //      return instrusive_ptr<ComClass>(com_ptr,false);
+       //};
+
+
+}
\ No newline at end of file
diff --git a/mfsample/sf_com.h b/mfsample/sf_com.h
new file mode 100644 (file)
index 0000000..5fc12d5
--- /dev/null
@@ -0,0 +1,111 @@
+#pragma once
+/*
+  ==============================================================================
+
+   This file is part of the mfsample
+   Copyright 2005-11 by Satoshi Fujiwara.
+
+   mfsample can be redistributed and/or modified under the terms of the
+   GNU General Public License, as published by the Free Software Foundation;
+   either version 2 of the License, or (at your option) any later version.
+
+   async is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with async; if not, visit www.gnu.org/licenses or write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
+   Boston, MA 02111-1307 USA
+
+  ==============================================================================
+*/
+/** @file
+ *  @brief util
+ *  @author S.F. (Satoshi Fujiwara)
+ */
+#include "objbase.h"
+
+
+
+namespace sf 
+{
+  template <class COM_SMART_PTR > inline void safe_release(COM_SMART_PTR& ptr)
+  {
+    if(ptr)
+    {
+      ptr.Reset();
+    }
+  };
+    enum com_init 
+    {
+        multi_threaded  = 0x0,
+        apartment_threaded = 0x2,
+        disable_ole1dde   = 0x4,
+        speed_over_memory = 0x8
+    };
+
+    struct com_initialize
+    {
+        struct impl;
+        com_initialize(void * reserved ,unsigned int init);
+        com_initialize(){com_initialize(0,multi_threaded);};
+        ~com_initialize() {};
+    private:
+        std::shared_ptr<impl> m_impl;
+    };
+
+       template <typename ComClass,typename ComInterface> 
+                 boost::intrusive_ptr<ComInterface> create_instance()
+                 {
+                       ComInterface * com_ptr;
+                       CoCreateInstance( __uuidof(ComClass), NULL,
+                                        CLSCTX_ALL, __uuidof(ComInterface),
+                                        (void**)&com_ptr);
+                       return boost::intrusive_ptr<ComInterface>(com_ptr,false);
+
+                 };
+                       template <typename COMInterface> 
+               struct IUnknownImpl : public COMInterface 
+               {
+                       IUnknownImpl() : ref_(1) {}; 
+                       virtual ~IUnknownImpl() {};
+                       ULONG __stdcall AddRef()
+                       {
+                               return InterlockedIncrement(&ref_);
+                       }
+
+                       ULONG __stdcall Release()
+                       {
+                               ULONG ref = InterlockedDecrement(&ref_);
+                               if (0 == ref)
+                               {
+                                       delete this;
+                               }
+                               return ref;
+                       }
+
+                       HRESULT __stdcall QueryInterface(REFIID riid, VOID **ppObj)
+                       {
+                               if (IID_IUnknown == riid)
+                               {
+                                       AddRef();
+                                       *ppObj = (IUnknown*)this;
+                               }
+                               else if (__uuidof(COMInterface) == riid)
+                               {
+                                       AddRef();
+                                       *ppObj = (COMInterface*)this;
+                               }
+                               else
+                               {
+                                       *ppObj = NULL;
+                                       return E_NOINTERFACE;
+                               }
+                               return S_OK;
+                       }
+               private:
+                       LONG ref_;
+               };
+}
\ No newline at end of file
diff --git a/mfsample/sf_memory.h b/mfsample/sf_memory.h
new file mode 100644 (file)
index 0000000..3bca7f5
--- /dev/null
@@ -0,0 +1,115 @@
+#pragma once
+namespace sf {
+// policy class
+struct heap_memory_free_policy
+{
+template< typename T >
+void operator()( const T* AMemory ) const
+{
+if( NULL != AMemory )
+::HeapFree( ::GetProcessHeap(), 0, AMemory );
+}
+};
+// policy class
+struct local_memory_free_policy
+{
+template< typename T >
+void operator()( const T* AMemory ) const
+{
+if( NULL != AMemory )
+::LocalFree( AMemory );
+}
+};
+// policy class
+struct co_task_memory_free_policy
+{
+template< typename T >
+void operator()( const T* AMemory ) const
+{
+if( NULL != AMemory )
+::CoTaskMemFree( AMemory );
+}
+};
+// base guard class
+template< typename T,class TFreePolicy >
+class base_memory
+{
+private:
+T *FMemory;
+
+public:
+base_memory( T* AMemory = NULL )
+: FMemory( AMemory ) {}
+
+virtual ~base_memory( void )
+{ reset(); }
+
+T* release( void )
+{
+T *tmp = FMemory;
+FMemory = NULL;
+return tmp;
+}
+
+void reset( T* AMemory = NULL )
+{
+if( AMemory != FMemory )
+{
+if( NULL != FMemory )
+TFreePolicy( FMemory );
+
+FMemory = AMemory;
+}
+}
+
+T* get( void )
+{ return FMemory; }
+
+T* operator ->(void)
+{
+  return FMemory;
+}
+
+T** operator&( void )
+{ return &FMemory; }
+
+};
+template< typename T >
+class heap_memory : public base_memory< T, 
+heap_memory_free_policy >
+{
+public:
+heap_memory( T* AMemory = NULL )
+: base_memory< T, heap_memory_free_policy >( AMemory )
+{ }
+};
+template< typename T >
+class local_memory : public base_memory< T, 
+local_memory_free_policy >
+{
+public:
+local_memory( T* AMemory = NULL )
+: base_memory< T, local_memory_free_policy >( AMemory )
+{ }
+};
+template< typename T >
+class co_task_memory : public base_memory< T, co_task_memory_free_policy >
+{
+public:
+co_task_memory( T* AMemory = NULL )
+: base_memory< T, co_task_memory_free_policy >( AMemory )
+{ }
+};
+
+struct handle_deleter {
+  typedef HANDLE pointer;
+  void operator ()(HANDLE handle) {
+      if (handle != INVALID_HANDLE_VALUE) {
+          CloseHandle(handle);
+      }
+  }
+};
+
+typedef std::unique_ptr<HANDLE,handle_deleter> handle_holder;
+
+};
diff --git a/mfsample/sf_windows.cpp b/mfsample/sf_windows.cpp
new file mode 100644 (file)
index 0000000..4ea1a16
--- /dev/null
@@ -0,0 +1,1220 @@
+#include "stdafx.h"\r
+#define BOOST_ASSIGN_MAX_PARAMS 7\r
+#include <boost/assign.hpp>\r
+#include <boost/assign/ptr_list_of.hpp>\r
+#include <boost/assign/ptr_list_inserter.hpp>\r
+#include <boost/foreach.hpp>\r
+\r
+#if _DEBUG\r
+#define _CRTDBG_MAP_ALLOC\r
+#include <crtdbg.h>\r
+#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)\r
+#endif\r
+\r
+#include "sf_windows.h"\r
+#include "exception.h"\r
+\r
+//#pragma comment(lib,"dxerr.lib")\r
+#pragma comment( lib, "dxguid.lib" )\r
+#pragma comment( lib, "d3d11.lib" )\r
+#pragma comment( lib, "D3DCompiler.lib" )\r
+#pragma comment( lib, "DirectXTK.lib" )\r
+#pragma comment( lib, "dxgi.lib" )\r
+//#pragma comment( lib, "d3dx9.lib" )   \r
+#pragma comment( lib, "Shlwapi.lib" ) \r
+#pragma comment( lib, "DWMApi.lib" )\r
+#pragma comment( lib,"msimg32.lib")\r
+\r
+#define THROW_IFERR(hres) \\r
+  if (FAILED(hres)) { throw sf::win32_error_exception(hres); }\r
+\r
+#ifndef HINST_THISCOMPONENT\r
+EXTERN_C IMAGE_DOS_HEADER __ImageBase;\r
+#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase)\r
+#endif\r
+using namespace std;\r
+using namespace DirectX;\r
+\r
+namespace sf \r
+{\r
+  HRESULT EnableBlurBehind(HWND hwnd)\r
+  {\r
+    HRESULT hr = S_OK;\r
+\r
+    //Create and populate the BlurBehind structre\r
+    DWM_BLURBEHIND bb = {0};\r
+    //Enable Blur Behind and Blur Region;\r
+    bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION;\r
+    bb.fEnable = true;\r
+    bb.hRgnBlur = ::CreateRectRgn(-1,-1,0,0);\r
+\r
+    //Enable Blur Behind\r
+    hr = DwmEnableBlurBehindWindow(hwnd, &bb);\r
+    //BOOL allow_ncpaint = TRUE;\r
+    //DwmSetWindowAttribute(hwnd,DWMWA_ALLOW_NCPAINT,&allow_ncpaint,sizeof(BOOL));\r
+    //DWMNCRENDERINGPOLICY policy = DWMNCRP_ENABLED;\r
+    //DwmSetWindowAttribute(hwnd,DWMWA_NCRENDERING_POLICY,&policy,sizeof(policy));\r
+\r
+    \r
+    //if (SUCCEEDED(hr))\r
+    //{\r
+    //  //do more things\r
+    //MARGINS mgn = {-1};\r
+    //hr = DwmExtendFrameIntoClientArea( hwnd, &mgn );\r
+    /*   }*/\r
+    return hr;\r
+  }\r
+\r
+  // 汎用情報格納用\r
+  struct mode_info \r
+  {\r
+    mode_info(const std::wstring& n,const std::wstring& d) : name(n),description(d) {}\r
+    std::wstring name;\r
+    std::wstring description;\r
+  };\r
+\r
+  // ディスプレイモード\r
+  struct display_mode \r
+  {\r
+    display_mode(const std::wstring& n,const std::wstring& d) : name(n),description(d) {}\r
+    std::wstring name;\r
+    std::wstring description;\r
+  };\r
+\r
+  std::vector<mode_info> display_modes = \r
+    boost::assign::list_of<mode_info>\r
+    (L"DXGI_FORMAT_UNKNOWN",L"フォーマットが不明")\r
+    (L"DXGI_FORMAT_R32G32B32A32_TYPELESS",L"4 成分、128 ビット型なしフォーマット 1")\r
+    (L"DXGI_FORMAT_R32G32B32A32_FLOAT",L"4 成分、128 ビット浮動小数点フォーマット 1")\r
+    (L"DXGI_FORMAT_R32G32B32A32_UINT",L"4 成分、128 ビット符号なし整数フォーマット 1")\r
+    (L"DXGI_FORMAT_R32G32B32A32_SINT",L"4 成分、128 ビット符号付き整数フォーマット 1")\r
+    (L"DXGI_FORMAT_R32G32B32_TYPELESS",L"3 成分、96 ビット型なしフォーマット")\r
+    (L"DXGI_FORMAT_R32G32B32_FLOAT",L"3 成分、96 ビット浮動小数点フォーマット")\r
+    (L"DXGI_FORMAT_R32G32B32_UINT",L"3 成分、96 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R32G32B32_SINT",L"3 成分、96 ビット符号付き整数フォーマット")\r
+    (L"DXGI_FORMAT_R16G16B16A16_TYPELESS",L"4 成分、64 ビット型なしフォーマット")\r
+    (L"DXGI_FORMAT_R16G16B16A16_FLOAT",L"4 成分、64 ビット浮動小数点フォーマット")\r
+    (L"DXGI_FORMAT_R16G16B16A16_UNORM",L"4 成分、64 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R16G16B16A16_UINT",L"4 成分、64 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R16G16B16A16_SNORM",L"4 成分、64 ビット符号付き整数フォーマット")\r
+    (L"DXGI_FORMAT_R16G16B16A16_SINT",L"4 成分、64 ビット符号付き整数フォーマット")\r
+    (L"DXGI_FORMAT_R32G32_TYPELESS",L"2 成分、64 ビット型なしフォーマット")\r
+    (L"DXGI_FORMAT_R32G32_FLOAT",L"2 成分、64 ビット浮動小数点フォーマット")\r
+    (L"DXGI_FORMAT_R32G32_UINT",L"2 成分、64 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R32G32_SINT",L"2 成分、64 ビット符号付き整数フォーマット")\r
+    (L"DXGI_FORMAT_R32G8X24_TYPELESS",L"2 成分、64 ビット型なしフォーマット")\r
+    (L"DXGI_FORMAT_D32_FLOAT_S8X24_UINT",L"32 ビット浮動小数点成分、および 2 つの符号なし整数成分です (追加の 32 ビットを含む)。")\r
+    (L"DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS",L"32 ビット浮動小数点成分、および 2 つの型なし成分です (追加の 32 ビットを含む)。")\r
+    (L"DXGI_FORMAT_X32_TYPELESS_G8X24_UINT",L"32 ビット型なし成分、および 2 つの符号なし整数成分です (追加の 32 ビットを含む)。")\r
+    (L"DXGI_FORMAT_R10G10B10A2_TYPELESS",L"4 成分、32 ビット型なしフォーマット")\r
+    (L"DXGI_FORMAT_R10G10B10A2_UNORM",L"4 成分、32 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R10G10B10A2_UINT",L"4 成分、32 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R11G11B10_FLOAT",L"3 成分、32 ビット浮動小数点フォーマット")\r
+    (L"DXGI_FORMAT_R8G8B8A8_TYPELESS",L"3 成分、32 ビット型なしフォーマット")\r
+    (L"DXGI_FORMAT_R8G8B8A8_UNORM",L"4 成分、32 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R8G8B8A8_UNORM_SRGB",L"4 成分、32 ビット符号なし正規化整数 sRGB フォーマット")\r
+    (L"DXGI_FORMAT_R8G8B8A8_UINT",L"4 成分、32 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R8G8B8A8_SNORM",L"3 成分、32 ビット符号付き整数フォーマット")\r
+    (L"DXGI_FORMAT_R8G8B8A8_SINT",L"3 成分、32 ビット符号付き整数フォーマット")\r
+    (L"DXGI_FORMAT_R16G16_TYPELESS",L"2 成分、32 ビット型なしフォーマット")\r
+    (L"DXGI_FORMAT_R16G16_FLOAT",L"2 成分、32 ビット浮動小数点フォーマット")\r
+    (L"DXGI_FORMAT_R16G16_UNORM",L"2 成分、32 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R16G16_UINT",L"2 成分、32 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R16G16_SNORM",L"2 成分、32 ビット符号付き整数フォーマット")\r
+    (L"DXGI_FORMAT_R16G16_SINT",L"2 成分、32 ビット符号付き整数フォーマット")\r
+    (L"DXGI_FORMAT_R32_TYPELESS",L"1 成分、32 ビット型なしフォーマット")\r
+    (L"DXGI_FORMAT_D32_FLOAT",L"1 成分、32 ビット浮動小数点フォーマット")\r
+    (L"DXGI_FORMAT_R32_FLOAT",L"1 成分、32 ビット浮動小数点フォーマット")\r
+    (L"DXGI_FORMAT_R32_UINT",L"1 成分、32 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R32_SINT",L"1 成分、32 ビット符号付き整数フォーマット")\r
+    (L"DXGI_FORMAT_R24G8_TYPELESS",L"2 成分、32 ビット型なしフォーマット")\r
+    (L"DXGI_FORMAT_D24_UNORM_S8_UINT",L"深度チャンネルに 24 ビット、ステンシル チャンネルに 8 ビットを使用する 32 ビット Z バッファー フォーマット")\r
+    (L"DXGI_FORMAT_R24_UNORM_X8_TYPELESS",L"1 成分、24 ビット符号なし正規化整数と追加の型なし 8 ビットを含む、32 ビット フォーマット")\r
+    (L"DXGI_FORMAT_X24_TYPELESS_G8_UINT",L"1 成分、24 ビット型なしフォーマットと追加の 8 ビット符号なし整数成分を含む、32 ビット フォーマット")\r
+    (L"DXGI_FORMAT_R8G8_TYPELESS",L"2 成分、16 ビット型なしフォーマット")\r
+    (L"DXGI_FORMAT_R8G8_UNORM",L"2 成分、16 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R8G8_UINT",L"2 成分、16 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R8G8_SNORM",L"2 成分、16 ビット符号付き整数フォーマット")\r
+    (L"DXGI_FORMAT_R8G8_SINT",L"2 成分、16 ビット符号付き整数フォーマット")\r
+    (L"DXGI_FORMAT_R16_TYPELESS",L"1 成分、16 ビット型なしフォーマット")\r
+    (L"DXGI_FORMAT_R16_FLOAT",L"1 成分、16 ビット浮動小数点フォーマット")\r
+    (L"DXGI_FORMAT_D16_UNORM",L"1 成分、16 ビット符号なし正規化整数フォーマット")\r
+    (L"DXGI_FORMAT_R16_UNORM",L"1 成分、16 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R16_UINT",L"1 成分、16 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R16_SNORM",L"1 成分、16 ビット符号付き整数フォーマット")\r
+    (L"DXGI_FORMAT_R16_SINT",L"1 成分、16 ビット符号付き整数フォーマット")\r
+    (L"DXGI_FORMAT_R8_TYPELESS",L"1 成分、8 ビット型なしフォーマット")\r
+    (L"DXGI_FORMAT_R8_UNORM",L"1 成分、8 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R8_UINT",L"1 成分、8 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R8_SNORM",L"1 成分、8 ビット符号付き整数フォーマット")\r
+    (L"DXGI_FORMAT_R8_SINT",L"1 成分、8 ビット符号付き整数フォーマット")\r
+    (L"DXGI_FORMAT_A8_UNORM",L"1 成分、8 ビット符号なし整数フォーマット")\r
+    (L"DXGI_FORMAT_R1_UNORM",L"1 成分、1 ビット符号なし正規化整数フォーマット 2.")\r
+    (L"DXGI_FORMAT_R9G9B9E5_SHAREDEXP",L"4 成分、32 ビット浮動小数点フォーマット 2.")\r
+    (L"DXGI_FORMAT_R8G8_B8G8_UNORM",L"4 成分、32 ビット符号なし正規化整数フォーマット 3")\r
+    (L"DXGI_FORMAT_G8R8_G8B8_UNORM",L"4 成分、32 ビット符号なし正規化整数フォーマット 3")\r
+    (L"DXGI_FORMAT_BC1_TYPELESS",L"4 成分、型なしブロック圧縮フォーマット")\r
+    (L"DXGI_FORMAT_BC1_UNORM",L"4 成分、ブロック圧縮フォーマット")\r
+    (L"DXGI_FORMAT_BC1_UNORM_SRGB",L"sRGB データ用の 4 成分、ブロック圧縮フォーマット")\r
+    (L"DXGI_FORMAT_BC2_TYPELESS",L"4 成分、型なしブロック圧縮フォーマット")\r
+    (L"DXGI_FORMAT_BC2_UNORM",L"4 成分、ブロック圧縮フォーマット")\r
+    (L"DXGI_FORMAT_BC2_UNORM_SRGB",L"sRGB データ用の 4 成分、ブロック圧縮フォーマット")\r
+    (L"DXGI_FORMAT_BC3_TYPELESS",L"4 成分、型なしブロック圧縮フォーマット")\r
+    (L"DXGI_FORMAT_BC3_UNORM",L"4 成分、ブロック圧縮フォーマット")\r
+    (L"DXGI_FORMAT_BC3_UNORM_SRGB",L"sRGB データ用の 4 成分、ブロック圧縮フォーマット")\r
+    (L"DXGI_FORMAT_BC4_TYPELESS",L"1 成分、型なしブロック圧縮フォーマット")\r
+    (L"DXGI_FORMAT_BC4_UNORM",L"1 成分、ブロック圧縮フォーマット")\r
+    (L"DXGI_FORMAT_BC4_SNORM",L"1 成分、ブロック圧縮フォーマット")\r
+    (L"DXGI_FORMAT_BC5_TYPELESS",L"2 成分、型なしブロック圧縮フォーマット")\r
+    (L"DXGI_FORMAT_BC5_UNORM",L"2 成分、ブロック圧縮フォーマット")\r
+    (L"DXGI_FORMAT_BC5_SNORM",L"2 成分、ブロック圧縮フォーマット")\r
+    (L"DXGI_FORMAT_B5G6R5_UNORM",L"3 成分、16 ビット符号なし正規化整数フォーマット")\r
+    (L"DXGI_FORMAT_B5G5R5A1_UNORM",L"1 ビット アルファをサポートする 4 成分、16 ビット符号なし正規化整数フォーマット")\r
+    (L"DXGI_FORMAT_B8G8R8A8_UNORM",L"8 ビット アルファをサポートする 4 成分、16 ビット符号なし正規化整数フォーマット")\r
+    (L"DXGI_FORMAT_B8G8R8X8_UNORM",L"4 成分、16 ビット符号なし正規化整数フォーマット")\r
+    (L"DXGI_FORMAT_FORCE_UINT",L"コンパイル時に、この列挙型のサイズを 32 ビットにするために定義されています。この値を指定しない場合、一部のコンパイラでは列挙型を 32 ビット以外のサイズでコンパイル可能この定数が使用されることはありません。");\r
+\r
+  // スキャンライン情報\r
+\r
+  std::vector<mode_info> scanline_orders = \r
+    boost::assign::list_of<mode_info>\r
+    (L"DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED",L"走査線の順序が指定されていません。")\r
+    (L"DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE",L"イメージは先頭の走査線~最後の走査線から作成され、スキップされる走査線はありません。")\r
+    (L"DXGI_MODE_SCANLINE_ORDER_UPPER_FIELD_FIRST",L"イメージが上部のフィールドから作成されます。")\r
+    (L"DXGI_MODE_SCANLINE_ORDER_LOWER_FIELD_FIRST",L"イメージが下部のフィールドから作成されます。");\r
+\r
+  // スケーリングパラメータ\r
+  std::vector<mode_info> scalings = boost::assign::list_of<mode_info>\r
+    (L"DXGI_MODE_SCALING_UNSPECIFIED",L"スケーリングが指定されていません。")\r
+    (L"DXGI_MODE_SCALING_CENTERED",L"スケーリングなしを指定します。イメージはディスプレイの中央に配置されます。通常、このフラグは固定ドットピッチ ディスプレイ (LED ディスプレイなど) に使用します。")\r
+    (L"DXGI_MODE_SCALING_STRETCHED",L"拡大スケーリングを指定します。");\r
+\r
+  struct simple_vertex\r
+  {\r
+    XMFLOAT3 pos;\r
+    XMFLOAT3 norm;\r
+    XMFLOAT2 tex;\r
+  };\r
+\r
+  struct cb_never_changes\r
+  {\r
+    XMMATRIX mView;\r
+    XMFLOAT4 vLightDir;\r
+  };\r
+\r
+  struct cb_change_on_resize\r
+  {\r
+    XMMATRIX mProjection;\r
+  };\r
+\r
+  struct cb_changes_every_frame\r
+  {\r
+    XMMATRIX mWorld;\r
+    XMFLOAT4 vLightColor;\r
+\r
+    //    XMFLOAT4 vMeshColor;\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
+\r
+    switch (message)\r
+    {\r
+    case WM_NCCREATE:\r
+      return on_nccreate(reinterpret_cast<CREATESTRUCT*>(lParam));\r
+    case WM_CREATE:\r
+      return on_create(reinterpret_cast<CREATESTRUCT*>(lParam));\r
+    case WM_INITDIALOG:\r
+      return on_init_dialog(reinterpret_cast<HWND>(wParam),lParam);\r
+    case WM_SIZE:\r
+      return on_size(wParam,LOWORD(lParam),HIWORD(lParam)) ;\r
+    case WM_PAINT:\r
+      return on_paint();\r
+    case WM_DISPLAYCHANGE:\r
+      return on_display_change(wParam,LOWORD(lParam),HIWORD(lParam));\r
+    case WM_ERASEBKGND:\r
+      return on_erase_backgroud(reinterpret_cast<HDC>(wParam));\r
+    case WM_HSCROLL:\r
+      return on_hscroll(LOWORD(wParam),HIWORD(wParam),reinterpret_cast<HWND>(lParam));\r
+    case WM_VSCROLL:\r
+      return on_vscroll(LOWORD(wParam),HIWORD(wParam),reinterpret_cast<HWND>(lParam));\r
+    case WM_LBUTTONDOWN:\r
+      return on_left_mouse_button_down(\r
+        wParam,dpi_.scale_x(\r
+        GET_X_LPARAM(lParam)),dpi_.scale_y(GET_Y_LPARAM(lParam)))\r
+        ;\r
+      ;\r
+    case WM_LBUTTONUP:\r
+      return on_left_mouse_button_up(\r
+        wParam,dpi_.scale_x(\r
+        GET_X_LPARAM(lParam)),dpi_.scale_y(GET_Y_LPARAM(lParam)))\r
+        ;\r
+    case WM_LBUTTONDBLCLK:\r
+      return on_left_mouse_button_double_click(wParam,\r
+        dpi_.scale_x(\r
+        GET_X_LPARAM(lParam)),dpi_.scale_y(GET_Y_LPARAM(lParam)))\r
+        ;\r
+    case WM_MOUSEMOVE:\r
+      {\r
+        return on_mouse_move(wParam,\r
+          dpi_.scale_x(\r
+          GET_X_LPARAM(lParam)),dpi_.scale_y(GET_Y_LPARAM(lParam)))\r
+          ;\r
+        //                                     on_mouse_move(GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam),wParam); \r
+      }\r
+    case WM_MOUSEWHEEL:\r
+      return on_mouse_wheel(GET_KEYSTATE_WPARAM(wParam),GET_WHEEL_DELTA_WPARAM(wParam),\r
+        dpi_.scale_x(\r
+        GET_X_LPARAM(lParam)),dpi_.scale_y(GET_Y_LPARAM(lParam)))\r
+        ;\r
+    case WM_MOUSELEAVE:\r
+      return on_mouse_leave() ;\r
+    case WM_KEYDOWN:\r
+      return on_key_down(wParam,lParam & 0xffff0000,LOWORD(lParam)) ;\r
+    case WM_KEYUP:\r
+      return on_key_up(wParam,lParam & 0xffff0000,LOWORD(lParam)) ;\r
+    case WM_APPCOMMAND:\r
+      return on_app_command(GET_APPCOMMAND_LPARAM(lParam),GET_DEVICE_LPARAM(lParam),GET_KEYSTATE_LPARAM(lParam));\r
+    case WM_COMMAND:\r
+      return on_command(wParam,lParam);\r
+    case WM_DESTROY:\r
+      return on_destroy();\r
+    case WM_CLOSE:\r
+      return on_close();\r
+    case WM_TIMER:\r
+      return on_timer(wParam);\r
+    case WM_NOTIFY:\r
+      return on_notify(reinterpret_cast<NMHDR*>(lParam));\r
+    case WM_DWMCOMPOSITIONCHANGED:\r
+      return on_dwm_composition_changed();\r
+    //case WM_DWMCOLORIZATIONCOLORCHANGED:\r
+    //  return on_dwm_colorlizationcolor_changed\r
+    }\r
+\r
+    // 他のWindowメッセージを派生クラス側でフックできるようにする\r
+    return other_window_proc(hwnd,message,wParam,lParam);\r
+\r
+  };\r
+\r
+  template <typename ProcType> \r
+  void base_win32_window<ProcType>::register_class (\r
+    const wchar_t * menu_name,\r
+    uint32_t        style ,\r
+    int32_t     cbClsExtra,\r
+    int32_t   cbWndExtra,\r
+    HICON       hIcon ,\r
+    HCURSOR     hCursor,\r
+    HBRUSH      hbrBackground ,\r
+    HICON       hIconSm\r
+    )          \r
+  {\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
+    //register_class(0,0);\r
+    wnd_class_.reset(new sf::window_class_ex(0,name_,HINST_THISCOMPONENT,&start_wnd_proc));\r
+  }\r
+\r
+  template <typename ProcType> \r
+  void base_win32_window<ProcType>::create_window(HWND parent)\r
+  {\r
+    // Create the application window.\r
+    //\r
+    // Because the CreateWindow function takes its size in pixels, we\r
+    // obtain the system DPI and use it to scale the window size.\r
+    //FLOAT dpiX, dpiY;\r
+    //factory_->GetDesktopDpi(&dpiX, &dpiY);\r
+\r
+\r
+    // Windowを作成する\r
+    // Windowを作成する\r
+    CreateWindowEx(\r
+       WS_EX_APPWINDOW/* | WS_EX_LAYERED */,\r
+      name_.c_str(),\r
+      title_.c_str(),\r
+      WS_OVERLAPPEDWINDOW /*| WS_POPUP*/,\r
+      CW_USEDEFAULT,\r
+      CW_USEDEFAULT,\r
+      static_cast<uint32_t>(width_),\r
+      static_cast<uint32_t>(height_),\r
+      parent,\r
+      NULL,\r
+      HINST_THISCOMPONENT,\r
+      this\r
+      );\r
+    ::GetWindowPlacement(hwnd_,&wp_);\r
+  }\r
+\r
+\r
+  //void base_win32_window::show() \r
+  //{\r
+  //  //HRESULT hr = S_OK;\r
+  //  //BOOL enable;\r
+  //  //DwmIsCompositionEnabled (&enable);\r
+  //  //if(enable){\r
+  //  //   //Create and populate the BlurBehind structre\r
+  //  //   DWM_BLURBEHIND bb = {0};\r
+  //  //   //Enable Blur Behind and Blur Region;\r
+  //  //   bb.dwFlags = DWM_BB_ENABLE;\r
+  //  //   bb.fEnable = true;\r
+  //  //   bb.hRgnBlur = NULL;\r
+\r
+  //  //   //Enable Blur Behind\r
+  //  //   hr = DwmEnableBlurBehindWindow(hwnd_, &bb);\r
+  //  //}\r
+  //  ::ShowWindow(hwnd_,SW_SHOW);\r
+  //  ::GetWindowPlacement(&wp_);\r
+  //}\r
+\r
+\r
+  template <typename ProcType> \r
+  void base_win32_window<ProcType>::update() {::UpdateWindow(hwnd_);}\r
+\r
+  template <typename ProcType> \r
+  base_win32_window<ProcType>::~base_win32_window()\r
+  {\r
+  }\r
+\r
+  template <typename ProcType> \r
+  base_win32_window<ProcType>::base_win32_window(const std::wstring& title,const std::wstring& name,bool fit_to_display,float width,float height)\r
+    : title_(title),name_(name),fit_to_display_(fit_to_display),width_(width),height_(height),thunk_(this,reinterpret_cast<ProcType::proc_type>(base_win32_window::WndProc)),hwnd_(0),timer_(*this,10)\r
+  {\r
+    ZeroMemory(&actual_desc_,sizeof(DXGI_MODE_DESC));\r
+    width_ = dpi_.scale_x(width_);\r
+    height_ = dpi_.scale_y(height_);\r
+    memset(&wp_,0,sizeof(wp_));\r
+    wp_.length = sizeof(WINDOWPLACEMENT);\r
+    thunk_proc_ = (WNDPROC)thunk_.getCode();\r
+    create_device_independent_resources();\r
+  }\r
+\r
+  template <typename ProcType> \r
+  typename base_win32_window<ProcType>::result_t base_win32_window<ProcType>::on_nccreate(CREATESTRUCT *p)\r
+  {\r
+\r
+    return std::is_same<proc_t,wndproc>::value?1:FALSE;\r
+  }\r
+\r
+  template <typename ProcType> \r
+  void  base_win32_window<ProcType>::create_device_independent_resources()\r
+  {\r
+\r
+    // DXGI Factory の 生成\r
+\r
+    if(!dxgi_factory_)\r
+    {\r
+      THROW_IFERR(CreateDXGIFactory1(__uuidof(IDXGIFactory1),reinterpret_cast<void**>(dxgi_factory_.GetAddressOf())));\r
+      get_dxgi_information();\r
+    }\r
+\r
+  }\r
+\r
+  template <typename ProcType> \r
+  void  base_win32_window<ProcType>::create_device(){\r
+    calc_client_size();\r
+    HRESULT hr = S_OK;\r
+    init_ = false;\r
+    RECT rc;\r
+    GetWindowRect(hwnd_,&rc);\r
+\r
+    // アダプタデバイス情報の取得\r
+    //LARGE_INTEGER version;\r
+    THROW_IFERR(dxgi_factory_->EnumAdapters1(0,&adapter_));\r
+    //THROW_IFERR(adapter_->CheckInterfaceSupport( __uuidof(ID3D10Device),&version));\r
+\r
+\r
+    // D3DDeviceの作成\r
+\r
+    std::vector<D3D_FEATURE_LEVEL> feature_levels = \r
+      boost::assign::list_of<D3D_FEATURE_LEVEL>\r
+      (D3D_FEATURE_LEVEL_11_0 )        // DirectX11対応GPU\r
+      (D3D_FEATURE_LEVEL_10_1)        // DirectX10.1対応GPU\r
+      (D3D_FEATURE_LEVEL_10_0 );       // DirectX10対応GPU\r
+\r
+    D3D_FEATURE_LEVEL level;\r
+    THROW_IFERR(::D3D11CreateDevice(\r
+      adapter_.Get(),\r
+      D3D_DRIVER_TYPE_UNKNOWN ,\r
+      NULL,\r
+      D3D11_CREATE_DEVICE_DEBUG,\r
+      &feature_levels[0],\r
+      feature_levels.size(),\r
+      D3D11_SDK_VERSION,\r
+      &d3d_device_,\r
+      &level,\r
+      &d3d_context_));\r
+\r
+    THROW_IFERR(adapter_->EnumOutputs(0,&output_));\r
+\r
+    // MSAA\r
+    DXGI_SAMPLE_DESC msaa;\r
+    for(int i = 0; i <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; i++){\r
+      UINT q;\r
+      if SUCCEEDED(d3d_device_->CheckMultisampleQualityLevels(DXGI_FORMAT_D24_UNORM_S8_UINT, i, &q)){\r
+        if(1 < q){\r
+          msaa.Count = i;\r
+          msaa.Quality = q - 1;\r
+          break;\r
+        }\r
+      }\r
+    }\r
+\r
+    // 表示モード\r
+    DXGI_MODE_DESC desired_desc = {};// , actual_desc_ = {};\r
+    // 各色8ビットで符号化なし正規化数\r
+    desired_desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;\r
+    desired_desc.Height = height_;// 高さ\r
+    desired_desc.Width = width_;// 幅\r
+    desired_desc.Scaling = DXGI_MODE_SCALING_CENTERED;// スケーリングなし\r
+    // リフレッシュレートを60Hzを要求する\r
+\r
+    desired_desc.RefreshRate.Numerator = 60000;\r
+    desired_desc.RefreshRate.Denominator = 1000;\r
+    // 近いモードを検索\r
+    THROW_IF_ERR(output_->FindClosestMatchingMode(&desired_desc,&actual_desc_,d3d_device_.Get()));\r
+\r
+    //// スワップチェーンの作成\r
+    //{\r
+    //  DXGI_SWAP_CHAIN_DESC desc = {};\r
+\r
+    //  desc.BufferDesc = actual_desc_;\r
+    //  desc.SampleDesc.Count  = 1;\r
+    //  desc.BufferUsage                       = DXGI_USAGE_RENDER_TARGET_OUTPUT;\r
+    //  desc.BufferCount                       = 1;\r
+    //  //      desc.SampleDesc = msaa;\r
+    //  desc.OutputWindow              = hwnd_;\r
+    //  //desc.SwapEffect                      = DXGI_SWAP_EFFECT_DISCARD;\r
+    //  desc.Windowed                  = TRUE;\r
+    //  desc.Flags = DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE;\r
+\r
+    //  THROW_IFERR(dxgi_factory_->CreateSwapChain(d3d_device_,&desc,&swap_chain_));\r
+\r
+    //}\r
+\r
+    // バックバッファの作成\r
+  \r
+    D3D11_TEXTURE2D_DESC desc = {0};\r
+    desc.Width = actual_desc_.Width;\r
+    desc.Height = actual_desc_.Height;\r
+    desc.Format = actual_desc_.Format;\r
+    desc.MipLevels = 1;\r
+    desc.SampleDesc.Count = 1;\r
+    desc.SampleDesc.Quality = 0;\r
+    desc.ArraySize = 1;\r
+    desc.Usage = D3D11_USAGE_DEFAULT;\r
+    desc.BindFlags = D3D11_BIND_RENDER_TARGET;\r
+    desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;\r
+    THROW_IF_ERR(d3d_device_->CreateTexture2D(&desc,NULL,&back_buffer_));\r
+\r
+    // スワップチェーン依存リソースの作成\r
+    \r
+    create_swapchain_dependent_resources();\r
+\r
+    {\r
+      // バーテックスシェーダのコンパイル\r
+      ID3DBlobPtr vsblob,vserrblob;\r
+      DWORD compile_flag = D3DCOMPILE_ENABLE_STRICTNESS;\r
+#if defined( DEBUG ) || defined( _DEBUG )\r
+      compile_flag |= D3DCOMPILE_DEBUG;\r
+#endif\r
+\r
+         HRESULT hr = D3DCompileFromFile\r
+                 (\r
+                       L"dxgi_test.fx", NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE , "VS", "vs_5_0", \r
+        compile_flag, 0, &vsblob, &vserrblob );\r
+      if( FAILED( hr ) )\r
+      {\r
+        if( vserrblob != NULL )\r
+          OutputDebugStringA( (char*)vserrblob->GetBufferPointer() );\r
+        if( vserrblob ) vserrblob.Reset();\r
+        throw sf::win32_error_exception(hr);\r
+      }\r
+\r
+      // バーテックスシェーダの生成\r
+      THROW_IFERR(d3d_device_->CreateVertexShader( vsblob->GetBufferPointer(), vsblob->GetBufferSize(), NULL, &v_shader_ ));\r
+\r
+      // 入力頂点レイアウトの定義\r
+      D3D11_INPUT_ELEMENT_DESC\r
+        layout[] = {\r
+          { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },\r
+          { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },\r
+          { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }};\r
+          ;\r
+\r
+          // 入力頂点レイアウトの生成\r
+          THROW_IFERR(d3d_device_->CreateInputLayout( layout, ARRAYSIZE(layout), vsblob->GetBufferPointer(),\r
+            vsblob->GetBufferSize(), &input_layout_ ));\r
+          vsblob.Reset();\r
+    }\r
+\r
+    // 入力レイアウトの設定\r
+    d3d_context_->IASetInputLayout( input_layout_.Get() );\r
+\r
+    // ピクセル・シェーダーのコンパイル\r
+    {\r
+      ID3DBlobPtr psblob,pserror;\r
+      DWORD compile_flag = D3DCOMPILE_ENABLE_STRICTNESS;\r
+#if defined( DEBUG ) || defined( _DEBUG )\r
+      compile_flag |= D3DCOMPILE_DEBUG;\r
+#endif\r
+      HRESULT hr = D3DCompileFromFile( L"dxgi_test.fx", NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, "PS", "ps_5_0", \r
+        compile_flag, 0,  &psblob, &pserror);\r
+      if( FAILED( hr ) )\r
+      {\r
+        if( pserror != NULL )\r
+          OutputDebugStringA( (char*)pserror->GetBufferPointer() );\r
+        safe_release(pserror);\r
+        throw sf::win32_error_exception(hr);\r
+      }\r
+\r
+      // ピクセルシェーダの作成\r
+      THROW_IFERR(d3d_device_->CreatePixelShader( psblob->GetBufferPointer(), psblob->GetBufferSize(), NULL, &p_shader_ ));\r
+\r
+      psblob.Reset();\r
+    }\r
+\r
+    // バーテックスバッファの作成\r
+    // Create vertex buffer\r
+    simple_vertex vertices[] =\r
+    {\r
+      { XMFLOAT3( 0.0f, 0.0f,0.0f ),XMFLOAT3( 0.0f, 0.0f, -1.0f ) , XMFLOAT2( 0.0f, 0.0f ) },\r
+      { XMFLOAT3( 640.0f, 0.0f, 0.0f ),XMFLOAT3( 0.0f, 0.0f, -1.0f ), XMFLOAT2( 1.0f, 0.0f ) },\r
+      { XMFLOAT3( 0.0f, 480.0f, 0.0f ),XMFLOAT3( 0.0f, 0.0f, -1.0f ) , XMFLOAT2( 0.0f, 1.0f ) },\r
+      { XMFLOAT3( 640.0f, 480.0f, 0.0f ),XMFLOAT3( 0.0f, 0.0f, -1.0f ), XMFLOAT2( 1.0f, 1.0f ) }\r
+\r
+      //{ XMFLOAT3( -1.0f, -1.0f, 2.0f ),XMFLOAT3( 0.0f, 0.0f, -1.0f ) , XMFLOAT2( 1.0f, 1.0f ) },\r
+      //{ XMFLOAT3( 1.0f, -1.0f, 2.0f ),XMFLOAT3( 0.0f, 0.0f, -1.0f ), XMFLOAT2( 0.0f, 1.0f ) },\r
+      //{ XMFLOAT3( -1.0f, 1.0f, 2.0f ),XMFLOAT3( 0.0f, 0.0f, -1.0f ) , XMFLOAT2( 1.0f, 0.0f ) },\r
+      //{ XMFLOAT3( 1.0f, 1.0f, 2.0f ),XMFLOAT3( 0.0f, 0.0f, -1.0f ), XMFLOAT2( 0.0f, 0.0f ) }\r
+      // ---------------------\r
+      //{ XMFLOAT3( -1.0f, 1.0f, -1.0f ), XMFLOAT3( 0.0f, 1.0f, 0.0f ),XMFLOAT2( 0.0f, 0.0f ) },\r
+      //{ XMFLOAT3( 1.0f, 1.0f, -1.0f ),XMFLOAT3( 0.0f, 1.0f, 0.0f ), XMFLOAT2( 1.0f, 0.0f ) },\r
+      //{ XMFLOAT3( 1.0f, 1.0f, 1.0f ),XMFLOAT3( 0.0f, 1.0f, 0.0f ), XMFLOAT2( 1.0f, 1.0f ) },\r
+      //{ XMFLOAT3( -1.0f, 1.0f, 1.0f ), XMFLOAT3( 0.0f, 1.0f, 0.0f ) ,XMFLOAT2( 0.0f, 1.0f ) },\r
+\r
+      //{ XMFLOAT3( -1.0f, -1.0f, -1.0f ),XMFLOAT3( 0.0f, -1.0f, 0.0f ), XMFLOAT2( 0.0f, 0.0f ) },\r
+      //{ XMFLOAT3( 1.0f, -1.0f, -1.0f ),  XMFLOAT3( 0.0f, -1.0f, 0.0f ) ,XMFLOAT2( 1.0f, 0.0f ) },\r
+      //{ XMFLOAT3( 1.0f, -1.0f, 1.0f ), XMFLOAT3( 0.0f, -1.0f, 0.0f ) , XMFLOAT2( 1.0f, 1.0f ) },\r
+      //{ XMFLOAT3( -1.0f, -1.0f, 1.0f ), XMFLOAT3( 0.0f, -1.0f, 0.0f ),XMFLOAT2( 0.0f, 1.0f ) },\r
+\r
+      //{ XMFLOAT3( -1.0f, -1.0f, 1.0f ),XMFLOAT3( -1.0f, 0.0f, 0.0f ) , XMFLOAT2( 0.0f, 0.0f ) },\r
+      //{ XMFLOAT3( -1.0f, -1.0f, -1.0f ),XMFLOAT3( -1.0f, 0.0f, 0.0f ), XMFLOAT2( 1.0f, 0.0f ) },\r
+      //{ XMFLOAT3( -1.0f, 1.0f, -1.0f ), XMFLOAT3( -1.0f, 0.0f, 0.0f ),XMFLOAT2( 1.0f, 1.0f ) },\r
+      //{ XMFLOAT3( -1.0f, 1.0f, 1.0f ),XMFLOAT3( -1.0f, 0.0f, 0.0f ), XMFLOAT2( 0.0f, 1.0f ) },\r
+\r
+      //{ XMFLOAT3( 1.0f, -1.0f, 1.0f ),XMFLOAT3( 1.0f, 0.0f, 0.0f ), XMFLOAT2( 0.0f, 0.0f ) },\r
+      //{ XMFLOAT3( 1.0f, -1.0f, -1.0f ),XMFLOAT3( 1.0f, 0.0f, 0.0f ), XMFLOAT2( 1.0f, 0.0f ) },\r
+      //{ XMFLOAT3( 1.0f, 1.0f, -1.0f ),XMFLOAT3( 1.0f, 0.0f, 0.0f ), XMFLOAT2( 1.0f, 1.0f ) },\r
+      //{ XMFLOAT3( 1.0f, 1.0f, 1.0f ),XMFLOAT3( 1.0f, 0.0f, 0.0f ), XMFLOAT2( 0.0f, 1.0f ) },\r
+\r
+      //{ XMFLOAT3( -1.0f, -1.0f, -1.0f ),XMFLOAT3( 0.0f, 0.0f, -1.0f ) , XMFLOAT2( 0.0f, 0.0f ) },\r
+      //{ XMFLOAT3( 1.0f, -1.0f, -1.0f ),XMFLOAT3( 0.0f, 0.0f, -1.0f ), XMFLOAT2( 1.0f, 0.0f ) },\r
+      //{ XMFLOAT3( 1.0f, 1.0f, -1.0f ),XMFLOAT3( 0.0f, 0.0f, -1.0f ), XMFLOAT2( 1.0f, 1.0f ) },\r
+      //{ XMFLOAT3( -1.0f, 1.0f, -1.0f ),XMFLOAT3( 0.0f, 0.0f, -1.0f ) , XMFLOAT2( 0.0f, 1.0f ) },\r
+\r
+      //{ XMFLOAT3( -1.0f, -1.0f, 1.0f ), XMFLOAT3( 0.0f, 0.0f, 1.0f ) , XMFLOAT2( 0.0f, 0.0f ) },\r
+      //{ XMFLOAT3( 1.0f, -1.0f, 1.0f ), XMFLOAT3( 0.0f, 0.0f, 1.0f ) , XMFLOAT2( 1.0f, 0.0f ) },\r
+      //{ XMFLOAT3( 1.0f, 1.0f, 1.0f ),XMFLOAT3( 0.0f, 0.0f, 1.0f ), XMFLOAT2( 1.0f, 1.0f ) },\r
+      //{ XMFLOAT3( -1.0f, 1.0f, 1.0f ), XMFLOAT3( 0.0f, 0.0f, 1.0f ),XMFLOAT2( 0.0f, 1.0f ) }\r
+    };\r
+    //std::vector<simple_vertex> vertices = boost::assign::list_of<simple_vertex>\r
+    //\r
+    //    ( XMFLOAT3( -1.0f, 1.0f, -1.0f ), XMFLOAT2( 0.0f, 0.0f ) )\r
+    //    ( XMFLOAT3( 1.0f, 1.0f, -1.0f ), XMFLOAT2( 1.0f, 0.0f ) )\r
+    //    ( XMFLOAT3( 1.0f, 1.0f, 1.0f ), XMFLOAT2( 1.0f, 1.0f ) )\r
+    //    ( XMFLOAT3( -1.0f, 1.0f, 1.0f ), XMFLOAT2( 0.0f, 1.0f ) )\r
+\r
+    //    ( XMFLOAT3( -1.0f, -1.0f, -1.0f ), XMFLOAT2( 0.0f, 0.0f ) )\r
+    //    ( XMFLOAT3( 1.0f, -1.0f, -1.0f ), XMFLOAT2( 1.0f, 0.0f ) )\r
+    //    ( XMFLOAT3( 1.0f, -1.0f, 1.0f ), XMFLOAT2( 1.0f, 1.0f ) )\r
+    //    ( XMFLOAT3( -1.0f, -1.0f, 1.0f ), XMFLOAT2( 0.0f, 1.0f ) )\r
+\r
+    //    ( XMFLOAT3( -1.0f, -1.0f, 1.0f ), XMFLOAT2( 0.0f, 0.0f ) )\r
+    //    ( XMFLOAT3( -1.0f, -1.0f, -1.0f ), XMFLOAT2( 1.0f, 0.0f ) )\r
+    //    ( XMFLOAT3( -1.0f, 1.0f, -1.0f ), XMFLOAT2( 1.0f, 1.0f ) )\r
+    //    ( XMFLOAT3( -1.0f, 1.0f, 1.0f ), XMFLOAT2( 0.0f, 1.0f ) )\r
+\r
+    //    ( XMFLOAT3( 1.0f, -1.0f, 1.0f ), XMFLOAT2( 0.0f, 0.0f ) )\r
+    //    ( XMFLOAT3( 1.0f, -1.0f, -1.0f ), XMFLOAT2( 1.0f, 0.0f ) )\r
+    //    ( XMFLOAT3( 1.0f, 1.0f, -1.0f ), XMFLOAT2( 1.0f, 1.0f ) )\r
+    //    ( XMFLOAT3( 1.0f, 1.0f, 1.0f ), XMFLOAT2( 0.0f, 1.0f ) )\r
+\r
+    //    ( XMFLOAT3( -1.0f, -1.0f, -1.0f ), XMFLOAT2( 0.0f, 0.0f ) )\r
+    //    ( XMFLOAT3( 1.0f, -1.0f, -1.0f ), XMFLOAT2( 1.0f, 0.0f ) )\r
+    //    ( XMFLOAT3( 1.0f, 1.0f, -1.0f ), XMFLOAT2( 1.0f, 1.0f ) )\r
+    //    ( XMFLOAT3( -1.0f, 1.0f, -1.0f ), XMFLOAT2( 0.0f, 1.0f ) )\r
+\r
+    //    ( XMFLOAT3( -1.0f, -1.0f, 1.0f ), XMFLOAT2( 0.0f, 0.0f ) )\r
+    //    ( XMFLOAT3( 1.0f, -1.0f, 1.0f ), XMFLOAT2( 1.0f, 0.0f ) )\r
+    //    ( XMFLOAT3( 1.0f, 1.0f, 1.0f ), XMFLOAT2( 1.0f, 1.0f ) )\r
+    //    ( XMFLOAT3( -1.0f, 1.0f, 1.0f ), XMFLOAT2( 0.0f, 1.0f ) );\r
+\r
+    D3D11_BUFFER_DESC bd = {};\r
+    bd.Usage = D3D11_USAGE_DEFAULT;\r
+    bd.ByteWidth = sizeof( simple_vertex ) * 4;\r
+    bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;\r
+    bd.CPUAccessFlags = 0;\r
+\r
+    D3D11_SUBRESOURCE_DATA init_data = {};\r
+    init_data.pSysMem = vertices;\r
+    THROW_IFERR(d3d_device_->CreateBuffer( &bd, &init_data, &v_buffer_ ));\r
+\r
+    // 頂点バッファのセット\r
+    uint32_t stride = sizeof( simple_vertex );\r
+    uint32_t offset = 0;\r
+    d3d_context_->IASetVertexBuffers( 0, 1, v_buffer_.GetAddressOf(), &stride, &offset );\r
+\r
+    // インデックスバッファの生成\r
+    WORD indices[] =\r
+    {\r
+      0,1,2,\r
+      2,3,1\r
+      //3,1,0,\r
+      //2,1,3,\r
+      //6,4,5,\r
+      //7,4,6,\r
+      //11,9,8,\r
+      //10,9,11,\r
+      //14,12,13,\r
+      //15,12,14,\r
+      //19,17,16,\r
+      //18,17,19,\r
+      //22,20,21,\r
+      //23,20,22\r
+    };\r
+\r
+    bd.Usage = D3D11_USAGE_DEFAULT;\r
+    bd.ByteWidth = sizeof( WORD ) * 6;\r
+    bd.BindFlags = D3D11_BIND_INDEX_BUFFER;\r
+    bd.CPUAccessFlags = 0;\r
+    init_data.pSysMem = indices;\r
+    THROW_IFERR(d3d_device_->CreateBuffer( &bd, &init_data, &i_buffer_ ));\r
+\r
+    // インデックスバッファのセット\r
+    d3d_context_->IASetIndexBuffer( i_buffer_.Get(), DXGI_FORMAT_R16_UINT, 0 );\r
+\r
+    // プリミティブの形態を指定する\r
+    d3d_context_->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP );\r
+\r
+    // 定数バッファを生成する。\r
+    bd.Usage = D3D11_USAGE_DEFAULT;\r
+    bd.ByteWidth = sizeof(cb_never_changes);\r
+    bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;\r
+    bd.CPUAccessFlags = 0;\r
+    THROW_IFERR(d3d_device_->CreateBuffer( &bd, NULL, &cb_never_changes_ ));\r
+\r
+    bd.ByteWidth = sizeof(cb_change_on_resize);\r
+    THROW_IFERR(d3d_device_->CreateBuffer( &bd, NULL, &cb_change_on_resize_ ));\r
+\r
+    bd.ByteWidth = sizeof(cb_changes_every_frame);\r
+    THROW_IFERR(d3d_device_->CreateBuffer( &bd, NULL, &cb_changes_every_frame_ ));\r
+\r
+    // テクスチャのロード\r
+       ID3D11ResourcePtr ptr;\r
+    THROW_IFERR(CreateDDSTextureFromFile( d3d_device_.Get(), L"SF.dds", &ptr, &shader_res_view_, NULL ));\r
+//    THROW_IFERR(CreateDDSTextureFromFile( d3d_device_, L"SF.dds", NULL, NULL, &shader_res_view_, NULL ));\r
+\r
+    // サンプルステートの生成\r
+    D3D11_SAMPLER_DESC sdesc = {};\r
+    sdesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;\r
+    sdesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;\r
+    sdesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;\r
+    sdesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;\r
+    sdesc.ComparisonFunc = D3D11_COMPARISON_NEVER;\r
+    sdesc.MinLOD = 0;\r
+    sdesc.MaxLOD = D3D11_FLOAT32_MAX;\r
+    THROW_IFERR(d3d_device_->CreateSamplerState( &sdesc, &sampler_state_ ));\r
+\r
+    // ワールド座標変換行列のセットアップ\r
+    mat_world_ = XMMatrixIdentity();\r
+\r
+    //g_vMeshColor( 0.7f, 0.7f, 0.7f, 1.0f );\r
+    // \r
+    init_view_matrix();\r
+\r
+\r
+\r
+    // 動的テクスチャの生成\r
+    {\r
+      //D3D11_TEXTURE2D_DESC desc = {0};\r
+      //desc.Width = 256;\r
+      //desc.Height = 256;\r
+      //desc.Format = actual_desc_.Format;\r
+      //desc.MipLevels = 1;\r
+      //desc.SampleDesc.Count = 1;\r
+      //desc.SampleDesc.Quality = 0;\r
+      //desc.ArraySize = 1;\r
+      //desc.Usage = D3D11_USAGE_DEFAULT;\r
+      //desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;\r
+      //// desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;\r
+      //THROW_IF_ERR(d3d_device_->CreateTexture2D(&desc,NULL,&cube_texture_));\r
+      //THROW_IF_ERR(d3d_device_->CreateRenderTargetView(cube_texture_,0,&cube_view_));\r
+\r
+      //// 深度バッファの作成\r
+      //D3D11_TEXTURE2D_DESC depth = {} ;\r
+      //depth.Width = desc.Width;//rc.right - rc.left;client_width_;\r
+      //depth.Height = desc.Height;//rc.bottom - rc.top;client_height_;\r
+      //depth.MipLevels = 1;\r
+      //depth.ArraySize = 1;\r
+      //depth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;\r
+      //depth.SampleDesc.Count = 1;\r
+      //depth.SampleDesc.Quality = 0;\r
+      //depth.Usage = D3D11_USAGE_DEFAULT;\r
+      //depth.BindFlags = D3D11_BIND_DEPTH_STENCIL;\r
+      //depth.CPUAccessFlags = 0;\r
+      //depth.MiscFlags = 0;\r
+      //THROW_IF_ERR(d3d_device_->CreateTexture2D( &depth, NULL, &cube_depth_texture_ ));\r
+\r
+      //D3D11_DEPTH_STENCIL_VIEW_DESC dsv = {};\r
+      //dsv.Format = depth.Format;\r
+      //dsv.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;\r
+      //dsv.Texture2D.MipSlice = 0;\r
+      //THROW_IF_ERR(d3d_device_->CreateDepthStencilView( cube_depth_texture_, &dsv, &cube_depth_view_ ));\r
+      //THROW_IF_ERR(d3d_device_->CreateShaderResourceView(cube_texture_,0,&cube_shader_res_view_));\r
+\r
+      //D3D11_SAMPLER_DESC sdesc = {};\r
+      //sdesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;\r
+      //sdesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;\r
+      //sdesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;\r
+      //sdesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;\r
+      //sdesc.ComparisonFunc = D3D11_COMPARISON_NEVER;\r
+      //sdesc.MinLOD = 0;\r
+      //sdesc.MaxLOD = D3D11_FLOAT32_MAX;\r
+      //THROW_IFERR(d3d_device_->CreateSamplerState( &sdesc, &cube_sampler_state_ ));\r
+      //cube_mat_projection_ = XMMatrixPerspectiveFovLH( XM_PIDIV4, /*(rc.right - rc.left)/(rc.bottom - rc.top)*/256 / 256, 0.01f, 100.0f );\r
+\r
+    }\r
+    // \r
+\r
+    init_ = true;// 初期化完了\r
+  }\r
+\r
+\r
+  template <typename ProcType> \r
+  void  base_win32_window<ProcType>::init_view_matrix()\r
+  {\r
+    // ビュー行列のセットアップ\r
+         //基本値設定\r
+         float aspect = (float) width_ / height_;          //アスペクト比(高さを1としたときの幅)\r
+         float depth = 1.0f;                                                                           //奥行きZ\r
+         float fovy  = (float)atan(1.0f / depth) * 2.0f;                                       //視野をZ=0でデバイスの幅と高さに合わせる\r
+       \r
+         XMVECTOR eye = { 0.0f, 0.0f, -depth, 0.0f };\r
+         XMVECTOR at = { 0.0f, 0.0f, 0.0f, 0.0f};\r
+         XMVECTOR up = { 0.0f, 1.0f, 0.0f, 0.0f };\r
+    mat_view_ = XMMatrixLookAtLH( eye, at, up );\r
+    cb_never_changes cnc;\r
+    cnc.mView = XMMatrixTranspose( mat_view_ );\r
+    //cnc.vLightColor = XMFLOAT4( 1.0f, 0.5f, 0.5f, 1.0f );\r
+    cnc.vLightDir =  XMFLOAT4(0.577f, 0.577f, -0.977f, 1.0f);\r
+    // 定数バッファに格納\r
+    d3d_context_->UpdateSubresource( cb_never_changes_.Get(), 0, NULL, &cnc, 0, 0 );\r
+\r
+    // 投影行列のセットアップ\r
+\r
+    //mat_projection_ = XMMatrixPerspectiveFovLH( XM_PIDIV4, /*(rc.right - rc.left)/(rc.bottom - rc.top)*/width_ / height_, 0.01f, 100.0f );\r
+    //mat_projection_ = XMMatrixPerspectiveFovLH( fovy, aspect, 0.01f, 100.0f );\r
+    mat_projection_ = XMMatrixPerspectiveFovLH( fovy, 1.0, 0.0001f, 100.0f );\r
+    cb_change_on_resize ccor;\r
+    ccor.mProjection = XMMatrixTranspose( mat_projection_ );\r
+    // 定数バッファに格納\r
+    d3d_context_->UpdateSubresource( cb_change_on_resize_.Get(), 0, NULL, &ccor, 0, 0 );\r
+\r
+  }\r
+  template <typename ProcType> \r
+  void  base_win32_window<ProcType>::create_swapchain_dependent_resources()\r
+  {\r
+\r
+    // ビューの作成\r
+    //THROW_IF_ERR(swap_chain_->GetBuffer(0,texture_.GetIID(),(void**)&texture_));\r
+    //D3D11_TEXTURE2D_DESC desc;\r
+    //texture_->GetDesc(&desc);\r
+\r
+    //THROW_IF_ERR(d3d_device_->CreateRenderTargetView(texture_,0,&view_));\r
+    //texture_.Release();\r
+    THROW_IF_ERR(d3d_device_->CreateRenderTargetView(back_buffer_.Get(),0,view_.GetAddressOf()));\r
+    D3D11_TEXTURE2D_DESC desc;\r
+    back_buffer_->GetDesc(&desc);\r
+\r
+    // 深度バッファの作成\r
+    D3D11_TEXTURE2D_DESC depth = {} ;\r
+    depth.Width = desc.Width;//rc.right - rc.left;client_width_;\r
+    depth.Height = desc.Height;//rc.bottom - rc.top;client_height_;\r
+    depth.MipLevels = 1;\r
+    depth.ArraySize = 1;\r
+    depth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;\r
+    depth.SampleDesc.Count = 1;\r
+    depth.SampleDesc.Quality = 0;\r
+    depth.Usage = D3D11_USAGE_DEFAULT;\r
+    depth.BindFlags = D3D11_BIND_DEPTH_STENCIL;\r
+    depth.CPUAccessFlags = 0;\r
+    depth.MiscFlags = 0;\r
+    THROW_IF_ERR(d3d_device_->CreateTexture2D( &depth, NULL, &depth_texture_ ));\r
+\r
+    D3D11_DEPTH_STENCIL_VIEW_DESC dsv = {};\r
+    dsv.Format = depth.Format;\r
+    dsv.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;\r
+    dsv.Texture2D.MipSlice = 0;\r
+    THROW_IF_ERR(d3d_device_->CreateDepthStencilView( depth_texture_.Get(), &dsv, depth_view_.GetAddressOf() ));\r
+\r
+    // OMステージに登録する\r
+    // d3d_context_->OMSetRenderTargets( 1, &view_.Get(), depth_view_ );\r
+    d3d_context_->OMSetRenderTargets( 1, view_.GetAddressOf(), depth_view_.Get() );\r
+\r
+    // ビューポートの設定\r
+    D3D11_VIEWPORT vp;\r
+    vp.Width = depth.Width;//client_width_;\r
+    vp.Height = depth.Height;//client_height_;\r
+    vp.MinDepth = 0.0f;\r
+    vp.MaxDepth = 1.0f;\r
+    vp.TopLeftX = 0;\r
+    vp.TopLeftY = 0;\r
+    d3d_context_->RSSetViewports( 1, &vp );\r
+\r
+       ID3D11RasterizerState* hpRasterizerState = NULL;\r
+       D3D11_RASTERIZER_DESC hRasterizerDesc = {\r
+                       D3D11_FILL_SOLID,\r
+                       D3D11_CULL_NONE,        //ポリゴンの裏表を無くす\r
+                       FALSE,\r
+                       0,\r
+                       0.0f,\r
+                       FALSE,\r
+                       FALSE,\r
+                       FALSE,\r
+                       FALSE,\r
+                       FALSE\r
+       };\r
+  d3d_device_->CreateRasterizerState(&hRasterizerDesc,&hpRasterizerState);\r
+  d3d_context_->RSSetState(hpRasterizerState);\r
+  }\r
+\r
+  template <typename ProcType> \r
+  void  base_win32_window<ProcType>::discard_swapchain_dependent_resources()\r
+  {\r
+    safe_release(depth_view_);\r
+    safe_release(depth_texture_);\r
+    safe_release(view_);\r
+    safe_release(texture_);\r
+  }\r
+\r
+  template <typename ProcType> \r
+  void  base_win32_window<ProcType>::discard_device()\r
+  {\r
+    safe_release(sampler_state_);\r
+    safe_release(shader_res_view_);\r
+    safe_release(cb_changes_every_frame_);\r
+    safe_release(cb_change_on_resize_);\r
+    safe_release(cb_never_changes_);\r
+    safe_release(i_buffer_);\r
+    safe_release(v_buffer_);\r
+    safe_release(p_shader_);\r
+    safe_release(input_layout_);\r
+    safe_release(v_shader_);\r
+    discard_swapchain_dependent_resources();\r
+    safe_release(back_buffer_);\r
+    //safe_release(cube_sampler_state_);\r
+    //safe_release(cube_shader_res_view_);\r
+    //safe_release(cube_view_);\r
+    //safe_release(cube_depth_view_);\r
+    //safe_release(cube_texture_);\r
+    //safe_release(cube_depth_texture_);\r
+    //safe_release(render_target_);\r
+//    safe_release(swap_chain_);\r
+    safe_release(d3d_context_);\r
+    safe_release(d3d_device_);\r
+    safe_release(adapter_);\r
+\r
+  }\r
+\r
+  template <typename ProcType> \r
+  void  base_win32_window<ProcType>::discard_device_independant_resources(){\r
+    safe_release(dxgi_factory_);\r
+  }\r
+\r
+  template <typename ProcType> \r
+  void  base_win32_window<ProcType>::get_dxgi_information()\r
+  {\r
+    int i = 0;\r
+\r
+    while(1){\r
+      IDXGIAdapter1Ptr adapter;\r
+      HRESULT hr = dxgi_factory_->EnumAdapters1(i,&adapter);\r
+      if(hr == DXGI_ERROR_NOT_FOUND)\r
+      {\r
+        break;\r
+      }\r
+      DXGI_ADAPTER_DESC1 desc;\r
+      adapter->GetDesc1(&desc);\r
+      //adapter->CheckInterfaceSupport();\r
+\r
+      wdout << desc.Description << std::endl;\r
+      wdout << desc.DedicatedVideoMemory << std::endl;\r
+      IDXGIDevice1Ptr device;\r
+\r
+      uint32_t oi = 0;\r
+\r
+\r
+      while(1)\r
+      {\r
+        IDXGIOutputPtr output;        \r
+        if(adapter->EnumOutputs(oi,&output) == DXGI_ERROR_NOT_FOUND){\r
+          break;\r
+        }\r
+        DXGI_OUTPUT_DESC output_desc;\r
+        output->GetDesc(&output_desc); \r
+        UINT num = 0;\r
+        DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;\r
+        UINT flags         = DXGI_ENUM_MODES_INTERLACED | DXGI_ENUM_MODES_SCALING;\r
+\r
+        output->GetDisplayModeList(format,flags,&num,0);\r
+        boost::shared_array<DXGI_MODE_DESC> disp_modes(new DXGI_MODE_DESC[num]);\r
+        output->GetDisplayModeList(format,flags,&num,&disp_modes[0]);\r
+        //output->GetFrameStatistics\r
+        for(uint32_t mode_index = 0;mode_index < num;++mode_index)\r
+        {\r
+          DXGI_MODE_DESC& mode(disp_modes[mode_index]);\r
+          wdout << boost::wformat(L"Format: %s %s \n Width: %d Height: %d RefleshRate: %d/%d Scaling:%s %s \n Scanline: %s %s ")\r
+            %  display_modes[mode.Format].name % display_modes[mode.Format].description\r
+            %  mode.Width % mode.Height \r
+            %  mode.RefreshRate.Numerator % mode.RefreshRate.Denominator\r
+            %  scalings[mode.Scaling].name %  scalings[mode.Scaling].description\r
+            %  scanline_orders[mode.ScanlineOrdering].name\r
+            %  scanline_orders[mode.ScanlineOrdering].description\r
+            << std::endl;\r
+        }\r
+        //        output->\r
+        wdout << output_desc.DeviceName << std::endl; \r
+        oi++;\r
+      }\r
+\r
+      adapter.Reset();\r
+      ++i;\r
+    }\r
+  }\r
+\r
+  template <typename ProcType>\r
+  typename base_win32_window<ProcType>::result_t  base_win32_window<ProcType>::on_size(uint32_t flag,uint32_t width,uint32_t height)\r
+  {\r
+    if(init_ && !(width == 0 || height == 0))\r
+    {\r
+      update_window_size();\r
+      calc_client_size();\r
+      discard_swapchain_dependent_resources();\r
+      back_buffer_.Reset();\r
+      D3D11_TEXTURE2D_DESC desc = {0};\r
+      desc.Width = width_;\r
+      desc.Height = height_;\r
+      desc.Format = actual_desc_.Format;\r
+      desc.MipLevels = 1;\r
+      desc.SampleDesc.Count = 1;\r
+      desc.SampleDesc.Quality = 0;\r
+      desc.ArraySize = 1;\r
+      desc.Usage = D3D11_USAGE_DEFAULT;\r
+      desc.BindFlags = D3D11_BIND_RENDER_TARGET;\r
+      desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;\r
+      THROW_IF_ERR(d3d_device_->CreateTexture2D(&desc,NULL,&back_buffer_));\r
+      //swap_chain_->ResizeBuffers(0,0,0,DXGI_FORMAT_B8G8R8A8_UNORM_SRGB,DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE);\r
+      create_swapchain_dependent_resources();\r
+      init_view_matrix(); \r
+\r
+      // リージョンの設定\r
+                 //HRGN rgn = CreateRectRgn(0, 0, width_, height_);\r
+                 //SetWindowRgn(hwnd_, rgn, FALSE);\r
+\r
+    }\r
+    return std::is_same<proc_t,wndproc>::value?0:FALSE;  \r
+  }\r
+\r
+  template <typename ProcType>\r
+  typename base_win32_window<ProcType>::result_t base_win32_window<ProcType>::on_create(CREATESTRUCT *p)\r
+  {\r
+    // DWM API\r
+    BOOL dwmEnable;\r
+    DwmIsCompositionEnabled (&dwmEnable); \r
+    if (dwmEnable) EnableBlurBehind(hwnd_);\r
+    //DwmEnableComposition(DWM_EC_DISABLECOMPOSITION );\r
+\r
+    // ウィンドウ全体を半透明にする\r
+    //SetLayeredWindowAttributes(\r
+    //  hwnd_,\r
+    //  RGB(0,0,0), // color key\r
+    //  100, // alpha value\r
+    //  LWA_ALPHA | LWA_COLORKEY);\r
+\r
+    // ウィンドウの指定領域を半透明にする\r
+    // リージョンの設定\r
+               //HRGN rgn = CreateRectRgn(0, 0, width_, height_);\r
+               //SetWindowRgn(hwnd_, rgn, FALSE);\r
+\r
+    create_device();\r
+\r
+    timer_.start();\r
+    //show();\r
+    show();\r
+    text(title_);\r
+    return std::is_same<proc_t,wndproc>::value?0:FALSE;\r
+  }\r
+\r
+  template <typename ProcType>\r
+  typename base_win32_window<ProcType>::result_t base_win32_window<ProcType>::on_paint() \r
+  {\r
+    //{\r
+    sf::paint_struct p(hwnd_);\r
+    //  gdi_object<HBRUSH> brush(::CreateSolidBrush(RGB(255,0,0)));\r
+    //  {\r
+    //    FillRect(p->hdc,&p->rcPaint,brush);\r
+    //  }\r
+    //}\r
+    render();\r
+    return  std::is_same<proc_t,wndproc>::value?0:FALSE;\r
+  }\r
+\r
+  template <typename ProcType>\r
+  void base_win32_window<ProcType>::render()\r
+  {\r
+\r
+    if(init_)\r
+    {\r
+      static float rot = 0.0f;\r
+\r
+      float color[4] = { 0.0f, 0.0f, 0.0f, 0.5f };    \r
+\r
+      // 描画ターゲットのクリア\r
+      d3d_context_->ClearRenderTargetView(view_.Get(),color);\r
+      // 深度バッファのクリア\r
+      d3d_context_->ClearDepthStencilView(depth_view_.Get(), D3D11_CLEAR_DEPTH, 1.0f, 0 );\r
+\r
+      // 色の変更\r
+      mesh_color_.x = 1.0f;\r
+      mesh_color_.y = 1.0f;\r
+      mesh_color_.z = 1.0f;\r
+\r
+      // 定数更新\r
+\r
+      cb_changes_every_frame cb;\r
+\r
+      mat_world_ = XMMatrixIdentity();\r
+//      mat_world_._11 = 2.0f / width_;\r
+         mat_world_.r[0].m128_f32[0] = 2.0f / width_;\r
+ //      mat_world_._22 = 2.0f  / height_ * -1.0f;\r
+         mat_world_.r[1].m128_f32[1] = 2.0f  / height_ * -1.0f;\r
+//      mat_world_._41 = -1.0f;\r
+         mat_world_.r[3].m128_f32[0] = -1.0f;\r
+//      mat_world_._42 = 1.0f;\r
+         mat_world_.r[3].m128_f32[1] = 1.0f;\r
+      mat_world_ *= XMMatrixRotationX(rot);\r
+      rot += 0.005f;\r
+      cb.mWorld =  XMMatrixTranspose(mat_world_);\r
+      cb.vLightColor = mesh_color_;\r
+      d3d_context_->UpdateSubresource( cb_changes_every_frame_.Get(), 0, NULL, &cb, 0, 0 );\r
+\r
+      // 四角形\r
+      d3d_context_->VSSetShader( v_shader_.Get(), NULL, 0 );\r
+      d3d_context_->VSSetConstantBuffers( 0, 1, cb_never_changes_.GetAddressOf() );\r
+      d3d_context_->VSSetConstantBuffers( 1, 1, cb_change_on_resize_.GetAddressOf() );\r
+      d3d_context_->VSSetConstantBuffers( 2, 1, cb_changes_every_frame_.GetAddressOf() );\r
+      d3d_context_->PSSetShader( p_shader_.Get(), NULL, 0 );\r
+      d3d_context_->PSSetConstantBuffers( 2, 1, cb_changes_every_frame_.GetAddressOf() );\r
+      d3d_context_->PSSetShaderResources( 0, 1, shader_res_view_.GetAddressOf() );\r
+      d3d_context_->PSSetSamplers( 0, 1, sampler_state_.GetAddressOf() );\r
+\r
+      d3d_context_->DrawIndexed( 6, 0, 0 );\r
+\r
+      // 画面に転送\r
+      IDXGISurface1Ptr surface;\r
+      THROW_IF_ERR(back_buffer_.As<IDXGISurface1>(&surface));\r
+      HDC sdc;\r
+      THROW_IF_ERR(surface->GetDC( FALSE, &sdc ));\r
+\r
+      //get_dc ddc(hwnd_);\r
+      get_window_dc ddc(hwnd_);\r
+//      RECT rc;\r
+//      GetWindowRect(hwnd_,&rc);\r
+/*      POINT wnd_pos = {rc.left,rc.top};\r
+      SIZE  wnd_size = {width_,height_};\r
+  */\r
+      //BLENDFUNCTION blend;\r
+  //    blend.BlendOp = AC_SRC_OVER;\r
+  //    blend.BlendFlags = 0;\r
+  //    blend.SourceConstantAlpha = 128; // 不透明度(レイヤードウィンドウ全体のアルファ値)\r
+  //    blend.AlphaFormat = AC_SRC_ALPHA;\r
+      // デバイスコンテキストにおけるレイヤの位置\r
+      POINT po;\r
+      po.x = po.y = 0;\r
+      BOOL err;\r
+      err = BitBlt(ddc.get(),0,0,width_,height_,sdc,0,0,SRCCOPY);\r
+//      err = AlphaBlend(ddc.get(),0,0,width_,height_,sdc,0,0,width_,height_,blend);\r
+      //err = UpdateLayeredWindow(hwnd_, ddc.get(), &wnd_pos, &wnd_size, sdc, &po, RGB(255,0,0), &blend, ULW_ALPHA | ULW_COLORKEY );\r
+      BOOST_ASSERT(err == TRUE);\r
+      surface->ReleaseDC( NULL);\r
+      surface.Reset();\r
+      // OMステージに登録する\r
+      d3d_context_->OMSetRenderTargets( 1, view_.GetAddressOf(), depth_view_.Get() );\r
+    }\r
+\r
+  }\r
+\r
+ template <typename ProcType>\r
+  typename base_win32_window<ProcType>::result_t base_win32_window<ProcType>::on_dwm_composition_changed()\r
+  {\r
+    BOOL enabled;\r
+    DwmIsCompositionEnabled(&enabled);\r
+    if(enabled)\r
+    {\r
+      EnableBlurBehind(hwnd_);\r
+    }\r
+    return  std::is_same<proc_t,wndproc>::value?0:FALSE;\r
+  }\r
+  template struct base_win32_window<wndproc>;\r
+  template struct base_win32_window<dlgproc>;\r
+\r
+  //ID2D1FactoryPtr base_win32_window::factory() { return impl_->factory();};\r
+  //ID2D1HwndRenderTargetPtr base_win32_window::render_target() { return impl_->render_target();};\r
+  //IDWriteFactoryPtr base_win32_window::write_factory() {return impl_->write_factory();};\r
+\r
+  subclass_window::subclass_window(HWND hwnd) \r
+    : base_win32_window (\r
+    std::wstring(L""),std::wstring(L""),false,0,0\r
+    ),is_subclassed_(false)\r
+  {\r
+    attach(hwnd);\r
+  }\r
+\r
+  subclass_window::subclass_window()\r
+    : base_win32_window (\r
+    std::wstring(L""),std::wstring(L""),false,0,0\r
+    ),is_subclassed_(false)\r
+  {\r
+\r
+  }\r
+\r
+  subclass_window::~subclass_window()\r
+  {\r
+    detatch();\r
+  }\r
+\r
+  void subclass_window::attach(HWND hwnd)\r
+  {\r
+    if(is_subclassed_)\r
+      detatch();\r
+\r
+    hwnd_ = hwnd;\r
+    proc_backup_ = reinterpret_cast<WNDPROC>(::GetWindowLongPtrW(hwnd_,GWLP_WNDPROC));\r
+    SetWindowLongPtrW(hwnd_,GWLP_WNDPROC,reinterpret_cast<LONG_PTR>(thunk_proc_));\r
+    is_subclassed_ = true;\r
+  }\r
+\r
+  void subclass_window::detatch()\r
+  {\r
+    if(is_subclassed_)\r
+    {\r
+      SetWindowLongPtrW(hwnd_,GWLP_WNDPROC,reinterpret_cast<LONG_PTR>(proc_backup_));\r
+      is_subclassed_ = false;\r
+    }\r
+  }\r
+}\r
+\r
diff --git a/mfsample/sf_windows.h b/mfsample/sf_windows.h
new file mode 100644 (file)
index 0000000..546caa2
--- /dev/null
@@ -0,0 +1,707 @@
+#pragma once\r
+/*\r
+*/\r
+// Windows Header Files:\r
+#define XBYAK64\r
+#include "exception.h"\r
+#include "base_window.h"\r
+#include "dpi.h"\r
+#include "xbyak.h"\r
+#include "windows.h"\r
+#include "windowsx.h"\r
+#include "CommCtrl.h"\r
+#include <type_traits>\r
+#include "timer.h"\r
+//#include <boost/type_traits/is_same.hpp>\r
+// DLLのリンク\r
+#pragma comment(lib,"d2d1.lib")\r
+#pragma comment(lib,"winmm.lib")\r
+#pragma comment(lib,"dwrite.lib")\r
+#pragma comment(lib,"dwmapi.lib")\r
+\r
+//#include "input.h"\r
+\r
+\r
+// Direct Write\r
+\r
+_WRL_PTR_TYPEDEF(IDWriteFactory);\r
+_WRL_PTR_TYPEDEF(IDWriteGdiInterop);\r
+_WRL_PTR_TYPEDEF(IDWriteFontFace);\r
+_WRL_PTR_TYPEDEF(IDWriteFont);\r
+_WRL_PTR_TYPEDEF(IDWriteFontFamily);\r
+_WRL_PTR_TYPEDEF(IDWriteFontCollection);\r
+_WRL_PTR_TYPEDEF(IDWriteLocalizedStrings);\r
+_WRL_PTR_TYPEDEF(IDWriteTextFormat);\r
+_WRL_PTR_TYPEDEF(IDWriteTextLayout);\r
+_WRL_PTR_TYPEDEF(IDWriteFontFile);\r
+//_WRL_PTR_TYPEDEF(IDWriteFontFile);\r
+\r
+// Direct2D\r
+\r
+_WRL_PTR_TYPEDEF(ID2D1Factory);\r
+_WRL_PTR_TYPEDEF(ID2D1HwndRenderTarget);\r
+_WRL_PTR_TYPEDEF(ID2D1BitmapRenderTarget);\r
+_WRL_PTR_TYPEDEF(ID2D1GdiInteropRenderTarget);\r
+_WRL_PTR_TYPEDEF(ID2D1DCRenderTarget);\r
+_WRL_PTR_TYPEDEF(ID2D1PathGeometry);\r
+_WRL_PTR_TYPEDEF(ID2D1LinearGradientBrush);\r
+_WRL_PTR_TYPEDEF(ID2D1GradientStopCollection);\r
+_WRL_PTR_TYPEDEF(ID2D1SolidColorBrush);\r
+_WRL_PTR_TYPEDEF(ID2D1BitmapBrush);\r
+_WRL_PTR_TYPEDEF(ID2D1Bitmap);\r
+\r
+// WIC\r
+\r
+_WRL_PTR_TYPEDEF(IWICImagingFactory);\r
+_WRL_PTR_TYPEDEF(IWICBitmapDecoder);\r
+_WRL_PTR_TYPEDEF(IWICBitmapFrameDecode);\r
+_WRL_PTR_TYPEDEF(IWICStream);\r
+_WRL_PTR_TYPEDEF(IWICFormatConverter);\r
+_WRL_PTR_TYPEDEF(IWICBitmapScaler);\r
+_WRL_PTR_TYPEDEF(ITaskbarList3);\r
+\r
+// DXGI \r
+\r
+_WRL_PTR_TYPEDEF(IDXGISwapChain);\r
+_WRL_PTR_TYPEDEF(IDXGIFactory1);\r
+_WRL_PTR_TYPEDEF(IDXGIAdapter1);\r
+_WRL_PTR_TYPEDEF(IDXGIDevice1);\r
+_WRL_PTR_TYPEDEF(IDXGIKeyedMutex);\r
+_WRL_PTR_TYPEDEF(IDXGIObject);\r
+_WRL_PTR_TYPEDEF(IDXGIDeviceSubObject);\r
+_WRL_PTR_TYPEDEF(IDXGISurface1);\r
+_WRL_PTR_TYPEDEF(IDXGIOutput);\r
+//_WRL_PTR_TYPEDEF(IDXGI);\r
+//_WRL_PTR_TYPEDEF(IDXGI);\r
+\r
+// Direct3D\r
+\r
+_WRL_PTR_TYPEDEF(ID3D11Device);\r
+_WRL_PTR_TYPEDEF(ID3D11DeviceContext);\r
+_WRL_PTR_TYPEDEF(ID3D11RenderTargetView);\r
+_WRL_PTR_TYPEDEF(ID3D11DepthStencilView);\r
+_WRL_PTR_TYPEDEF(ID3D11VertexShader);\r
+_WRL_PTR_TYPEDEF(ID3D11PixelShader);\r
+_WRL_PTR_TYPEDEF(ID3D11InputLayout);\r
+_WRL_PTR_TYPEDEF(ID3D11Buffer);\r
+_WRL_PTR_TYPEDEF(ID3D11Texture2D);\r
+_WRL_PTR_TYPEDEF(ID3DBlob);\r
+_WRL_PTR_TYPEDEF(ID3D11ShaderResourceView);\r
+_WRL_PTR_TYPEDEF(ID3D11SamplerState);\r
+_WRL_PTR_TYPEDEF(ID3D11Resource);\r
+\r
+namespace sf{\r
+\r
+  /* inline template <class Exc = win32_error_exception> void throw_if_err<>()(HRESULT hr)\r
+  {\r
+  if(hr != S_OK){throw Exc(hr);}\r
+  };*/\r
+\r
+\r
+  ID2D1BitmapPtr load_bitmap_from_file(\r
+    ID2D1HwndRenderTargetPtr render_target,\r
+    IWICImagingFactoryPtr wic_factory,\r
+    std::wstring uri,\r
+    uint32_t destination_width = 0,\r
+    uint32_t destination_height = 0\r
+    );\r
+\r
+  /** WNDCLASSEXラッパクラス */\r
+  struct window_class_ex\r
+  {\r
+    window_class_ex(\r
+      const wchar_t*  menu_name ,\r
+      const std::wstring&  class_name ,\r
+      HINSTANCE   hInstance = NULL,\r
+      WNDPROC     lpfnWndProc = ::DefWindowProcW,\r
+      uint32_t        style = CS_HREDRAW | CS_VREDRAW,\r
+      int32_t     cbClsExtra  = 0,\r
+      int32_t     cbWndExtra = sizeof(LONG_PTR), \r
+      HICON       hIcon = ::LoadIcon(NULL,IDI_APPLICATION),\r
+      HCURSOR     hCursor = ::LoadCursor(NULL, IDC_ARROW),\r
+      HBRUSH      hbrBackground = ::CreateSolidBrush(0xff000000),\r
+      HICON       hIconSm = NULL\r
+      ) : is_register_(false)\r
+    {\r
+\r
+      if(::GetClassInfoExW(hInstance,class_name.c_str(),&wndclass_) == 0)\r
+      {\r
+        if(::GetLastError() == ERROR_CLASS_DOES_NOT_EXIST)\r
+        { \r
+          ::ZeroMemory(&wndclass_,sizeof(wndclass_));\r
+          wndclass_.lpszMenuName = (LPCWSTR)menu_name;\r
+          wndclass_.lpszClassName = class_name.c_str();\r
+          wndclass_.cbSize = sizeof(::WNDCLASSEXW);\r
+          wndclass_.cbWndExtra = cbWndExtra;\r
+          wndclass_.hInstance = hInstance;\r
+          wndclass_.lpfnWndProc = lpfnWndProc;\r
+          wndclass_.style = style;\r
+          wndclass_.cbClsExtra = cbClsExtra;\r
+          wndclass_.hIcon = hIcon;\r
+          wndclass_.hCursor = hCursor;\r
+          wndclass_.hbrBackground = hbrBackground;\r
+          wndclass_.hIconSm = hIconSm;\r
+          atom_ = ::RegisterClassExW(&wndclass_) ;\r
+          BOOST_ASSERT(atom_ != 0);\r
+          is_register_ = true;\r
+        } else {\r
+          throw win32_error_exception();\r
+        }\r
+      } else {\r
+        is_register_ = false;\r
+      }\r
+    };\r
+\r
+    ~window_class_ex()\r
+    {\r
+      if(is_register_){\r
+        ::UnregisterClassW(wndclass_.lpszClassName,wndclass_.hInstance);\r
+      }\r
+    }\r
+\r
+  private:\r
+    bool is_register_;\r
+    ATOM atom_;\r
+    ::WNDCLASSEXW wndclass_;\r
+  };\r
+\r
+  struct get_dc {\r
+    get_dc(HWND hwnd) : hwnd_(hwnd),hdc_(GetDC(hwnd)) {}\r
+    HDC get(){return hdc_;}\r
+    ~get_dc(){::ReleaseDC(hwnd_,hdc_);}\r
+  private:\r
+    HDC hdc_;\r
+    HWND hwnd_;\r
+  };\r
+\r
+  struct get_window_dc {\r
+    get_window_dc(HWND hwnd) : hwnd_(hwnd),hdc_(GetWindowDC(hwnd)) {}\r
+    HDC get(){return hdc_;}\r
+    ~get_window_dc(){::ReleaseDC(hwnd_,hdc_);}\r
+  private:\r
+    HDC hdc_;\r
+    HWND hwnd_;\r
+  };\r
+\r
+  struct compatible_dc {\r
+    compatible_dc(HDC hdc) : hdc_(::CreateCompatibleDC(hdc)){}; \r
+    ~compatible_dc(){::DeleteDC(hdc_);};\r
+    HDC get() { return hdc_;};\r
+  private:\r
+    HDC hdc_;\r
+  };\r
+\r
+  struct ref_dc {\r
+    ref_dc(HDC& hdc) : hdc_(hdc) {};\r
+    ~ref_dc(){};\r
+    HDC get() { return hdc_;};\r
+  private:\r
+    HDC& hdc_;\r
+  };\r
+\r
+  struct d2_dc {\r
+    d2_dc(ID2D1GdiInteropRenderTargetPtr& ptr,D2D1_DC_INITIALIZE_MODE mode) :hdc_(0),ptr_(ptr)\r
+    {\r
+      hr_ = ptr->GetDC(mode,&hdc_);\r
+    };\r
+    ~d2_dc(){ptr_->ReleaseDC(NULL);};\r
+    HDC get() { return hdc_;};\r
+  private:\r
+    HRESULT hr_;\r
+    HDC hdc_;\r
+    ID2D1GdiInteropRenderTargetPtr& ptr_;\r
+  };\r
+\r
+  template <typename Holder>\r
+  struct device_context\r
+  {\r
+    explicit device_context(Holder* holder) : holder_(holder){};\r
+    ~device_context() {}\r
+    operator HDC(){return holder_->get();}\r
+  private:\r
+    std::unique_ptr<Holder> holder_;\r
+  };\r
+\r
+  //struct handle_holder : boost::noncopyable\r
+  //{\r
+  //  explicit handle_holder(HANDLE handle) : handle_(handle) {};\r
+  //  ~handle_holder(){if(handle_) ::CloseHandle(handle_);}\r
+  //  operator HANDLE(){return handle_;}\r
+  //private:\r
+  //  HANDLE handle_;\r
+  //};\r
+\r
+\r
+  struct HBITMAP_deleter {\r
+    typedef HBITMAP pointer;\r
+    void operator ()(HBITMAP handle) {\r
+      if (handle) {\r
+        ::DeleteObject(handle);\r
+      }\r
+    }\r
+  };\r
+\r
+  //template <typename Handle,typename Handle_Deleter>\r
+  //struct handle_holder {\r
+  //  typedef boost::unique_ptr<Handle,Handle_Deleter> holder_type;\r
+  //  handle_holder(Handle handle) : holder_(handle) {}\r
+  //  operator Handle(){return holder_->get();}\r
+  //private:\r
+  //  holder_type holder_;\r
+  //};\r
+\r
+  typedef std::unique_ptr<HBITMAP,HBITMAP_deleter> bitmap_holder;\r
+\r
+  typedef device_context<d2_dc> d2_dc_type;\r
+\r
+  struct paint_struct \r
+  {\r
+    paint_struct(HWND hwnd) : hwnd_(hwnd)\r
+    {\r
+      ::BeginPaint(hwnd,&paintstruct_);\r
+    }\r
+    ~paint_struct() {::EndPaint(hwnd_,&paintstruct_);}\r
+    PAINTSTRUCT* operator->(){return &paintstruct_;}\r
+  private:\r
+    HWND hwnd_;\r
+    PAINTSTRUCT paintstruct_;\r
+  };\r
+\r
+  // GDI オブジェクト管理テンプレート\r
+  template <class GdiObject> \r
+  struct gdi_object: boost::noncopyable\r
+  {\r
+    explicit gdi_object(GdiObject obj) : gdiobj_(obj) {}\r
+    ~gdi_object(){::DeleteObject(gdiobj_);}\r
+    operator GdiObject(){return gdiobj_;}\r
+  private:\r
+    GdiObject gdiobj_;\r
+  };\r
+\r
+  //\r
+  struct select_object \r
+  {\r
+    select_object(HDC dc,HGDIOBJ o) : dc_(dc),o_(::SelectObject(dc,o)) {}\r
+    ~select_object(){::SelectObject(dc_,o_);}\r
+  private:\r
+    HDC dc_;\r
+    HGDIOBJ o_;\r
+  };\r
+\r
+  // Direct2D BeginDrawヘルパ関数\r
+  template <typename T >\r
+  struct begin_draw\r
+  {\r
+    typedef std::function<void(HRESULT hr)> err_handler_type;\r
+\r
+    begin_draw(T& render_target,err_handler_type& handler)\r
+      : render_target_(render_target) ,\r
+      is_end_(false),handler_(handler)\r
+    {render_target->BeginDraw();}\r
+\r
+    ~begin_draw(){ \r
+      HRESULT hr = S_OK;\r
+      hr = render_target_->EndDraw();\r
+      if( hr != S_OK)\r
+      {\r
+        handler_(hr);\r
+      }\r
+    }\r
+  private:\r
+    T& render_target_;\r
+    err_handler_type handler_;\r
+  };\r
+\r
+  struct mouse\r
+  {\r
+    mouse() : x_(0.0f),y_(0.0f),left_button_(false),middle_button_(false),right_button_(false){}\r
+  private:\r
+    float x_,y_;\r
+    bool left_button_,middle_button_,right_button_;\r
+  };\r
+\r
+\r
+  // ウィンドウプロシージャの識別用クラス\r
+  struct wndproc \r
+  {\r
+    typedef WNDPROC proc_type;\r
+    typedef LRESULT return_type;\r
+    static inline return_type def_wnd_proc(HWND hwnd,uint32_t message, WPARAM wParam, LPARAM lParam) \r
+    {\r
+      return ::DefWindowProcW(hwnd,message,wParam,lParam);\r
+    }\r
+  };\r
+\r
+  // ダイアログプロシージャの識別用クラス\r
+  struct dlgproc\r
+  {\r
+    typedef DLGPROC proc_type;\r
+    typedef INT_PTR return_type;\r
+    static inline return_type def_wnd_proc(HWND hwnd,uint32_t message, WPARAM wParam, LPARAM lParam)\r
+    {\r
+      return FALSE;\r
+    }\r
+  };\r
+\r
+  /** window ベースクラス */\r
+  template <typename ProcType = wndproc>\r
+  struct base_win32_window : public base_window \r
+  {\r
+    typedef ProcType proc_t;\r
+    typedef typename proc_t::return_type result_t;\r
+//    typedef proc_t::return_type result_t;\r
+\r
+    operator HWND() const {return hwnd_;};\r
+\r
+    virtual void * raw_handle() const {return hwnd_;};\r
+    //    virtual void show(uint32_t show_flag);\r
+\r
+    virtual void show() {\r
+      ::ShowWindow(hwnd_,SW_SHOW);\r
+      ::GetWindowPlacement(hwnd_,&wp_);\r
+    }\r
+\r
+    // Window を画面から隠す\r
+    virtual bool is_show() {\r
+      return ( wp_.showCmd == SW_SHOWMAXIMIZED \r
+        || wp_.showCmd == SW_SHOWMINIMIZED\r
+        || wp_.showCmd == SW_SHOWNORMAL );\r
+    };\r
+\r
+    //\r
+    virtual void hide()\r
+    {\r
+      ::ShowWindow(hwnd_,SW_HIDE);\r
+      ::GetWindowPlacement(hwnd_,&wp_);\r
+    };\r
+\r
+    virtual void text(std::wstring& text)\r
+    {\r
+      ::SetWindowTextW(*this,text.c_str());\r
+    };\r
+\r
+    virtual void send_message(uint32_t message,uint32_t wparam,uint32_t lparam )\r
+    {\r
+      ::SendNotifyMessage(hwnd_,message,wparam,lparam);\r
+    }\r
+\r
+    virtual void post_message(uint32_t message,uint32_t wparam,uint32_t lparam )\r
+    {\r
+      ::PostMessage(hwnd_,message,wparam,lparam);\r
+    }\r
+\r
+    virtual void message_box(const std::wstring& text,const std::wstring& caption,uint32_t type = MB_OK)\r
+    {\r
+      ::MessageBox(hwnd_,text.c_str(),caption.c_str(),type);\r
+    }\r
+\r
+    virtual void update();\r
+\r
+    virtual void create_device_independent_resources();\r
+    virtual void create_device();\r
+    virtual void create_swapchain_dependent_resources();\r
+\r
+    virtual void discard_swapchain_dependent_resources();\r
+    virtual void discard_device();\r
+    virtual void discard_device_independant_resources();\r
+\r
+  protected:\r
+\r
+    base_win32_window(\r
+      const std::wstring& title,\r
+      const std::wstring& name,bool fit_to_display,\r
+      float width,float height);\r
+\r
+\r
+    ~base_win32_window();\r
+\r
+    void register_class (\r
+      const wchar_t* menu_name,\r
+      uint32_t style, \r
+      int32_t     cbClsExtra  = 0,\r
+      int32_t     cbWndExtra  = sizeof(LONG_PTR),\r
+      HICON       hIcon = ::LoadIcon(NULL,IDI_APPLICATION),\r
+      HCURSOR     hCursor = ::LoadCursor(NULL, IDC_ARROW),\r
+      HBRUSH      hbrBackground = ::CreateSolidBrush(0xff000000),\r
+      HICON       hIconSm = NULL\r
+      );               \r
+\r
+    /** デフォルト設定 */\r
+    void register_class();\r
+    void create_window(HWND parent = NULL);\r
+\r
+    void calc_client_size()\r
+    {\r
+      //クライアント領域の現在の幅、高さを求める\r
+      RECT rc;\r
+      GetClientRect( hwnd_, &rc );\r
+      client_width_ = rc.right - rc.left;\r
+      client_height_ = rc.bottom - rc.top;\r
+    }\r
+  public:\r
+    // SetWindowLong API\r
+    void set_long(int index,long data)\r
+    {\r
+      SetLastError(0);\r
+      if(::SetWindowLongW(hwnd_,index,data) == 0)\r
+      {\r
+        long err = 0;\r
+        if( (err = GetLastError()) != 0){\r
+          SetLastError(err);\r
+          throw sf::win32_error_exception();\r
+        }\r
+      };\r
+    }\r
+\r
+    void set_pos(\r
+      HWND hwnd_insert_after,  // 配置順序のハンドル\r
+      int x,                 // 横方向の位置\r
+      int y,                 // 縦方向の位置\r
+      int cx,                // 幅\r
+      int cy,                // 高さ\r
+      UINT flags            // ウィンドウ位置のオプション\r
+      )\r
+    {\r
+      BOOL res = SetWindowPos(hwnd_,hwnd_insert_after,x,y,cx,cy,flags);\r
+      if(!res)\r
+      {\r
+        throw win32_error_exception();\r
+      }\r
+    }\r
+\r
+    bool invalidate_rect(bool erase = false,const RECT * rect_ptr = 0)\r
+    {\r
+      return ::InvalidateRect(*this,rect_ptr,erase) == TRUE;\r
+    }\r
+\r
+    void enable_control(uint32_t id,bool enable)\r
+    {\r
+      ::EnableWindow(GetDlgItem(hwnd_,id),enable?TRUE:FALSE);\r
+    }\r
+\r
+    void enable_control(HWND hwnd,uint32_t id,bool enable)\r
+    {\r
+      ::EnableWindow(GetDlgItem(hwnd,id),enable?TRUE:FALSE);\r
+    };\r
+\r
+    virtual result_t window_proc(HWND hwnd,uint32_t message, WPARAM wParam, LPARAM lParam);\r
+    virtual result_t other_window_proc(HWND hwnd,uint32_t message, WPARAM wParam, LPARAM lParam)\r
+    {\r
+      return proc_t::def_wnd_proc(hwnd,message,wParam,lParam);\r
+    };\r
+\r
+    // デフォルトウィンドウメッセージハンドラ\r
+    virtual result_t on_nccreate(CREATESTRUCT *p) ;//{ return std::is_same<proc_t,wndproc>::value?1:FALSE;}\r
+    virtual result_t on_create(CREATESTRUCT *p); //{ return std::is_same<proc_t,wndproc>::value?0:FALSE;}\r
+    virtual result_t on_init_dialog(HWND default_focus_ctrl,LPARAM data) {return TRUE;}\r
+    virtual result_t on_size(uint32_t flag,uint32_t width,uint32_t height);//{return std::is_same<proc_t,wndproc>::value?0:FALSE;    }\r
+    //virtual LRESULT \r
+    virtual result_t on_paint();\r
+    virtual result_t on_display_change(uint32_t bpp,uint32_t h_resolution,uint32_t v_resolution) {         invalidate_rect();return std::is_same<proc_t,wndproc>::value?0:FALSE;}\r
+    virtual result_t on_erase_backgroud(HDC dc) {return std::is_same<proc_t,wndproc>::value?1:TRUE;}\r
+    virtual result_t on_hscroll(uint32_t state,uint32_t position,HWND ctrl_hwnd) {return std::is_same<proc_t,wndproc>::value?0:FALSE;}\r
+    virtual result_t on_vscroll(uint32_t state,uint32_t position,HWND ctrl_hwnd) {return std::is_same<proc_t,wndproc>::value?0:FALSE;}\r
+    virtual result_t on_left_mouse_button_down(uint32_t mouse_key,int x,int y ) { return std::is_same<proc_t,wndproc>::value?0:FALSE; }\r
+    virtual result_t on_left_mouse_button_up(uint32_t mouse_key,int x,int y) { return std::is_same<proc_t,wndproc>::value?0:FALSE; }\r
+    virtual result_t on_left_mouse_button_double_click(uint32_t mouse_key,int x,int y) { return std::is_same<proc_t,wndproc>::value?0:FALSE; }\r
+    virtual result_t on_mouse_move(uint32_t mouse_key,int x,int y) {return std::is_same<proc_t,wndproc>::value?0:FALSE; }\r
+    virtual result_t on_mouse_wheel(uint32_t mouse_key,int delta,int x,int y) {  return std::is_same<proc_t,wndproc>::value?0:FALSE; }\r
+    //virtual bool on_mouse_enter(uint32_t mouse_key,int x,int y) {  return false; }\r
+    virtual result_t on_mouse_leave() {  return std::is_same<proc_t,wndproc>::value?0:FALSE; }\r
+    virtual result_t on_destroy(){   \r
+      //::PostQuitMessage(0);\r
+      return std::is_same<proc_t,wndproc>::value?0:FALSE;\r
+    }\r
+\r
+    virtual result_t on_close()\r
+    {\r
+      discard_device();\r
+      // Windowの破棄\r
+      BOOL ret(::DestroyWindow(hwnd_));\r
+      BOOST_ASSERT(ret != 0);\r
+//      return TRUE;\r
+      return std::is_same<proc_t,wndproc>::value?1:TRUE;\r
+    }\r
+\r
+    virtual result_t on_set_cursor() { return std::is_same<proc_t,wndproc>::value?0:FALSE; }\r
+    virtual result_t on_key_down(uint32_t vkey,uint32_t ext_key,uint32_t repeat) { return std::is_same<proc_t,wndproc>::value?0:FALSE; }\r
+    virtual result_t on_key_up(uint32_t vkey,uint32_t ext_key,uint32_t repeat) { return std::is_same<proc_t,wndproc>::value?0:FALSE; }\r
+    virtual result_t on_app_command(uint32_t command,uint32_t device,uint32_t keystate) {return std::is_same<proc_t,wndproc>::value?0:FALSE;}\r
+    virtual result_t on_command(uint32_t wparam, uint32_t lparam)  { return std::is_same<proc_t,wndproc>::value?0:FALSE; } \r
+    virtual result_t on_timer(uint32_t timer_id)  {\r
+      //::InvalidateRect(hwnd_,NULL,FALSE);\r
+      render();\r
+      return std::is_same<proc_t,wndproc>::value?0:FALSE; \r
+    } \r
+    virtual result_t on_notify(NMHDR* nmhdr)  { return std::is_same<proc_t,wndproc>::value?0:FALSE; }\r
+    virtual result_t on_dwm_composition_changed();\r
+    virtual void render();\r
+  protected:\r
+    void get_dxgi_information();\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
+      return ptr->window_proc(ptr->hwnd_,message,wParam,lParam);\r
+    };\r
+\r
+    // thisとhwndをつなぐthunkクラス\r
+    struct hwnd_this_thunk : public Xbyak::CodeGenerator {\r
+      hwnd_this_thunk(base_win32_window* impl,typename proc_t::proc_type proc)\r
+      {\r
+        // rcxにhwndが格納されているので、それをimpl->hwndに保存\r
+//        mov(ptr[&(impl->hwnd_)],rcx); // <-- エラー発生部分\r
+               mov(rax,(size_t)&impl->hwnd_);  // <-- 訂正\r
+        mov(ptr[rax],rcx);                             // <-- 訂正\r
+        // 代わりにthisのアドレスをrcxに格納\r
+        mov(rcx,(LONG_PTR)impl);\r
+        // r10にproc(Window プロシージャ)へのアドレスを格納\r
+        mov(r10,(LONG_PTR)proc);\r
+        // Window プロシージャへへジャンプ\r
+        jmp(r10);\r
+      }\r
+    };\r
+\r
+    void update_window_size()\r
+    {\r
+      RECT r;\r
+      GetWindowRect(hwnd_,&r);\r
+      width_ = r.right - r.left;\r
+      height_ = r.bottom - r.top;\r
+    }\r
+\r
+    void init_view_matrix();\r
+\r
+    HWND hwnd_;\r
+    hwnd_this_thunk thunk_;\r
+    std::wstring title_;\r
+    std::wstring name_;\r
+    float width_,height_;\r
+    bool fit_to_display_;\r
+    std::shared_ptr<sf::window_class_ex> wnd_class_;\r
+    typename proc_t::proc_type thunk_proc_;\r
+    dpi dpi_;\r
+    WINDOWPLACEMENT wp_;\r
+    bool init_;\r
+\r
+    //ID2D1FactoryPtr factory_;\r
+    //ID2D1HwndRenderTargetPtr render_target_;\r
+    //IDWriteFactoryPtr write_factory_;\r
+    //IWICImagingFactoryPtr wic_imaging_factory_;\r
+    //IDWriteTextFormatPtr write_text_format_;\r
+\r
+    IDXGIFactory1Ptr dxgi_factory_;\r
+    IDXGIAdapter1Ptr adapter_;\r
+    IDXGIOutputPtr output_;\r
+    ID3D11DevicePtr d3d_device_;\r
+    ID3D11DeviceContextPtr d3d_context_;\r
+    ID3D11Texture2DPtr texture_;\r
+    ID3D11RenderTargetViewPtr view_;\r
+    ID3D11Texture2DPtr depth_texture_;\r
+    ID3D11DepthStencilViewPtr depth_view_;\r
+    ID3D11VertexShaderPtr v_shader_;\r
+    ID3D11InputLayoutPtr input_layout_;\r
+    ID3D11PixelShaderPtr p_shader_;\r
+    ID3D11BufferPtr v_buffer_;\r
+    ID3D11BufferPtr i_buffer_;\r
+    ID3D11BufferPtr cb_never_changes_;\r
+    ID3D11BufferPtr cb_change_on_resize_;\r
+    ID3D11BufferPtr cb_changes_every_frame_;\r
+    ID3D11ShaderResourceViewPtr shader_res_view_;\r
+    ID3D11SamplerStatePtr sampler_state_;\r
+    ID3D11Texture2DPtr back_buffer_;\r
+    \r
+    //ID3D11SamplerStatePtr cube_sampler_state_;\r
+    //ID3D11Texture2DPtr cube_texture_;\r
+    //ID3D11Texture2DPtr cube_depth_texture_;\r
+    //ID3D11ShaderResourceViewPtr cube_shader_res_view_;\r
+    //ID3D11RenderTargetViewPtr cube_view_;\r
+    //ID3D11DepthStencilViewPtr cube_depth_view_;\r
+\r
+    DXGI_MODE_DESC actual_desc_;\r
+    //IDXGISwapChainPtr swap_chain_;\r
+    std::wstring dxgi_info_;\r
+\r
+       \r
+       \r
+    DirectX::XMMATRIX                            mat_world_;\r
+    DirectX::XMMATRIX                            mat_view_;\r
+    DirectX::XMMATRIX                            mat_projection_;\r
+    DirectX::XMMATRIX                            cube_mat_projection_;\r
+       \r
+    DirectX::XMFLOAT4                            mesh_color_;\r
+    float client_width_,client_height_;\r
+\r
+    timer timer_;\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
+  typedef base_win32_window<dlgproc> base_win32_dialog_t;\r
+\r
+  /// サブクラスウィンドウ\r
+  struct subclass_window : public base_win32_window_t\r
+  {\r
+    subclass_window(HWND hwnd);\r
+    subclass_window();\r
+    void attach(HWND hwnd);\r
+    void detatch();\r
+    ~subclass_window();\r
+    virtual result_t window_proc(HWND hwnd,uint32_t message, WPARAM wParam, LPARAM lParam) \r
+    {\r
+      return CallWindowProc(proc_backup_,hwnd,message,wParam,lParam);\r
+    };\r
+  protected:\r
+    bool is_subclassed_;\r
+    WNDPROC proc_backup_;\r
+  };\r
+\r
+  struct av_mm_thread_characteristics\r
+  {\r
+    av_mm_thread_characteristics(std::wstring& str) : task_name_(str)\r
+    {\r
+      handle_ = ::AvSetMmThreadCharacteristicsW(str.c_str(),(LPDWORD)&task_index_);\r
+    }\r
+\r
+    bool set_priority(AVRT_PRIORITY p){return (::AvSetMmThreadPriority(handle_,p) == TRUE);}\r
+\r
+    ~av_mm_thread_characteristics()\r
+    {\r
+      ::AvRevertMmThreadCharacteristics(handle_);\r
+    }\r
+\r
+  private:\r
+    std::wstring task_name_;\r
+    uint32_t task_index_;\r
+    HANDLE handle_;\r
+  };\r
+\r
+  struct widget\r
+  {\r
+    void draw();\r
+    float x_,y_;\r
+  };\r
+\r
+  typedef sf::begin_draw<ID2D1BitmapRenderTargetPtr> begin_draw_bitmap;\r
+  typedef sf::begin_draw<ID2D1HwndRenderTargetPtr> begin_draw_hwnd;\r
+\r
+}
\ No newline at end of file
diff --git a/mfsample/singleton.h b/mfsample/singleton.h
new file mode 100644 (file)
index 0000000..0ca7b46
--- /dev/null
@@ -0,0 +1,55 @@
+#pragma once
+/*
+  ==============================================================================
+
+   This file is part of the async
+   Copyright 2005-7 by Satoshi Fujiwara.
+
+   async can be redistributed and/or modified under the terms of the
+   GNU General Public License, as published by the Free Software Foundation;
+   either version 2 of the License, or (at your option) any later version.
+
+   async is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with async; if not, visit www.gnu.org/licenses or write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
+   Boston, MA 02111-1307 USA
+
+  ==============================================================================
+*/
+/** @file
+ *  @brief 
+ *  @author S.F. (Satoshi Fujiwara)
+ */
+#include <boost/thread.hpp>
+#include <boost/shared_ptr.hpp>
+namespace sf {
+    template<typename BaseClass,template <class> class PointerType = std::shared_ptr > struct singleton 
+    {
+        typedef PointerType<BaseClass> ptr;
+        friend  BaseClass;
+        static ptr& instance()
+        {
+            boost::call_once(init,flag_);
+            return instance_;
+        };
+
+
+        singleton(){};
+    private:
+        singleton(const singleton& );
+               static void init(){instance_.reset(new BaseClass);};
+        static PointerType<BaseClass> instance_;
+        static boost::once_flag flag_;
+    };
+
+    template<class BaseClass,template <class> class PointerType> boost::once_flag singleton<BaseClass,PointerType>::flag_ = BOOST_ONCE_INIT;
+    template<class BaseClass,template <class> class PointerType> PointerType<BaseClass> singleton<BaseClass,PointerType>::instance_;
+};
+
+
diff --git a/mfsample/stdafx.cpp b/mfsample/stdafx.cpp
new file mode 100644 (file)
index 0000000..5da86af
--- /dev/null
@@ -0,0 +1,11 @@
+// stdafx.cpp : 標準インクルードのみを含むソース ファイルです。\r
+// STed2.pch は、プリコンパイル済みヘッダーになります。\r
+//  stdafx.obj にはプリコンパイル型情報が含まれます。\r
+\r
+#include "stdafx.h"\r
+// TODO: このファイルではなく、STDAFX.H で必要な\r
+// 追加ヘッダーを参照してください。\r
+#pragma comment(lib, "winmm.lib")\r
+#pragma comment(lib, "Avrt.lib")\r
+#pragma comment(lib, "Mmdevapi.lib")\r
+\r
diff --git a/mfsample/stdafx.h b/mfsample/stdafx.h
new file mode 100644 (file)
index 0000000..49c1ccf
--- /dev/null
@@ -0,0 +1,153 @@
+// stdafx.h : 標準のシステム インクルード ファイルのインクルード ファイル、または\r
+// 参照回数が多く、かつあまり変更されない、プロジェクト専用のインクルード ファイル\r
+// を記述します。\r
+//\r
+\r
+\r
+#pragma once\r
+#include <SDKDDKVer.h>\r
+\r
+#ifndef UNICODE\r
+#define UNICODE\r
+#endif\r
+// STL\r
+\r
+#define DIRECTINPUT_VERSION 0x0800\r
+//#define BOOST_ALL_NO_LIB\r
+\r
+#include <stdint.h>\r
+#include <tchar.h>\r
+#include <iostream>\r
+#include <fstream>\r
+#include <exception>\r
+#include <memory>\r
+#include <string>\r
+#include <map>\r
+#include <locale>\r
+#include <fstream>\r
+#include <algorithm>\r
+#include <functional>\r
+#include <thread>\r
+\r
+// Boost\r
+#include <boost/archive/xml_woarchive.hpp>\r
+#include <boost/archive/xml_wiarchive.hpp>\r
+//#include <boost/archive/text_woarchive.hpp>\r
+//#include <boost/archive/text_wiarchive.hpp>\r
+//#include <boost/archive/text_oarchive.hpp>\r
+//#include <boost/archive/text_iarchive.hpp>\r
+//#include <boost/archive/binary_woarchive.hpp>\r
+//#include <boost/archive/binary_wiarchive.hpp>\r
+//#include <boost/archive/binary_oarchive.hpp>\r
+//#include <boost/archive/binary_iarchive.hpp>\r
+\r
+#include <boost/serialization/export.hpp>\r
+//#include <boost/serialization/is_abstract.hpp>\r
+#include <boost/serialization/version.hpp>\r
+#include <boost/serialization/serialization.hpp>\r
+#include <boost/serialization/split_member.hpp>\r
+#include <boost/serialization/string.hpp>\r
+#include <boost/serialization/shared_ptr.hpp>\r
+#include <boost/serialization/vector.hpp>\r
+#include <boost/serialization/nvp.hpp>\r
+#include <boost/serialization/void_cast.hpp>\r
+\r
+#include <boost/scoped_ptr.hpp> \r
+#include <boost/scoped_array.hpp> \r
+#include <boost/shared_ptr.hpp> \r
+#include <boost/shared_array.hpp> \r
+#include <boost/intrusive_ptr.hpp>\r
+#include <boost/format.hpp>\r
+#include <boost/lexical_cast.hpp>\r
+#include <boost/array.hpp>\r
+//#include <boost/thread.hpp>\r
+#include <boost/optional.hpp>\r
+#include <boost/bind.hpp>\r
+#include <boost/function.hpp>\r
+#include <boost/variant.hpp>\r
+#include <boost/any.hpp>\r
+#include <boost/signals2.hpp>\r
+#include <boost/tuple/tuple.hpp>\r
+#include <boost/ptr_container/ptr_container.hpp>\r
+//#include <boost/thread/condition.hpp>\r
+//#include <boost/serialization/ptr_vector.hpp>\r
+#include <boost/ptr_container/ptr_array.hpp>\r
+#include <boost/ptr_container/serialize_ptr_container.hpp>\r
+//#include "serialization.h"\r
+#include <boost/filesystem/path.hpp>\r
+#include <boost/filesystem/operations.hpp>\r
+#include <boost/filesystem/convenience.hpp>\r
+#include <boost/filesystem/fstream.hpp>\r
+#include "sf_com.h"\r
+//#include <d3d10_1.h>\r
+//#include <d3d10.h>\r
+//#include <d3d11.h>\r
+//#include <d3dx10.h>\r
+//#include <d3dx11.h>\r
+#include "dinput.h"\r
+#include <wincodec.h>\r
+#include <windows.h>\r
+#include <windowsx.h>\r
+#include <wincodec.h>\r
+#include <wincodecsdk.h>\r
+\r
+#include <comdef.h>\r
+#include "avrt.h"\r
+#include "mmsystem.h"\r
+\r
+// Direct Input\r
+\r
+#include "dinput.h"\r
+\r
+\r
+// DXGI\r
+\r
+#include "dxgi.h"\r
+\r
+#include "d3d11_1.h"\r
+#include <d3d11shader.h>\r
+#include <DDSTextureLoader.h>\r
+//#include "d3dx11.h"\r
+//#include <d3dx11effect.h>\r
+//#include <d3dxGlobal.h>\r
+#include <d3dcompiler.h>\r
+#include "DirectXMath.h"\r
+//#include <xnamath.h>\r
+\r
+// Direct2D\r
+\r
+#include <d2d1_1.h>\r
+#include <d2d1helper.h>\r
+\r
+// Direct Write\r
+\r
+#include <dwrite.h>\r
+\r
+// DWM\r
+\r
+#include "dwmapi.h" \r
+#include "Shobjidl.h"\r
+\r
+#include <wincodec.h>\r
+#include <wincodecsdk.h>\r
+\r
+#include "exception.h"\r
+//#include "singleton.h"\r
+//#include "code_converter.h"\r
+//#include "logger.h"\r
+\r
+\r
+// TODO: プログラムに必要な追加ヘッダーをここで参照してください。\r
+#include "code_converter.h"\r
+#include "logger.h"\r
+#include "dout.h"\r
+//#include "dxerr.h"\r
+#include <wrl.h>\r
+#using <windows.winmd>\r
+#using <platform.winmd>\r
+#include <concrt.h>\r
+#include <ppl.h>\r
+#include <ppltasks.h>\r
+#include <agents.h>\r
+\r
+#define _WRL_PTR_TYPEDEF(x) typedef Microsoft::WRL::ComPtr<x> x ## Ptr\r
diff --git a/mfsample/tab_dialog.cpp b/mfsample/tab_dialog.cpp
new file mode 100644 (file)
index 0000000..424b85c
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+==============================================================================
+
+Copyright 2005-11 by Satoshi Fujiwara.
+
+async can be redistributed and/or modified under the terms of the
+GNU General Public License, as published by the Free Software Foundation;
+either version 2 of the License, or (at your option) any later version.
+
+async is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with async; if not, visit www.gnu.org/licenses or write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
+Boston, MA 02111-1307 USA
+
+==============================================================================
+*/
+/* ToDo
+
+TODO: リサイズに対応する
+
+*/
+
+#include "stdafx.h"
+#include "resource.h"
+#define BOOST_ASSIGN_MAX_PARAMS 7
+#include <boost/assign.hpp>
+#include <boost/assign/ptr_list_of.hpp>
+#include <boost/assign/ptr_list_inserter.hpp>
+#include <boost/foreach.hpp>
+
+#if _DEBUG
+#define _CRTDBG_MAP_ALLOC
+#include <crtdbg.h>
+#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
+#endif
+
+#include "sf_windows.h"
+#include "tab_dialog.h"
+#include "CommDlg.h"
+#include "icon.h"
+#include "timer.h"
+#include "exception.h"
+#include "application.h"
+
+#define THROW_IFERR(hres) \
+  if (FAILED(hres)) { throw sf::win32_error_exception(hres); }
+
+#ifndef HINST_THISCOMPONENT
+EXTERN_C IMAGE_DOS_HEADER __ImageBase;
+#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase)
+#endif
+
+namespace sf 
+{
+    tab_dialog_base::tab_dialog_base(sf::base_window& parent_window,HWND tab_hwnd,int tab_id,const std::wstring& menu_name,const std::wstring& name,HINSTANCE inst,LPCTSTR temp)
+      : base_win32_dialog_t(menu_name,name,false,0,0),parent_window_(parent_window)
+      ,tab_hwnd_(tab_hwnd),tab_id_(tab_id),inst_(inst),temp_(temp)
+    {
+
+    }
+
+    void tab_dialog_base::create()
+    {
+      hwnd_ =  CreateDialogW(inst_,temp_,(HWND)parent_window_.raw_handle(),thunk_proc_);
+      BOOST_ASSERT(hwnd_ != NULL);
+      if(hwnd_ == NULL)
+      {
+        throw win32_error_exception();
+      }
+
+      resize();
+    }
+
+    void tab_dialog_base::resize()
+    {
+      
+      DWORD dwDlgBase = GetDialogBaseUnits();
+      int cxMargin = LOWORD(dwDlgBase) / 4; 
+      int cyMargin = HIWORD(dwDlgBase) / 8;
+      RECT rci;
+      TabCtrl_GetItemRect(tab_hwnd_,0,&rci);
+      RECT r;
+      GetClientRect(tab_hwnd_,&r);
+      RECT rw;
+      GetWindowRect(tab_hwnd_,&rw);
+      POINT pt = {rw.left,rw.top + rci.bottom};
+      ScreenToClient((HWND)parent_window_.raw_handle(),&pt);
+
+      set_pos(HWND_TOP,
+        pt.x + cxMargin,
+        pt.y + cyMargin,
+        r.right - cxMargin * 2 - 1,
+        r.bottom - rci.bottom - cyMargin * 2 - 1
+        ,SWP_NOZORDER 
+        );
+    }
+}
+
diff --git a/mfsample/tab_dialog.h b/mfsample/tab_dialog.h
new file mode 100644 (file)
index 0000000..de3d019
--- /dev/null
@@ -0,0 +1,34 @@
+#pragma once\r
+/*\r
+*/\r
+// Windows Header Files:\r
+#include "sf_windows.h"\r
+#include "icon.h"\r
+#include "base_window.h"\r
+#include "taskbar.h"\r
+\r
+namespace sf\r
+{\r
+\r
+  struct tab_dialog_base;\r
+  typedef std::shared_ptr<tab_dialog_base> tab_dialog_ptr;\r
+\r
+  /** toplevel ウィンドウクラス */\r
+  /* このクラスは、create_tab_dialog 関数からのみ生成可能 */\r
+  struct tab_dialog_base : public base_win32_dialog_t\r
+  {\r
+    tab_dialog_base(sf::base_window& parent_window,HWND tab_hwnd,int tab_id,const std::wstring& menu_name,const std::wstring& name,HINSTANCE inst,LPCTSTR temp);\r
+    virtual ~tab_dialog_base(){};\r
+    virtual void create() ;\r
+    virtual void enable() = 0;\r
+    virtual void disable() = 0;\r
+    virtual void resize();\r
+  protected:\r
+    base_window& parent_window_;\r
+  private:\r
+    HWND tab_hwnd_;\r
+    int tab_id_;\r
+    HINSTANCE inst_;\r
+    LPCTSTR temp_;\r
+  };\r
+}
\ No newline at end of file
diff --git a/mfsample/taskbar.cpp b/mfsample/taskbar.cpp
new file mode 100644 (file)
index 0000000..8a6088c
--- /dev/null
@@ -0,0 +1,98 @@
+#include "StdAfx.h"
+
+#if _DEBUG
+#define _CRTDBG_MAP_ALLOC
+#include <crtdbg.h>
+#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
+#endif
+
+#include "sf_windows.h"
+#include "taskbar.h"
+
+
+namespace sf {
+
+const int taskbar::none = TBPF_NOPROGRESS;
+const int taskbar::indeterminate = TBPF_INDETERMINATE;
+const int taskbar::normal = TBPF_NORMAL;
+const int taskbar::error = TBPF_ERROR;
+const int taskbar::paused = TBPF_PAUSED;
+
+long  taskbar::register_message()
+{
+  return ::RegisterWindowMessage(L"TaskbarButtonCreated");
+}
+
+struct taskbar::impl
+{
+  typedef throw_if_err<sf::taskbar::exception> throw_if_err_;
+
+  impl(){}
+  ~impl()
+  {
+    discard();
+  }
+
+  void create() {
+        throw_if_err_()(CoCreateInstance(CLSID_TaskbarList,nullptr,CLSCTX::CLSCTX_INPROC_SERVER,__uuidof(ITaskbarList4),(LPVOID*)taskbar_.GetAddressOf()));
+  }
+  bool is_create() const 
+  {
+    return (taskbar_ != 0);
+  }
+  void discard()
+  {
+    safe_release(taskbar_);
+  }
+    
+  void overlay_icon(const sf::base_window& w,const sf::icon& ic,const std::wstring& description)
+  {
+    throw_if_err_()(taskbar_->SetOverlayIcon(reinterpret_cast<HWND>(w.raw_handle()),ic.get(),description.c_str()));
+  }
+
+  void progress_state(const sf::base_window& w,TBPFLAG state)
+  {
+    throw_if_err_()(taskbar_->SetProgressState(reinterpret_cast<HWND>(w.raw_handle()),state));
+  }
+
+  void progress_value(const sf::base_window& w,boost::uint64_t completed, boost::uint64_t total)
+  {
+    throw_if_err_()(taskbar_->SetProgressValue(reinterpret_cast<HWND>(w.raw_handle()),completed,total));
+  }
+
+  void add_thumb_buttons(const sf::base_window& w,const std::vector<THUMBBUTTON>& tbs){
+      taskbar_->ThumbBarAddButtons(reinterpret_cast<HWND>(w.raw_handle()),tbs.size(),const_cast<LPTHUMBBUTTON>(&(tbs[0])));
+  };
+
+  void update_thumb_buttons(const sf::base_window& w,const std::vector<THUMBBUTTON>& tbs){
+      taskbar_->ThumbBarUpdateButtons(reinterpret_cast<HWND>(w.raw_handle()),tbs.size(),const_cast<LPTHUMBBUTTON>(&(tbs[0])));
+  };
+
+private:
+  _WRL_PTR_TYPEDEF(ITaskbarList4);
+  ITaskbarList4Ptr taskbar_;
+};
+
+   
+taskbar::taskbar() : impl_(new sf::taskbar::impl()) {}
+taskbar::~taskbar() { discard();};
+
+void taskbar::create(){impl_->create();};
+bool taskbar::is_create() const {return impl_->is_create();};
+void taskbar::discard(){impl_->discard();};
+void taskbar::overlay_icon(const sf::base_window& w,const icon& ic,const std::wstring& description){impl_->overlay_icon(w,ic,description);};
+void taskbar::progress_state(const sf::base_window& w,int state){impl_->progress_state(w,(TBPFLAG)state);};
+void taskbar::progress_value(const sf::base_window& w,boost::uint64_t completed, boost::uint64_t total){impl_->progress_value(w,completed,total);};
+void taskbar::add_thumb_buttons(const sf::base_window& w,const thumb_button_manager& tm){
+  BOOST_ASSERT(!tm.is_added);
+  impl_->add_thumb_buttons(w,tm.thumbbuttons_);
+  tm.is_added = true;
+};
+void taskbar::update_thumb_buttons(const sf::base_window& w,const thumb_button_manager& tm){
+  BOOST_ASSERT(tm.is_added);
+  if(tm.is_added){
+    impl_->update_thumb_buttons(w,tm.thumbbuttons_);
+  }
+};
+
+}
\ No newline at end of file
diff --git a/mfsample/taskbar.h b/mfsample/taskbar.h
new file mode 100644 (file)
index 0000000..97ccb0d
--- /dev/null
@@ -0,0 +1,161 @@
+#pragma once\r
+\r
+/*\r
+  ==============================================================================\r
+\r
+   This file is part of the async\r
+   Copyright 2005-10 by Satoshi Fujiwara.\r
+\r
+   async can be redistributed and/or modified under the terms of the\r
+   GNU General Public License, as published by the Free Software Foundation;\r
+   either version 2 of the License, or (at your option) any later version.\r
+\r
+   async is distributed in the hope that it will be useful,\r
+   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+   GNU General Public License for more details.\r
+\r
+   You should have received a copy of the GNU General Public License\r
+   along with async; if not, visit www.gnu.org/licenses or write to the\r
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, \r
+   Boston, MA 02111-1307 USA\r
+\r
+  ==============================================================================\r
+*/\r
+\r
+#include "exception.h"\r
+#include "icon.h"\r
+\r
+namespace sf\r
+{\r
+  \r
+  ///** インターフェース */\r
+  //struct thumb_button : boost::noncopyable\r
+  //{\r
+  //  typedef std::shared_ptr<thumb_button> ptr;\r
+  //  static ptr create_thumb_button();\r
+  //  virtual void show()  = 0;\r
+  //  virtual void hide()  = 0;\r
+  //  virtual void enable() = 0;\r
+  //  virtual void disable() = 0;\r
+  //private:\r
+  //  thumb_button();\r
+  //};\r
+\r
+  struct taskbar;\r
+\r
+  /** サムネイルボタン管理 */\r
+  struct thumb_button_manager\r
+  {\r
+    friend struct taskbar;\r
+    // Thumb Buttonは最大7個まで\r
+    static const int THUMB_BUTTON_MAX = 7;\r
+\r
+    // THUMBBUTTON構造体操作クラス\r
+    struct thumb_button {\r
+\r
+      // コンストラクタ\r
+      thumb_button(uint32_t id ,const icon& i,const std::wstring& tool_tip,THUMBBUTTON& t) : thumb_(t)\r
+      {\r
+        BOOST_ASSERT(tool_tip.size() < 259);\r
+        memset(&thumb_,0,sizeof(THUMBBUTTON));\r
+        thumb_.dwMask = THB_ICON | THB_TOOLTIP | THB_FLAGS;\r
+        thumb_.hIcon = i.get();\r
+        thumb_.iId = id;\r
+        std::copy(tool_tip.begin(),tool_tip.end(),thumb_.szTip);\r
+        //thumb_.szTip = const_cast<wchar_t*>(tool_tip_.c_str());\r
+      }\r
+      \r
+      // 今回はプロパティ・チェイニングなアクセス方法にしてみた。\r
+      /** アイコン */\r
+      thumb_button& set_icon(icon& ic) {thumb_.hIcon = ic.get(); return *this;};\r
+      /** IDのセット */\r
+      thumb_button& id(uint32_t v) {thumb_.iId = v; return *this;}\r
+      /** ツールチップ */\r
+      thumb_button& tool_tip(const std::wstring& v) {\r
+        BOOST_ASSERT(v.size() < 259);\r
+        std::copy(v.begin(),v.end(),thumb_.szTip);\r
+        thumb_.szTip[v.size()] = L'\0';\r
+        return *this;\r
+      }\r
+      /** 有効化・無効化 */\r
+      thumb_button& enable(bool v){v?(thumb_.dwFlags &= ~THBF_ENABLED):(thumb_.dwFlags |= THBF_DISABLED); return *this;}\r
+      /** クリックされたらサムネイルを閉じるか */\r
+      thumb_button& dismission_click(bool v){ v?(thumb_.dwFlags |= THBF_DISMISSONCLICK):(thumb_.dwFlags &= ~THBF_DISMISSONCLICK); return *this;}\r
+      /** ボタンの外枠を描画するかどうか */\r
+      thumb_button& no_background(bool v){v?(thumb_.dwFlags |= THBF_NOBACKGROUND):(thumb_.dwFlags &= ~THBF_NOBACKGROUND);return *this;}\r
+      /** 隠すか・表示するか */\r
+      thumb_button& hidden(bool v){v?(thumb_.dwFlags |= THBF_HIDDEN):(thumb_.dwFlags &= ~ THBF_HIDDEN);return *this;}\r
+      /** ボタンアクションを起こすかどうか。ボタンを通知目的で使用する際に用いる。*/\r
+      thumb_button& no_interacive(bool v){v?(thumb_.dwFlags |= THBF_NONINTERACTIVE):(thumb_.dwFlags &= ~THBF_NONINTERACTIVE);return *this;}\r
+\r
+    private:\r
+      THUMBBUTTON& thumb_;\r
+    };\r
+    \r
+    thumb_button_manager() : is_added(false) {}\r
+\r
+    // Thumb Buttonは7個までに制限されている\r
+    thumb_button&  add_thumb_button(uint32_t id,const icon& i,const std::wstring& str)\r
+    {\r
+      // 事前条件\r
+      BOOST_ASSERT(thumb_buttons_.size() < 7 && is_added == false);\r
+      if(!is_added){\r
+        thumbbuttons_.push_back(THUMBBUTTON());\r
+        thumb_buttons_.push_back(thumb_button(id,i,str, (thumbbuttons_.at(thumbbuttons_.size() - 1))));\r
+      }\r
+      return thumb_buttons_.at(thumb_buttons_.size() - 1);\r
+    }\r
+\r
+    thumb_button& at(uint32_t i){\r
+      BOOST_ASSERT(i < thumb_buttons_.size());\r
+      return thumb_buttons_.at(i);\r
+    }\r
+\r
+    size_t size() const {return thumb_buttons_.size();}\r
+  private:\r
+    mutable bool is_added;\r
+    // メモリ配列を合わせるためにこうした。\r
+    std::vector<THUMBBUTTON> thumbbuttons_;\r
+    std::vector<thumb_button> thumb_buttons_;\r
+    //typedef boost::ptr_vector<thumb_button> thumb_buttons;\r
+  };\r
+\r
+  /** タスクバーAPIのラップクラス。本来であればインターフェースにする方が良いかもしれないけれど */\r
+  struct taskbar : boost::noncopyable\r
+  {\r
+    struct exception\r
+     : public sf::win32_error_exception \r
+    {\r
+      exception(uint32_t hr) : win32_error_exception(hr) {};\r
+      exception() : win32_error_exception() {} ;\r
+    };\r
+\r
+     taskbar();\r
+    ~taskbar();\r
+    void create();\r
+    void discard();\r
+    void overlay_icon(const sf::base_window& w,const icon& ic,const std::wstring& description);\r
+    void progress_state(const sf::base_window& w,int state);\r
+    void progress_value(const sf::base_window& w,boost::uint64_t completed, boost::uint64_t total);\r
+\r
+    void add_thumb_buttons(const sf::base_window& w,const thumb_button_manager& tm);\r
+    void update_thumb_buttons(const sf::base_window& w,const thumb_button_manager& tm);\r
+    bool is_create() const;\r
+\r
+    static long register_message();\r
+\r
+    static const int none;\r
+    static const int indeterminate;\r
+    static const int normal;\r
+    static const int error;\r
+    static const int paused;\r
+\r
+  private:\r
+    struct impl;\r
+    std::shared_ptr<impl> impl_;\r
+    friend struct impl;\r
+  };\r
+\r
+}\r
+\r
diff --git a/mfsample/timer.cpp b/mfsample/timer.cpp
new file mode 100644 (file)
index 0000000..b73c26e
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+  ==============================================================================
+
+   This file is part of the async
+   Copyright 2005-11 by Satoshi Fujiwara.
+
+   async can be redistributed and/or modified under the terms of the
+   GNU General Public License, as published by the Free Software Foundation;
+   either version 2 of the License, or (at your option) any later version.
+
+   async is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with async; if not, visit www.gnu.org/licenses or write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
+   Boston, MA 02111-1307 USA
+
+  ==============================================================================
+*/
+
+#include "StdAfx.h"
+
+#if _DEBUG
+#define _CRTDBG_MAP_ALLOC
+#include <crtdbg.h>
+#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
+#endif
+
+#include "sf_windows.h"
+#include "timer.h"
+
+namespace sf {
+timer::timer(sf::base_window& window,uint32_t timeout) : window_(window),timeout_(timeout),timer_id_(0)
+{
+
+}
+void timer::start(){
+  if(!::SetTimer(reinterpret_cast<HWND>(window_.raw_handle()),(UINT_PTR)&timer_id_,timeout_,NULL)){
+    throw timer::exception();
+  };
+};
+
+void timer::player_stop()
+{
+  if(timer_id_)
+  {
+    ::KillTimer(reinterpret_cast<HWND>(window_.raw_handle()),(UINT_PTR)&timer_id_);
+    timer_id_ = 0;
+  }
+};
+
+}
diff --git a/mfsample/timer.h b/mfsample/timer.h
new file mode 100644 (file)
index 0000000..2dd7511
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+  ==============================================================================
+
+   This file is part of the async
+   Copyright 2005-11 by Satoshi Fujiwara.
+
+   async can be redistributed and/or modified under the terms of the
+   GNU General Public License, as published by the Free Software Foundation;
+   either version 2 of the License, or (at your option) any later version.
+
+   async is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with async; if not, visit www.gnu.org/licenses or write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
+   Boston, MA 02111-1307 USA
+
+  ==============================================================================
+*/
+#pragma once
+#include "base_window.h"
+namespace sf{
+struct timer
+{
+  struct exception
+    : public sf::win32_error_exception 
+  {
+    exception(uint32_t hr) : win32_error_exception(hr) {};
+    exception() : win32_error_exception() {} ;
+  };
+
+  timer(sf::base_window& window,uint32_t timeout);
+  void start();
+  void player_stop();
+  ~timer(){player_stop();};
+private:
+  sf::base_window& window_;
+  uint32_t timer_id_;
+  uint32_t timeout_;
+};
+}
+
diff --git a/mfsample/toplevel_window.cpp b/mfsample/toplevel_window.cpp
new file mode 100644 (file)
index 0000000..11bc752
--- /dev/null
@@ -0,0 +1,1175 @@
+/*\r
+==============================================================================\r
+\r
+Copyright 2005-11 by Satoshi Fujiwara.\r
+\r
+async can be redistributed and/or modified under the terms of the\r
+GNU General Public License, as published by the Free Software Foundation;\r
+either version 2 of the License, or (at your option) any later version.\r
+\r
+async is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+GNU General Public License for more details.\r
+\r
+You should have received a copy of the GNU General Public License\r
+along with async; if not, visit www.gnu.org/licenses or write to the\r
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, \r
+Boston, MA 02111-1307 USA\r
+\r
+==============================================================================\r
+*/\r
+/* ToDo\r
+\r
+TODO: リサイズに対応する\r
+\r
+*/\r
+\r
+#include "stdafx.h"\r
+#include "resource.h"\r
+#define BOOST_ASSIGN_MAX_PARAMS 7\r
+#include <boost/assign.hpp>\r
+#include <boost/assign/ptr_list_of.hpp>\r
+#include <boost/assign/ptr_list_inserter.hpp>\r
+#include <boost/foreach.hpp>\r
+\r
+#include "sf_windows.h"\r
+#include "toplevel_window.h"\r
+#include "CommDlg.h"\r
+#include "icon.h"\r
+#include "timer.h"\r
+#include "exception.h"\r
+#include "application.h"\r
+//#include "config_tab_dialog.h"\r
+#include "info_tab_dialog.h"\r
+\r
+#if _DEBUG\r
+#define _CRTDBG_MAP_ALLOC\r
+#include <crtdbg.h>\r
+#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)\r
+#endif\r
+\r
+\r
+//#include "seq_tab_dialog.h"\r
+\r
+//#pragma comment( lib, "dxguid.lib" )\r
+//#pragma comment( lib, "d3d11.lib" )\r
+//#pragma comment( lib, "d3dx11.lib" )\r
+//#pragma comment( lib, "dxgi.lib" )\r
+//#pragma comment( lib, "d3dx9.lib" )   \r
+#pragma comment( lib, "Shlwapi.lib" ) \r
+\r
+#define THROW_IFERR(hres) \\r
+  if (FAILED(hres)) { throw sf::win32_error_exception(hres); }\r
+\r
+#ifndef HINST_THISCOMPONENT\r
+EXTERN_C IMAGE_DOS_HEADER __ImageBase;\r
+#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase)\r
+#endif\r
+\r
+namespace sf \r
+{\r
+\r
+  //HRESULT EnableBlurBehind(HWND hwnd)\r
+  //{\r
+  //  HRESULT hr = S_OK;\r
+\r
+  //  //Create and populate the BlurBehind structre\r
+  //  DWM_BLURBEHIND bb = {0};\r
+  //  //Enable Blur Behind and Blur Region;\r
+  //  bb.dwFlags = DWM_BB_ENABLE;\r
+  //  bb.fEnable = true;\r
+  //  bb.hRgnBlur = NULL;\r
+\r
+  //  //Enable Blur Behind\r
+  //  hr = DwmEnableBlurBehindWindow(hwnd, &bb);\r
+  //  if (SUCCEEDED(hr))\r
+  //  {\r
+  //    //do more things\r
+  //  }\r
+  //  return hr;\r
+  //}\r
+\r
+  //// 汎用情報格納用\r
+  //struct mode_info \r
+  //{\r
+  //  mode_info(const std::wstring& n,const std::wstring& d) : name(n),description(d) {}\r
+  //  std::wstring name;\r
+  //  std::wstring description;\r
+  //};\r
+\r
+  //// ディスプレイモード\r
+  //struct display_mode \r
+  //{\r
+  //  display_mode(const std::wstring& n,const std::wstring& d) : name(n),description(d) {}\r
+  //  std::wstring name;\r
+  //  std::wstring description;\r
+  //};\r
+\r
+  //std::vector<mode_info> display_modes = \r
+  //  boost::assign::list_of<mode_info>\r
+  //  (L"DXGI_FORMAT_UNKNOWN",L"フォーマットが不明")\r
+  //  (L"DXGI_FORMAT_R32G32B32A32_TYPELESS",L"4 成分、128 ビット型なしフォーマット 1")\r
+  //  (L"DXGI_FORMAT_R32G32B32A32_FLOAT",L"4 成分、128 ビット浮動小数点フォーマット 1")\r
+  //  (L"DXGI_FORMAT_R32G32B32A32_UINT",L"4 成分、128 ビット符号なし整数フォーマット 1")\r
+  //  (L"DXGI_FORMAT_R32G32B32A32_SINT",L"4 成分、128 ビット符号付き整数フォーマット 1")\r
+  //  (L"DXGI_FORMAT_R32G32B32_TYPELESS",L"3 成分、96 ビット型なしフォーマット")\r
+  //  (L"DXGI_FORMAT_R32G32B32_FLOAT",L"3 成分、96 ビット浮動小数点フォーマット")\r
+  //  (L"DXGI_FORMAT_R32G32B32_UINT",L"3 成分、96 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R32G32B32_SINT",L"3 成分、96 ビット符号付き整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R16G16B16A16_TYPELESS",L"4 成分、64 ビット型なしフォーマット")\r
+  //  (L"DXGI_FORMAT_R16G16B16A16_FLOAT",L"4 成分、64 ビット浮動小数点フォーマット")\r
+  //  (L"DXGI_FORMAT_R16G16B16A16_UNORM",L"4 成分、64 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R16G16B16A16_UINT",L"4 成分、64 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R16G16B16A16_SNORM",L"4 成分、64 ビット符号付き整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R16G16B16A16_SINT",L"4 成分、64 ビット符号付き整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R32G32_TYPELESS",L"2 成分、64 ビット型なしフォーマット")\r
+  //  (L"DXGI_FORMAT_R32G32_FLOAT",L"2 成分、64 ビット浮動小数点フォーマット")\r
+  //  (L"DXGI_FORMAT_R32G32_UINT",L"2 成分、64 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R32G32_SINT",L"2 成分、64 ビット符号付き整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R32G8X24_TYPELESS",L"2 成分、64 ビット型なしフォーマット")\r
+  //  (L"DXGI_FORMAT_D32_FLOAT_S8X24_UINT",L"32 ビット浮動小数点成分、および 2 つの符号なし整数成分です (追加の 32 ビットを含む)。")\r
+  //  (L"DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS",L"32 ビット浮動小数点成分、および 2 つの型なし成分です (追加の 32 ビットを含む)。")\r
+  //  (L"DXGI_FORMAT_X32_TYPELESS_G8X24_UINT",L"32 ビット型なし成分、および 2 つの符号なし整数成分です (追加の 32 ビットを含む)。")\r
+  //  (L"DXGI_FORMAT_R10G10B10A2_TYPELESS",L"4 成分、32 ビット型なしフォーマット")\r
+  //  (L"DXGI_FORMAT_R10G10B10A2_UNORM",L"4 成分、32 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R10G10B10A2_UINT",L"4 成分、32 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R11G11B10_FLOAT",L"3 成分、32 ビット浮動小数点フォーマット")\r
+  //  (L"DXGI_FORMAT_R8G8B8A8_TYPELESS",L"3 成分、32 ビット型なしフォーマット")\r
+  //  (L"DXGI_FORMAT_R8G8B8A8_UNORM",L"4 成分、32 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R8G8B8A8_UNORM_SRGB",L"4 成分、32 ビット符号なし正規化整数 sRGB フォーマット")\r
+  //  (L"DXGI_FORMAT_R8G8B8A8_UINT",L"4 成分、32 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R8G8B8A8_SNORM",L"3 成分、32 ビット符号付き整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R8G8B8A8_SINT",L"3 成分、32 ビット符号付き整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R16G16_TYPELESS",L"2 成分、32 ビット型なしフォーマット")\r
+  //  (L"DXGI_FORMAT_R16G16_FLOAT",L"2 成分、32 ビット浮動小数点フォーマット")\r
+  //  (L"DXGI_FORMAT_R16G16_UNORM",L"2 成分、32 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R16G16_UINT",L"2 成分、32 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R16G16_SNORM",L"2 成分、32 ビット符号付き整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R16G16_SINT",L"2 成分、32 ビット符号付き整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R32_TYPELESS",L"1 成分、32 ビット型なしフォーマット")\r
+  //  (L"DXGI_FORMAT_D32_FLOAT",L"1 成分、32 ビット浮動小数点フォーマット")\r
+  //  (L"DXGI_FORMAT_R32_FLOAT",L"1 成分、32 ビット浮動小数点フォーマット")\r
+  //  (L"DXGI_FORMAT_R32_UINT",L"1 成分、32 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R32_SINT",L"1 成分、32 ビット符号付き整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R24G8_TYPELESS",L"2 成分、32 ビット型なしフォーマット")\r
+  //  (L"DXGI_FORMAT_D24_UNORM_S8_UINT",L"深度チャンネルに 24 ビット、ステンシル チャンネルに 8 ビットを使用する 32 ビット Z バッファー フォーマット")\r
+  //  (L"DXGI_FORMAT_R24_UNORM_X8_TYPELESS",L"1 成分、24 ビット符号なし正規化整数と追加の型なし 8 ビットを含む、32 ビット フォーマット")\r
+  //  (L"DXGI_FORMAT_X24_TYPELESS_G8_UINT",L"1 成分、24 ビット型なしフォーマットと追加の 8 ビット符号なし整数成分を含む、32 ビット フォーマット")\r
+  //  (L"DXGI_FORMAT_R8G8_TYPELESS",L"2 成分、16 ビット型なしフォーマット")\r
+  //  (L"DXGI_FORMAT_R8G8_UNORM",L"2 成分、16 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R8G8_UINT",L"2 成分、16 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R8G8_SNORM",L"2 成分、16 ビット符号付き整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R8G8_SINT",L"2 成分、16 ビット符号付き整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R16_TYPELESS",L"1 成分、16 ビット型なしフォーマット")\r
+  //  (L"DXGI_FORMAT_R16_FLOAT",L"1 成分、16 ビット浮動小数点フォーマット")\r
+  //  (L"DXGI_FORMAT_D16_UNORM",L"1 成分、16 ビット符号なし正規化整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R16_UNORM",L"1 成分、16 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R16_UINT",L"1 成分、16 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R16_SNORM",L"1 成分、16 ビット符号付き整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R16_SINT",L"1 成分、16 ビット符号付き整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R8_TYPELESS",L"1 成分、8 ビット型なしフォーマット")\r
+  //  (L"DXGI_FORMAT_R8_UNORM",L"1 成分、8 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R8_UINT",L"1 成分、8 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R8_SNORM",L"1 成分、8 ビット符号付き整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R8_SINT",L"1 成分、8 ビット符号付き整数フォーマット")\r
+  //  (L"DXGI_FORMAT_A8_UNORM",L"1 成分、8 ビット符号なし整数フォーマット")\r
+  //  (L"DXGI_FORMAT_R1_UNORM",L"1 成分、1 ビット符号なし正規化整数フォーマット 2.")\r
+  //  (L"DXGI_FORMAT_R9G9B9E5_SHAREDEXP",L"4 成分、32 ビット浮動小数点フォーマット 2.")\r
+  //  (L"DXGI_FORMAT_R8G8_B8G8_UNORM",L"4 成分、32 ビット符号なし正規化整数フォーマット 3")\r
+  //  (L"DXGI_FORMAT_G8R8_G8B8_UNORM",L"4 成分、32 ビット符号なし正規化整数フォーマット 3")\r
+  //  (L"DXGI_FORMAT_BC1_TYPELESS",L"4 成分、型なしブロック圧縮フォーマット")\r
+  //  (L"DXGI_FORMAT_BC1_UNORM",L"4 成分、ブロック圧縮フォーマット")\r
+  //  (L"DXGI_FORMAT_BC1_UNORM_SRGB",L"sRGB データ用の 4 成分、ブロック圧縮フォーマット")\r
+  //  (L"DXGI_FORMAT_BC2_TYPELESS",L"4 成分、型なしブロック圧縮フォーマット")\r
+  //  (L"DXGI_FORMAT_BC2_UNORM",L"4 成分、ブロック圧縮フォーマット")\r
+  //  (L"DXGI_FORMAT_BC2_UNORM_SRGB",L"sRGB データ用の 4 成分、ブロック圧縮フォーマット")\r
+  //  (L"DXGI_FORMAT_BC3_TYPELESS",L"4 成分、型なしブロック圧縮フォーマット")\r
+  //  (L"DXGI_FORMAT_BC3_UNORM",L"4 成分、ブロック圧縮フォーマット")\r
+  //  (L"DXGI_FORMAT_BC3_UNORM_SRGB",L"sRGB データ用の 4 成分、ブロック圧縮フォーマット")\r
+  //  (L"DXGI_FORMAT_BC4_TYPELESS",L"1 成分、型なしブロック圧縮フォーマット")\r
+  //  (L"DXGI_FORMAT_BC4_UNORM",L"1 成分、ブロック圧縮フォーマット")\r
+  //  (L"DXGI_FORMAT_BC4_SNORM",L"1 成分、ブロック圧縮フォーマット")\r
+  //  (L"DXGI_FORMAT_BC5_TYPELESS",L"2 成分、型なしブロック圧縮フォーマット")\r
+  //  (L"DXGI_FORMAT_BC5_UNORM",L"2 成分、ブロック圧縮フォーマット")\r
+  //  (L"DXGI_FORMAT_BC5_SNORM",L"2 成分、ブロック圧縮フォーマット")\r
+  //  (L"DXGI_FORMAT_B5G6R5_UNORM",L"3 成分、16 ビット符号なし正規化整数フォーマット")\r
+  //  (L"DXGI_FORMAT_B5G5R5A1_UNORM",L"1 ビット アルファをサポートする 4 成分、16 ビット符号なし正規化整数フォーマット")\r
+  //  (L"DXGI_FORMAT_B8G8R8A8_UNORM",L"8 ビット アルファをサポートする 4 成分、16 ビット符号なし正規化整数フォーマット")\r
+  //  (L"DXGI_FORMAT_B8G8R8X8_UNORM",L"4 成分、16 ビット符号なし正規化整数フォーマット")\r
+  //  (L"DXGI_FORMAT_FORCE_UINT",L"コンパイル時に、この列挙型のサイズを 32 ビットにするために定義されています。この値を指定しない場合、一部のコンパイラでは列挙型を 32 ビット以外のサイズでコンパイル可能この定数が使用されることはありません。");\r
+\r
+  //// スキャンライン情報\r
+\r
+  //std::vector<mode_info> scanline_orders = \r
+  //  boost::assign::list_of<mode_info>\r
+  //  (L"DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED",L"走査線の順序が指定されていません。")\r
+  //  (L"DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE",L"イメージは先頭の走査線~最後の走査線から作成され、スキップされる走査線はありません。")\r
+  //  (L"DXGI_MODE_SCANLINE_ORDER_UPPER_FIELD_FIRST",L"イメージが上部のフィールドから作成されます。")\r
+  //  (L"DXGI_MODE_SCANLINE_ORDER_LOWER_FIELD_FIRST",L"イメージが下部のフィールドから作成されます。");\r
+\r
+  //// スケーリングパラメータ\r
+  //std::vector<mode_info> scalings = boost::assign::list_of<mode_info>\r
+  //  (L"DXGI_MODE_SCALING_UNSPECIFIED",L"スケーリングが指定されていません。")\r
+  //  (L"DXGI_MODE_SCALING_CENTERED",L"スケーリングなしを指定します。イメージはディスプレイの中央に配置されます。通常、このフラグは固定ドットピッチ ディスプレイ (LED ディスプレイなど) に使用します。")\r
+  //  (L"DXGI_MODE_SCALING_STRETCHED",L"拡大スケーリングを指定します。");\r
+\r
+  struct simple_vertex\r
+  {\r
+    DirectX::XMFLOAT3 pos;\r
+    DirectX::XMFLOAT3 norm;\r
+    DirectX::XMFLOAT2 tex;\r
+  };\r
+\r
+  struct cb_never_changes\r
+  {\r
+    DirectX::XMMATRIX mView;\r
+    DirectX::XMFLOAT4 vLightDir;\r
+  };\r
+\r
+  struct cb_change_on_resize\r
+  {\r
+    DirectX::XMMATRIX mProjection;\r
+  };\r
+\r
+  struct cb_changes_every_frame\r
+  {\r
+    DirectX::XMMATRIX mWorld;\r
+    DirectX::XMFLOAT4 vLightColor;\r
+\r
+    //    DirectX::XMFLOAT4 vMeshColor;\r
+  };\r
+\r
+  struct slider : public subclass_window\r
+  {\r
+    slider() : subclass_window() {};\r
+    void create() {};\r
+    virtual LRESULT window_proc(HWND hwnd,uint32_t message, WPARAM wParam, LPARAM lParam) \r
+    {\r
+      //switch(message){\r
+      //case WM_HSCROLL :\r
+      //  {\r
+      //    switch(wParam)\r
+      //    {\r
+      //    case TB_THUMBTRACK : \r
+      //       DWORD dwPos = SendMessage(GetDlgItem(hwnd_,IDC_SLIDER), TBM_GETPOS, 0, 0); \r
+      //       break; \r
+      //    }\r
+      //  }\r
+      /*   }*/\r
+      return CallWindowProc(proc_backup_,hwnd,message,wParam,lParam);\r
+    };\r
+  };\r
+\r
+  struct toplevel_window::impl : public base_win32_dialog_t\r
+  {\r
+\r
+    static const uint32_t SLIDER_MAX = 30000;\r
+    static const int TAB_INFO = 0;\r
+    static const int TAB_CONFIG = 1;\r
+    static const int TAB_SEQ = 2;\r
+\r
+    impl(const std::wstring& menu_name,const std::wstring& name,bool fit_to_display,float width = 160,float height = 100) \r
+      : base_win32_dialog_t(menu_name,name,fit_to_display,width,height) \r
+      , timer_(*this,100)\r
+      , icon_(IDI_ICON1)\r
+      /*,mesh_color_(0.7f, 0.7f, 0.7f, 1.0f)*/\r
+      ,init_(false)\r
+      ,thumb_start_(false)\r
+    {\r
+\r
+      file_name_.reserve(MAX_PATH + 1);\r
+      dir_name_.reserve(MAX_PATH + 1);\r
+      on_render.connect(boost::bind(&impl::render,this));\r
+    };\r
+\r
+    ~impl(){\r
+      //safe_release(dxgi_factory_);\r
+    };\r
+\r
+\r
+    // -------------------------------------------------------------------\r
+    // ウィンドウプロシージャ\r
+    // -------------------------------------------------------------------\r
+\r
+    void init_control()\r
+    {\r
+      SendMessage(GetDlgItem(hwnd_,IDC_SLIDER), TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, SLIDER_MAX));\r
+      application::instance()->player_init_ok().connect(boost::bind(&toplevel_window::impl::player_init_ok,this));\r
+\r
+      DWORD dwDlgBase = GetDialogBaseUnits();\r
+      int cxMargin = LOWORD(dwDlgBase) / 4; \r
+      int cyMargin = HIWORD(dwDlgBase) / 8;\r
+\r
+      //タブの初期設定\r
+      TCITEM tie; \r
+      tie.mask = TCIF_TEXT | TCIF_IMAGE; \r
+      tie.iImage = -1; \r
+      HWND tab = GetDlgItem(hwnd_,IDC_TAB);\r
+      // 情報タブの挿入\r
+      tie.pszText = L"情報";\r
+      TabCtrl_InsertItem(tab,TAB_INFO,&tie);\r
+      tab_dialogs_.push_back(\r
+        new info_tab_dialog(*this,tab,TAB_INFO,L"info",L"info",HINST_THISCOMPONENT,MAKEINTRESOURCEW(IDD_INFO))\r
+        );\r
+      tab_dialogs_[TAB_INFO].show();\r
+\r
+      // 設定タブの挿入\r
+      //tie.pszText = L"設定";\r
+      //TabCtrl_InsertItem(tab,TAB_CONFIG,&tie);\r
+      //tab_dialogs_.push_back(\r
+      //  new config_tab_dialog(*this,tab,TAB_CONFIG,L"config",L"config",HINST_THISCOMPONENT,MAKEINTRESOURCEW(IDD_CONFIG)) \r
+      //  );\r
+      //TabCtrl_SetCurSel(tab,0);\r
+      //RECT rci;\r
+      //TabCtrl_GetItemRect(tab,0,&rci);\r
+      //RECT r;\r
+      ////TabCtrl_GetItemRect(tab,0,&r);\r
+      //GetClientRect(tab,&r);\r
+      //RECT rw;\r
+      //GetWindowRect(tab,&rw);\r
+      //POINT pt = {rw.left,rw.top + rci.bottom};\r
+      //ScreenToClient(hwnd_,&pt);\r
+\r
+      // シーケンサタブの挿入\r
+      //tie.pszText = L"シーケンサ";\r
+      //TabCtrl_InsertItem(tab,TAB_SEQ,&tie);\r
+      //tab_dialogs_.push_back(\r
+      //  new seq_tab_dialog(application::instance()->sequencer(),*this,tab,TAB_SEQ,L"sequencer",L"sequencer",HINST_THISCOMPONENT,MAKEINTRESOURCEW(IDD_SEQ))\r
+      //  );\r
+\r
+      //GetRect(\r
+\r
+      //情報表示ダイアログの作成・表示\r
+      //hwnd_info_ = CreateDialogW(HINST_THISCOMPONENT,MAKEINTRESOURCE(IDD_INFO),hwnd_,proc_info_);\r
+      //SetWindowPos(hwnd_info_,HWND_TOP,pt.x + cxMargin,pt.y + cyMargin,r.right - cxMargin * 2 - 1,r.bottom - rci.bottom - cyMargin * 2 - 1,SWP_NOZORDER | SWP_SHOWWINDOW);\r
+\r
+      //TODO: 設定ダイアログの作成・表示\r
+      //hwnd_config_ = CreateDialogW(HINST_THISCOMPONENT,MAKEINTRESOURCEW(IDD_CONFIG),hwnd_,proc_config_);\r
+      //SetWindowPos(hwnd_config_,HWND_TOP,pt.x + cxMargin,pt.y + cyMargin,r.right - cxMargin * 2 - 1,r.bottom - rci.bottom - cyMargin * 2 - 1,SWP_NOZORDER | SWP_SHOWWINDOW);\r
+      ////MapDialogRect(hwnd_config_,&r);\r
+      //ShowWindow(hwnd_config_,FALSE);\r
+      //config_dialog_.reset();\r
+\r
+      // 背景色の設定\r
+      //get_dc tab_dc(tab);\r
+      //get_dc info_dc(hwnd_info_);\r
+      //get_dc config_dc(hwnd_config_);\r
+      //SetBkMode(info_dc.get(),GetBkMode(tab_dc.get()));\r
+      //SetBkMode(config_dc.get(),GetBkMode(tab_dc.get()));\r
+      //SetBkColor(info_dc.get(),GetBkColor(tab_dc.get()));\r
+      //SetBkColor(config_dc.get(),GetBkColor(tab_dc.get()));\r
+\r
+      tab_page_ = 0;\r
+      //slider_.attach(GetDlgItem(hwnd_,IDC_SLIDER));\r
+    }\r
+\r
+    // プレイヤーの初期設定完了時の処理\r
+    void player_init_ok()\r
+    {\r
+      // ファイルオープン完了後の処理\r
+      sf::player::PlayerPtr player = application::instance()->Player();\r
+      player->OnOpenComplete().connect([this](sf::player::Player &) -> void\r
+      {\r
+        this->player_ready();\r
+      }\r
+        );\r
+\r
+      // 再生時イベントの処理\r
+      player->OnStart().connect([this](sf::player::Player &) -> void \r
+      {\r
+        this->play_();\r
+      }\r
+        );\r
+\r
+      // Pauseイベントの処理\r
+      player->OnPause().connect([this](sf::player::Player &) -> void \r
+      {\r
+        this->pause_();\r
+      }\r
+        );\r
+\r
+      // 停止イベントの処理\r
+      player->OnStop().connect([this](sf::player::Player &) -> void \r
+      {\r
+        stop_();\r
+      }\r
+        );\r
+\r
+\r
+      // ファイルオープンボタンを有効化する\r
+      enable_control(IDC_FILE,true);\r
+    }\r
+\r
+    void player_ready()\r
+    {\r
+      // プレイボタンは有効化\r
+      enable_control(IDC_PLAY,true);\r
+      focus(IDC_PLAY);\r
+      // highlight(IDC_PLAY);\r
+      // その他のボタンは無効化\r
+      enable_control(IDC_REPEAT_CHECK,true);\r
+      enable_control(IDC_PAUSE,false);\r
+      enable_control(IDC_SLIDER,true);\r
+      enable_control(IDC_STOP,false);\r
+      //    enable_control(hwnd_config_,IDC_EXC_MODE,true);\r
+    }\r
+\r
+    void player_read_file()\r
+    {\r
+      post_message(WM_PLAY_PLAY,0,0);\r
+    }\r
+\r
+    void play_()\r
+    {\r
+      enable_control(IDC_PLAY,false);\r
+      enable_control(IDC_STOP,true);\r
+      focus(IDC_STOP);\r
+      //highlight(IDC_STOP);\r
+      enable_control(IDC_REPEAT_CHECK,true);\r
+      enable_control(IDC_PAUSE,true);\r
+      ::SetWindowText(GetDlgItem(hwnd_,IDC_PAUSE),L"一時停止");\r
+      enable_control(IDC_SLIDER,true);\r
+      enable_control(IDC_FILE,false);\r
+\r
+      // 設定ダイアログ\r
+      // EnableWindow(hwnd_config_,FALSE);\r
+      // tab_dialogs_[TAB_CONFIG].disable();\r
+      //    enable_config_dialog(false);\r
+\r
+    }\r
+\r
+    void player_stop()\r
+    {\r
+      post_message(WM_PLAY_STOP,0,0);\r
+    }\r
+\r
+    void stop_()\r
+    {\r
+      enable_control(IDC_PLAY,true);\r
+      focus(IDC_PLAY);\r
+      //highlight(IDC_PLAY);\r
+      enable_control(IDC_REPEAT_CHECK,true);\r
+      enable_control(IDC_STOP,false);\r
+      enable_control(IDC_PAUSE,false);\r
+      enable_control(IDC_SLIDER,true);\r
+      ::SendMessage(GetDlgItem(hwnd_,IDC_SLIDER), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)0);\r
+      enable_control(IDC_FILE,true);\r
+\r
+      // 設定ダイアログ\r
+      // EnableWindow(hwnd_config_,TRUE);\r
+      // tab_dialogs_[TAB_CONFIG].enable();\r
+      //    enable_config_dialog(true);\r
+\r
+    }\r
+\r
+\r
+    void player_pause()\r
+    {\r
+      send_message(WM_PLAY_PAUSE,0,0);\r
+    }\r
+\r
+    void pause_()\r
+    {\r
+      enable_control(IDC_PLAY,false);\r
+      enable_control(IDC_STOP,false);\r
+      enable_control(IDC_PAUSE,true);\r
+      enable_control(IDC_REPEAT_CHECK,true);\r
+      focus(IDC_PAUSE);\r
+      //highlight(IDC_PAUSE);\r
+      ::SetWindowText(GetDlgItem(hwnd_,IDC_PAUSE),L"再開");\r
+      enable_control(IDC_SLIDER,true);\r
+      enable_control(IDC_FILE,false);\r
+\r
+      // 設定ダイアログ\r
+      //tab_dialogs_[TAB_CONFIG].disable();\r
+      //    enable_config_dialog(false);\r
+    }\r
+\r
+    virtual void create(){\r
+      create_device_independent_resources();\r
+      //    icon_ = ::LoadIconW(HINST_THISCOMPONENT,MAKEINTRESOURCE(IDI_ICON1));\r
+      register_class(this->name_.c_str(),CS_HREDRAW | CS_VREDRAW ,0,DLGWINDOWEXTRA,icon_.get());\r
+      create_dialog();\r
+\r
+      // 半透明ウィンドウを有効にする。\r
+      //BOOL dwmEnable;\r
+      //DwmIsCompositionEnabled (&dwmEnable); \r
+      //if (dwmEnable) EnableBlurBehind(*this);\r
+\r
+    }\r
+\r
+    void create_dialog()\r
+    {\r
+      hwnd_ = ::CreateDialog(HINST_THISCOMPONENT,MAKEINTRESOURCE(IDD_MAINDIALOG),::GetDesktopWindow(),thunk_proc_);\r
+      // ::DialogBox(HINST_THISCOMPONENT,MAKEINTRESOURCE(IDD_MAINDIALOG),0,thunk_proc_);\r
+    }\r
+\r
+    virtual void discard_device()\r
+    {}\r
+\r
+    void calc_client_size()\r
+    {\r
+      //クライアント領域の現在の幅、高さを求める\r
+      RECT rc;\r
+      GetClientRect( hwnd_, &rc );\r
+      client_width_ = rc.right - rc.left;\r
+      client_height_ = rc.bottom - rc.top;\r
+    }\r
+\r
+    virtual void create_device()\r
+    {\r
+      calc_client_size();\r
+      //HRESULT hr = S_OK;\r
+      init_ = false;\r
+      init_ = true;// 初期化完了\r
+    }\r
+\r
+\r
+    virtual void create_device_independent_resources()\r
+    {\r
+\r
+    }\r
+\r
+    void render(){\r
+\r
+    }\r
+\r
+\r
+    void create_window()\r
+    {\r
+\r
+      // Windowを作成する\r
+      CreateWindowEx(\r
+        WS_EX_APPWINDOW | WS_EX_TOPMOST,\r
+        name_.c_str(),\r
+        title_.c_str(),\r
+        WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME,\r
+        CW_USEDEFAULT,\r
+        CW_USEDEFAULT,\r
+        static_cast<uint32_t>(dpi_.scale_x(width_)),\r
+        static_cast<uint32_t>(dpi_.scale_x(height_)),\r
+        NULL,\r
+        NULL,\r
+        HINST_THISCOMPONENT,\r
+        this\r
+        );\r
+    };\r
+\r
+    void get_dxgi_information()\r
+    {\r
+      //    int i = 0;\r
+      //\r
+      //    while(1){\r
+      //      IDXGIAdapter1Ptr adapter;\r
+      //      HRESULT hr = dxgi_factory_->EnumAdapters1(i,&adapter);\r
+      //      if(hr == DXGI_ERROR_NOT_FOUND)\r
+      //      {\r
+      //        break;\r
+      //      }\r
+      //      DXGI_ADAPTER_DESC1 desc;\r
+      //      adapter->GetDesc1(&desc);\r
+      //      //adapter->CheckInterfaceSupport();\r
+      //      \r
+      //      wdout << desc.Description << std::endl;\r
+      //      wdout << desc.DedicatedVideoMemory << std::endl;\r
+      //      IDXGIDevice1Ptr device;\r
+      //\r
+      //      uint32_t oi = 0;\r
+      //\r
+      //\r
+      //      while(1)\r
+      //      {\r
+      //        IDXGIOutputPtr output;        \r
+      //        if(adapter->EnumOutputs(oi,&output) == DXGI_ERROR_NOT_FOUND){\r
+      //          break;\r
+      //        }\r
+      //        DXGI_OUTPUT_DESC output_desc;\r
+      //        output->GetDesc(&output_desc); \r
+      //        UINT num = 0;\r
+      //        DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;\r
+      //        UINT flags         = DXGI_ENUM_MODES_INTERLACED | DXGI_ENUM_MODES_SCALING;\r
+      //\r
+      //        output->GetDisplayModeList(format,flags,&num,0);\r
+      //        boost::shared_array<DXGI_MODE_DESC> disp_modes(new DXGI_MODE_DESC[num]);\r
+      //        output->GetDisplayModeList(format,flags,&num,&disp_modes[0]);\r
+      //        //output->GetFrameStatistics\r
+      //        for(uint32_t mode_index = 0;mode_index < num;++mode_index)\r
+      //        {\r
+      //          DXGI_MODE_DESC& mode(disp_modes[mode_index]);\r
+      //          wdout << boost::wformat(L"Format: %s %s \n Width: %d Height: %d RefleshRate: %d/%d Scaling:%s %s \n Scanline: %s %s ")\r
+      //            %  display_modes[mode.Format].name % display_modes[mode.Format].description\r
+      //            %  mode.Width % mode.Height \r
+      //            %  mode.RefreshRate.Numerator % mode.RefreshRate.Denominator\r
+      //            %  scalings[mode.Scaling].name %  scalings[mode.Scaling].description\r
+      //            %  scanline_orders[mode.ScanlineOrdering].name\r
+      //            %  scanline_orders[mode.ScanlineOrdering].description\r
+      //            << std::endl;\r
+      //        }\r
+      ////        output->\r
+      //        wdout << output_desc.DeviceName << std::endl; \r
+      //        oi++;\r
+      //      }\r
+      //\r
+      //      adapter.Release();\r
+      //      ++i;\r
+      //    }\r
+    }\r
+\r
+    // コントロールにフォーカスを移動する\r
+    // id ... コントロールID\r
+    void focus(uint32_t id)\r
+    {\r
+      // 間違い\r
+      // ::SetFocus(GetDlgItem(hwnd_,id));\r
+\r
+      // 正解\r
+      post_message(WM_NEXTDLGCTL,(WPARAM)GetDlgItem(hwnd_,id),TRUE);\r
+    }\r
+\r
+    void highlight(uint32_t id)\r
+    {\r
+      Button_SetState(GetDlgItem(hwnd_,id),TRUE);\r
+    }\r
+\r
+  LRESULT other_window_proc(HWND hwnd,uint32_t message, WPARAM wParam, LPARAM lParam)\r
+\r
+  {\r
+    switch (message)\r
+    {\r
+    case WM_PLAY_PLAY:\r
+      play_();\r
+      return TRUE;\r
+    case WM_PLAY_STOP:\r
+      stop_();\r
+      return TRUE;\r
+    case WM_PLAY_PAUSE:\r
+      pause_();\r
+      return TRUE;\r
+//    case WM_APP_PLAYER_EVENT:\r
+//      on_player_event(hwnd,wParam);\r
+//      return FALSE;\r
+      //::SetTimer(hwnd_,(UINT_PTR)&timer_id_,1000,NULL);\r
+    }\r
+\r
+    return FALSE;\r
+  };\r
+\r
+  void on_player_event(HWND wnd,UINT_PTR wParam)\r
+  {\r
+    application::instance()->Player()->HandleEvent(wParam);\r
+  }\r
+\r
+  LRESULT on_init_dialog(HWND default_focus_ctrl,LPARAM data)\r
+  {\r
+    init_control();\r
+    create_device();\r
+    timer_.start();\r
+    //MARGINS mgn = {-1};//left,right,top,bottom\r
+    //HRESULT hr = DwmExtendFrameIntoClientArea(hwnd_, &mgn);\r
+    return TRUE;\r
+  }\r
+\r
+  LRESULT on_size(uint32_t flag,uint32_t width,uint32_t height)\r
+  {\r
+    // バックバッファなどに関係するインターフェースを解放する\r
+    // バックバッファを解放する\r
+    if(init_)\r
+    {\r
+      int height = client_height_;\r
+      int width = client_width_;\r
+\r
+      calc_client_size();\r
+\r
+      int delta_height = client_height_ - height; \r
+\r
+      HWND hwnd_tab = GetDlgItem(hwnd_,IDC_TAB);\r
+      RECT rect_tab;\r
+      GetWindowRect(hwnd_tab,&rect_tab);\r
+\r
+\r
+      int tab_width(rect_tab.right - rect_tab.left),\r
+        tab_height(rect_tab.bottom - rect_tab.top);\r
+      int delta_width = width - tab_width; \r
+\r
+      SetWindowPos(hwnd_tab,0,0,0,client_width_ - delta_width,tab_height + delta_height,SWP_NOZORDER | SWP_NOMOVE);\r
+\r
+      for(int i = 0;i < tab_dialogs_.size();++i)\r
+      {\r
+        tab_dialogs_[i].resize();\r
+      }\r
+\r
+      //client_width_\r
+    }\r
+    // バックバッファなどに関係するインターフェースを再作成する\r
+\r
+    //if (render_target_)\r
+    //{\r
+    // D2D1_SIZE_U size;\r
+    // size.width = lParam & 0xFFFF;\r
+    // size.height = (lParam >> 16) & 0xFFFF; ;\r
+\r
+    // // Note: This method can fail, but it's okay to ignore the\r
+    // // error here -- it will be repeated on the next call to\r
+    // // EndDraw.\r
+    // render_target_->Resize(size);\r
+    //}\r
+    return TRUE;\r
+  }\r
+\r
+  LRESULT on_paint()\r
+  {\r
+    //create_device();\r
+\r
+    { \r
+      paint_struct begin_paint(hwnd_);\r
+      //CloseHandle(cb);\r
+      // 描画コードの呼び出し\r
+      /*render();*/\r
+\r
+    }\r
+    return FALSE;\r
+    //        ::ShowWindow(hwnd_,SW_MINIMIZE);\r
+\r
+  }\r
+\r
+  LRESULT on_display_change(uint32_t bpp,uint32_t h_resolution,uint32_t v_resolution)\r
+  {\r
+    invalidate_rect();\r
+    return TRUE;\r
+  }\r
+\r
+  LRESULT on_erase_backgroud(HDC dc)\r
+  {\r
+    return FALSE;\r
+  }\r
+\r
+  LRESULT on_hscroll(uint32_t state,uint32_t position,HWND ctrl_hwnd)\r
+  {\r
+    switch(state)\r
+    {\r
+    case TB_THUMBTRACK :\r
+\r
+#ifdef _DEBUG\r
+      wdout << L"TB_THUMBTRACK" << std::endl;\r
+#endif\r
+      thumb_start_ = true;\r
+      break;\r
+    case TB_ENDTRACK :\r
+#ifdef _DEBUG\r
+      wdout << L"TB_ENDTRACK" << std::endl;\r
+#endif\r
+//      application::instance()->reader_position(SendMessage(GetDlgItem(hwnd_,IDC_SLIDER), TBM_GETPOS, 0, 0) * application::instance()->reader_data_size() / SLIDER_MAX); \r
+\r
+      thumb_start_ = false;\r
+      break;\r
+    case TB_PAGEUP:\r
+      thumb_start_ = true;\r
+      break;\r
+    case TB_PAGEDOWN:\r
+      thumb_start_ = true;\r
+      break;\r
+    default:\r
+#ifdef _DEBUG\r
+      wdout << boost::wformat(L"LOWORD(wParam):%d") % state << std::endl;\r
+#endif\r
+      break;\r
+    }\r
+    return FALSE;\r
+  }\r
+\r
+  LRESULT on_destroy()\r
+  {\r
+    ::PostQuitMessage(0);\r
+    return FALSE;\r
+  }\r
+\r
+  LRESULT on_close()\r
+  {\r
+    //slider_.detatch();\r
+    timer_.player_stop();\r
+    // 後始末\r
+    discard_device();\r
+    // レンダーターゲットのリリース\r
+    //safe_release(dcr_);\r
+    //      safe_release(render_target_);\r
+    // Windowの破棄\r
+    BOOL ret(::DestroyWindow(hwnd_));\r
+    BOOST_ASSERT(ret != 0);\r
+    return TRUE;\r
+  }\r
+\r
+  LRESULT on_command(uint32_t wparam, uint32_t lparam)\r
+  {\r
+    switch(LOWORD(wparam)){\r
+    case IDC_FILE:\r
+      {\r
+        BOOL ret =  get_file_path();\r
+        if(ret){\r
+          sf::player::ev::OpenURL url(file_name_);\r
+          application::instance()->Player()->process_event(url);\r
+          //player_ready();\r
+        }\r
+      }\r
+       return TRUE;\r
+    case IDC_SLIDER:\r
+      //::MessageBox( hwnd_,L"SLIDERが動作しました。",L"IDC_SLIDER",MB_OK);\r
+      return TRUE;\r
+    case IDC_PLAY:\r
+      //         ::MessageBox( hwnd_,L"player_read_fileボタンが押されました。",L"IDC_PLAY",MB_OK);\r
+      application::instance()->Player()->process_event(player::ev::Play());\r
+      return TRUE;\r
+    case IDC_STOP:\r
+      //::MessageBox( hwnd_,L"player_stopボタンが押されました。",L"IDC_STOP",MB_OK);\r
+      application::instance()->Player()->process_event(player::ev::Stop());\r
+      return TRUE;\r
+    case IDC_PAUSE:\r
+      //::MessageBox( hwnd_,L"player_pauseボタンが押されました。",L"IDC_PAUSE",MB_OK);\r
+      application::instance()->Player()->process_event(player::ev::Pause());\r
+      return TRUE;\r
+    case IDC_REPEAT_CHECK:\r
+  //    application::instance()->reader_repeat_mode(::SendMessage(GetDlgItem(hwnd_,IDC_REPEAT_CHECK),BM_GETCHECK,0,0) == BST_CHECKED);\r
+      return TRUE;\r
+    }\r
+\r
+    //if(HIWORD(wParam) == THBN_CLICKED ){\r
+    //  switch(LOWORD(wParam)){\r
+    //  case THUMB_START:\r
+    //    {\r
+    //      if(status_ != player_stop)\r
+    //      {\r
+    //        update_status(player_stop);\r
+    //      } else {\r
+    //        update_status(active);\r
+    //      }\r
+    //    }\r
+    //    break;\r
+    //  }\r
+    //}\r
+    return FALSE;\r
+  }\r
+\r
+  LRESULT on_timer(uint32_t timer_id)\r
+  {\r
+    // TODO:スレッドのエラーチェックも入れておく\r
+    if(!thumb_start_){\r
+      //int status = application::instance()->reader_status(std::memory_order_relaxed);\r
+      //if( status == reader_agent_t::status_play_ok || status == reader_agent_t::status_end_ok)\r
+      //{\r
+      //  uint64_t pos = application::instance()->reader_position() * SLIDER_MAX / application::instance()->reader_data_size(); \r
+      //  SendMessage(GetDlgItem(hwnd_,IDC_SLIDER), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)pos);\r
+      //}\r
+    }\r
+    return TRUE;\r
+\r
+  }\r
+\r
+  LRESULT on_notify(NMHDR* nmhdr)\r
+  {\r
+    switch (nmhdr->code)\r
+    {\r
+    case TCN_SELCHANGE:\r
+      {\r
+        tab_page_ = TabCtrl_GetCurSel(nmhdr->hwndFrom);\r
+        for(int i = 0;i < tab_dialogs_.size();++ i)\r
+        {\r
+          if( i == tab_page_)\r
+          {\r
+            tab_dialogs_[i].show();\r
+          } else {\r
+            tab_dialogs_[i].hide();\r
+          }\r
+        }\r
+        return TRUE;\r
+        break;\r
+      }\r
+    }\r
+    return FALSE;\r
+  }\r
+\r
+  private:\r
+\r
+    void read_start() {};\r
+    BOOL get_file_path ()\r
+    {\r
+      WCHAR file_name[MAX_PATH]  = L"";  // ファイル名\r
+      WCHAR dir_name[MAX_PATH]   = L"";  // ディレクトリ\r
+\r
+      WCHAR file_title[MAX_PATH] = L"";  // ダイアログのタイトル\r
+      OPENFILENAME ofn;              \r
+\r
+      if (dir_name_.empty())\r
+      {\r
+        GetWindowsDirectory(dir_name, MAX_PATH);\r
+        dir_name_.assign(dir_name);\r
+      }\r
+\r
+      if(!file_name_.empty())\r
+      {\r
+        wcscpy_s(file_name,MAX_PATH,dir_name_.c_str());\r
+      }\r
+\r
+      // Set up structure for file dialog\r
+      ZeroMemory(&ofn, sizeof(ofn));\r
+      ofn.lStructSize = sizeof(OPENFILENAME);\r
+      ofn.hwndOwner = ::GetDesktopWindow();\r
+      ofn.lpstrFilter = L"Media File (*.*)\0*.*\0";\r
+      ofn.lpstrCustomFilter = NULL;\r
+      ofn.nFilterIndex = 1;\r
+      ofn.lpstrFile = file_name;\r
+      ofn.nMaxFile = MAX_PATH;\r
+      ofn.lpstrFileTitle = file_title;\r
+      ofn.nMaxFileTitle = MAX_PATH;\r
+      ofn.lpstrInitialDir = dir_name;\r
+      ofn.lpstrTitle = L"Mediaファイルを指定してください。";\r
+      ofn.lpstrDefExt = L"mp4";\r
+      ofn.Flags = OFN_SHAREAWARE | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;\r
+\r
+      // Put up Open File dialog to get file name.\r
+      if (GetOpenFileName(&ofn))\r
+      {\r
+        file_name_.assign(file_name);\r
+//        sf::application::instance()->reader_setup(file_name);\r
+      }\r
+      return TRUE;\r
+    }\r
+\r
+    //long wm_task_bar_create_;\r
+    //sf::taskbar taskbar_;\r
+\r
+    timer timer_;\r
+    bool thumb_start_;\r
+    //slider slider_;\r
+\r
+    //IDXGIFactory1Ptr dxgi_factory_;\r
+    //IDXGIAdapter1Ptr adapter_;\r
+    //IDXGIOutputPtr output_;\r
+    //ID3D11DevicePtr d3d_device_;\r
+    //ID3D11DeviceContextPtr d3d_context_;\r
+    //ID3D11Texture2DPtr texture_;\r
+    //ID3D11RenderTargetViewPtr view_;\r
+    //ID3D11Texture2DPtr depth_texture_;\r
+    //ID3D11DepthStencilViewPtr depth_view_;\r
+    //ID3D11VertexShaderPtr v_shader_;\r
+    //ID3D11InputLayoutPtr input_layout_;\r
+    //ID3D11PixelShaderPtr p_shader_;\r
+    //ID3D11BufferPtr v_buffer_;\r
+    //ID3D11BufferPtr i_buffer_;\r
+    //ID3D11BufferPtr cb_never_changes_;\r
+    //ID3D11BufferPtr cb_change_on_resize_;\r
+    //ID3D11BufferPtr cb_changes_every_frame_;\r
+    //ID3D11ShaderResourceViewPtr shader_res_view_;\r
+    //ID3D11SamplerStatePtr sampler_state_;\r
+\r
+    //DirectX::XMMATRIX                            mat_world_;\r
+    //DirectX::XMMATRIX                            mat_view_;\r
+    //DirectX::XMMATRIX                            mat_projection_;\r
+    //DirectX::XMFLOAT4                            mesh_color_;\r
+\r
+    float client_width_,client_height_;\r
+\r
+    //IDXGISwapChainPtr; \r
+    //IDXGISwapChainPtr swap_chain_;\r
+    // std::wstring dxgi_info_;\r
+\r
+    std::wstring file_name_;\r
+    std::wstring dir_name_;\r
+    icon icon_;\r
+    bool init_;\r
+\r
+    D2D1_SIZE_U icon_size_;\r
+\r
+    //  HWND hwnd_config_;\r
+    // HWND hwnd_info_;\r
+\r
+    boost::ptr_vector<tab_dialog_base> tab_dialogs_;\r
+    //tab_dialog_ptr config_dialog_;\r
+\r
+    int tab_page_;\r
+\r
+\r
+    // thisとhwndをつなぐthunkクラス\r
+    // メンバー関数を直接呼び出す。\r
+    struct hwnd_this_thunk2 : public Xbyak::CodeGenerator {\r
+      hwnd_this_thunk2(LONG_PTR this_addr,const void * proc)\r
+      {\r
+        // 引数の位置をひとつ後ろにずらす\r
+        mov(r10,r9);\r
+        mov(r9,r8);\r
+        mov(r8,rdx);\r
+        mov(rdx,rcx);\r
+        // thisのアドレスをrcxに格納する\r
+        mov(rcx,(LONG_PTR)this_addr);\r
+        // 第5引数をスタックに格納\r
+        push(r10);\r
+        sub(rsp,32);\r
+        mov(r10,(LONG_PTR)proc);\r
+        // メンバ関数呼び出し\r
+        call(r10);\r
+        add(rsp,40);\r
+        ret(0);\r
+      }\r
+    };\r
+\r
+    //hwnd_this_thunk2 thunk_info_;\r
+    //  hwnd_this_thunk2 thunk_config_;\r
+    //proc_t proc_info_;\r
+    //  proc_t proc_config_;\r
+\r
+  };\r
+\r
+  //\r
+  // Creates a Direct2D bitmap from the specified\r
+  // file name.\r
+  //\r
+  ID2D1BitmapPtr load_bitmap_from_file(\r
+    ID2D1HwndRenderTargetPtr render_target,\r
+    IWICImagingFactoryPtr wic_factory,\r
+    std::wstring uri,\r
+    uint32_t destination_width,\r
+    uint32_t destination_height\r
+    )\r
+  {\r
+    HRESULT hr = S_OK;\r
+\r
+    IWICBitmapDecoderPtr decoder;\r
+    IWICBitmapFrameDecodePtr decoder_source;\r
+    IWICStreamPtr stream;\r
+    IWICFormatConverterPtr converter;\r
+    IWICBitmapScalerPtr scaler;\r
+    ID2D1BitmapPtr bitmap;\r
+\r
+    THROW_IFERR(wic_factory->CreateDecoderFromFilename(\r
+      uri.c_str(),\r
+      NULL,\r
+      GENERIC_READ,\r
+      WICDecodeMetadataCacheOnLoad,\r
+      &decoder\r
+      ));\r
+\r
+    // Create the initial frame.\r
+    THROW_IFERR(decoder->GetFrame(0, &decoder_source));\r
+\r
+    // Convert the image format to 32bppPBGRA\r
+    // (DXGI_FORMAT_B8G8R8A8_UNORM + D2D1_ALPHA_MODE_PREMULTIPLIED).\r
+    THROW_IFERR(hr = wic_factory->CreateFormatConverter(&converter));\r
+\r
+    // If a new width or height was specified, create an\r
+    // IWICBitmapScaler and use it to resize the image.\r
+    if (destination_width != 0 || destination_height != 0)\r
+    {\r
+      uint32_t originalWidth, originalHeight;\r
+      THROW_IFERR(decoder_source->GetSize((UINT*)&originalWidth, (UINT*)&originalHeight));\r
+      if (destination_width == 0)\r
+      {\r
+        FLOAT scalar = static_cast<FLOAT>(destination_height) / static_cast<FLOAT>(originalHeight);\r
+        destination_width = static_cast<uint32_t>(scalar * static_cast<FLOAT>(originalWidth));\r
+      }\r
+      else if (destination_height == 0)\r
+      {\r
+        FLOAT scalar = static_cast<FLOAT>(destination_width) / static_cast<FLOAT>(originalWidth);\r
+        destination_height = static_cast<uint32_t>(scalar * static_cast<FLOAT>(originalHeight));\r
+      }\r
+\r
+      THROW_IFERR(wic_factory->CreateBitmapScaler(&scaler));\r
+      THROW_IFERR(scaler->Initialize(\r
+        decoder_source.Get(),\r
+        destination_width,\r
+        destination_height,\r
+        WICBitmapInterpolationModeCubic\r
+        ));\r
+      THROW_IFERR(converter->Initialize(\r
+        scaler.Get(),\r
+        GUID_WICPixelFormat32bppPBGRA,\r
+        WICBitmapDitherTypeNone,\r
+        NULL,\r
+        0.f,\r
+        WICBitmapPaletteTypeMedianCut\r
+        ));\r
+    }\r
+    else // Don't scale the image.\r
+    {\r
+      THROW_IFERR(converter->Initialize(\r
+        decoder_source.Get(),\r
+        GUID_WICPixelFormat32bppPBGRA,\r
+        WICBitmapDitherTypeNone,\r
+        NULL,\r
+        0.f,\r
+        WICBitmapPaletteTypeMedianCut\r
+        ));\r
+    }\r
+\r
+    // Create a Direct2D bitmap from the WIC bitmap.\r
+    THROW_IFERR(render_target->CreateBitmapFromWicBitmap(\r
+      converter.Get(),\r
+      NULL,\r
+      bitmap.GetAddressOf()\r
+      ));\r
+\r
+    return bitmap;\r
+  }\r
+\r
+\r
+  toplevel_window::toplevel_window(const std::wstring& menu_name,const std::wstring& name,bool fit_to_display,float width ,float height)\r
+    : impl_(new impl(menu_name,name,fit_to_display,width,height))\r
+  {\r
+\r
+  };\r
+\r
+  void * toplevel_window::raw_handle() const {return impl_->raw_handle();};\r
+  void toplevel_window::create(){impl_->create();};\r
+  void toplevel_window::show(){impl_->show();};\r
+  void toplevel_window::hide(){impl_->hide();};\r
+  bool toplevel_window::is_show(){return impl_->is_show();};\r
+  void toplevel_window::text(std::wstring& text){impl_->text(text);};\r
+  void toplevel_window::message_box(const std::wstring& text,const std::wstring& caption,uint32_t type )\r
+  {\r
+    impl_->message_box(text,caption,type);\r
+  };\r
+  void toplevel_window::update(){impl_->update();};\r
+  void toplevel_window::render(){impl_->render();};\r
+ // void toplevel_window::player_ready(){impl_->player_ready();};\r
+  void toplevel_window::player_read_file(){impl_->player_read_file();};\r
+  void toplevel_window::player_pause(){impl_->player_pause();};\r
+  void toplevel_window::player_stop(){impl_->player_stop();};\r
+\r
+  void toplevel_window::enable_control(uint32_t id,bool enable)\r
+  {\r
+    impl_->enable_control(id,enable);\r
+  };\r
+\r
+\r
+  toplevel_window_ptr create_toplevel_window\r
+    (\r
+    const std::wstring& menu_name,\r
+    const std::wstring& name,\r
+    const uint32_t show_flag,\r
+    bool fit_to_display,\r
+    float width,\r
+    float height\r
+    )\r
+  {\r
+    // クライアント領域のサイズからウィンドウサイズを設定\r
+    RECT    rect    = { 0, 0, width, height };\r
+    ::AdjustWindowRectEx( &rect, WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME, FALSE, 0 );\r
+    toplevel_window* p = new toplevel_window(menu_name,name,fit_to_display,rect.right - rect.left,rect.bottom - rect.top);\r
+    p->create();\r
+    p->show();\r
+    p->update();\r
+    return toplevel_window_ptr(p);\r
+  }\r
+  void dialogbox\r
+    (\r
+    const std::wstring& menu_name,\r
+    const std::wstring& name\r
+    )\r
+  {\r
+    toplevel_window_ptr p(new toplevel_window(menu_name,name,false));\r
+    p->create();\r
+  }\r
+\r
+\r
+\r
+\r
+}\r
+\r
diff --git a/mfsample/toplevel_window.h b/mfsample/toplevel_window.h
new file mode 100644 (file)
index 0000000..33d3ec2
--- /dev/null
@@ -0,0 +1,80 @@
+#pragma once\r
+/*\r
+*/\r
+// Windows Header Files:\r
+#include "sf_windows.h"\r
+#include "icon.h"\r
+#include "base_window.h"\r
+#include "taskbar.h"\r
+\r
+#define WM_PLAY_STOP WM_USER + 1\r
+#define WM_PLAY_PAUSE WM_USER + 2\r
+#define WM_PLAY_PLAY WM_USER + 3\r
+\r
+namespace sf\r
+{\r
+\r
+  struct toplevel_window;\r
+  typedef std::shared_ptr<toplevel_window> toplevel_window_ptr;\r
+\r
+  /** toplevel_window を生成する関数 */\r
+  toplevel_window_ptr create_toplevel_window (\r
+    const std::wstring& menu_name,\r
+    const std::wstring& name,\r
+    const uint32_t show_flag = SW_SHOW,\r
+    bool fit_to_display = false,\r
+    float width = 640,\r
+    float height = 480\r
+    );\r
+  /** toplevel_window を生成する関数 */\r
+  void dialogbox (\r
+    const std::wstring& menu_name,\r
+    const std::wstring& name\r
+    );\r
+\r
+  /** toplevel ウィンドウクラス */\r
+  /* このクラスは、create_toplevel_window 関数からのみ生成可能 */\r
+  struct toplevel_window : public base_window\r
+  {\r
+\r
+    friend   toplevel_window_ptr create_toplevel_window\r
+      (\r
+      const std::wstring& menu_name,\r
+      const std::wstring& name,\r
+      const uint32_t show_flag,\r
+      bool fit_to_display,\r
+      float width ,\r
+      float height\r
+      );\r
+\r
+    friend void dialogbox (\r
+      const std::wstring& menu_name,\r
+      const std::wstring& name\r
+    );\r
+\r
+    ~toplevel_window(){};\r
\r
+    void * raw_handle() const;\r
+    void create();\r
+    void toplevel_window::show();\r
+    bool toplevel_window::is_show();\r
+    void toplevel_window::hide();\r
+    void message_box(const std::wstring& text,const std::wstring& caption,uint32_t type = MB_OK);\r
+    void text(std::wstring& text);\r
+    void update();\r
+    void render();\r
+\r
+    void player_ready();\r
+    void player_read_file();\r
+    void player_pause();\r
+    void player_stop();\r
+   \r
+    void enable_control(uint32_t id,bool enable);\r
+\r
+  private:\r
+    struct impl;\r
+    toplevel_window(const std::wstring& menu_name,const std::wstring& name,bool fit_to_display,float width = 800 ,float height = 600);\r
+    // 実装部\r
+    std::shared_ptr<impl> impl_;\r
+  };\r
+}
\ No newline at end of file
diff --git a/mfsample/wasapi2.rc b/mfsample/wasapi2.rc
new file mode 100644 (file)
index 0000000..062360f
--- /dev/null
@@ -0,0 +1,122 @@
+// Generated by ResEdit 1.5.11\r
+// Copyright (C) 2006-2012\r
+// http://www.resedit.net\r
+\r
+#include <windows.h>\r
+#include <commctrl.h>\r
+#include <richedit.h>\r
+#include "resource.h"\r
+\r
+\r
+\r
+\r
+//\r
+// Dialog resources\r
+//\r
+LANGUAGE LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN\r
+IDD_CONFIG DIALOG 0, 0, 300, 200\r
+STYLE DS_3DLOOK | DS_CENTER | DS_SHELLFONT | WS_VISIBLE | WS_CHILDWINDOW | WS_SYSMENU\r
+FONT 9, "\83\81\83C\83\8a\83I"\r
+{\r
+    AUTOCHECKBOX    "\94r\91¼\83\82\81[\83h", IDC_EXC_MODE, 166, 20, 50, 8, 0, WS_EX_TRANSPARENT\r
+    COMBOBOX        IDC_ENDPOINT_DEVICE, 40, 3, 250, 15, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS\r
+    COMBOBOX        IDC_SAMPLE_BIT, 40, 18, 35, 12, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS\r
+    LTEXT           "\8fo\97Í", IDC_STATIC, 7, 5, 15, 8, SS_LEFT, WS_EX_TRANSPARENT\r
+    LTEXT           "\83r\83b\83g\90\94", IDC_STATIC, 7, 20, 28, 8, SS_LEFT, WS_EX_TRANSPARENT\r
+    LTEXT           "\8eÀ\8dÛ\83r\83b\83g\90\94", IDC_STATIC, 77, 20, 42, 8, SS_LEFT, WS_EX_TRANSPARENT\r
+    COMBOBOX        IDC_VALID_SAMPLE_BITS, 124, 18, 40, 15, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS\r
+    COMBOBOX        IDC_SAMPLE_RATE, 124, 33, 40, 15, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS\r
+    LTEXT           "\8eü\94g\90\94", IDC_STATIC, 77, 35, 22, 8, SS_LEFT, WS_EX_TRANSPARENT\r
+    PUSHBUTTON      "\93K\97p", IDC_APPLY, 205, 175, 39, 14\r
+    PUSHBUTTON      "\83L\83\83\83\93\83Z\83\8b", IDC_CANCEL, 250, 175, 39, 14\r
+    LTEXT           "\83o\83b\83t\83@ms", IDC_STATIC, 166, 35, 39, 8, SS_LEFT, WS_EX_TRANSPARENT\r
+    COMBOBOX        IDC_CHANNEL, 40, 33, 35, 15, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS\r
+    LTEXT           "\83`\83\83\83l\83\8b", IDC_STATIC, 7, 35, 28, 8, SS_LEFT, WS_EX_TRANSPARENT\r
+    EDITTEXT        IDC_LATENCY, 206, 33, 25, 12, ES_AUTOHSCROLL\r
+    LTEXT           "Static", IDC_MIN_MAX_LATENCY, 232, 35, 68, 10, SS_LEFT\r
+    AUTOCHECKBOX    "\83C\83x\83\93\83g\83\82\81[\83h", IDC_EVENT_MODE, 218, 20, 64, 8, 0, WS_EX_TRANSPARENT\r
+    LTEXT           "\93ü\97Í", IDC_STATIC, 7, 50, 15, 8, SS_LEFT, WS_EX_TRANSPARENT\r
+    COMBOBOX        IDC_INPUT_ENDPOINT_DEVICE, 40, 50, 250, 15, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS\r
+    AUTOCHECKBOX    "\94r\91¼\83\82\81[\83h", IDC_INPUT_EXC_MODE, 166, 66, 50, 8, 0, WS_EX_TRANSPARENT\r
+    COMBOBOX        IDC_INPUT_SAMPLE_BIT, 40, 64, 35, 12, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS\r
+    LTEXT           "\83r\83b\83g\90\94", IDC_STATIC, 7, 66, 28, 8, SS_LEFT, WS_EX_TRANSPARENT\r
+    LTEXT           "\8eÀ\8dÛ\83r\83b\83g\90\94", IDC_STATIC, 79, 66, 42, 8, SS_LEFT, WS_EX_TRANSPARENT\r
+    COMBOBOX        IDC_INPUT_VALID_SAMPLE_BITS, 124, 64, 40, 15, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS\r
+    COMBOBOX        IDC_INPUT_SAMPLE_RATE, 124, 79, 40, 15, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS\r
+    LTEXT           "\8eü\94g\90\94", IDC_STATIC, 79, 81, 22, 8, SS_LEFT, WS_EX_TRANSPARENT\r
+    LTEXT           "\83o\83b\83t\83@ms", IDC_STATIC, 166, 81, 39, 8, SS_LEFT, WS_EX_TRANSPARENT\r
+    COMBOBOX        IDC_INPUT_CHANNEL, 40, 79, 35, 15, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS\r
+    LTEXT           "\83`\83\83\83l\83\8b", IDC_STATIC, 7, 81, 28, 8, SS_LEFT, WS_EX_TRANSPARENT\r
+    EDITTEXT        IDC_INPUT_LATENCY, 206, 79, 25, 12, ES_AUTOHSCROLL\r
+    AUTOCHECKBOX    "\83C\83x\83\93\83g\83\82\81[\83h", IDC_INPUT_EVENT_MODE, 218, 66, 64, 8, 0, WS_EX_TRANSPARENT\r
+    LTEXT           "Static", IDC_INPUT_MIN_MAX_LATENCY, 232, 81, 65, 10, SS_LEFT\r
+}\r
+\r
+\r
+\r
+LANGUAGE LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN\r
+IDD_INFO DIALOG 0, 0, 304, 200\r
+STYLE DS_CENTER | DS_SHELLFONT | WS_VISIBLE | WS_CHILDWINDOW | WS_SYSMENU\r
+FONT 9, "\83\81\83C\83\8a\83I"\r
+{\r
+    LTEXT           "Static", IDC_INFO, 4, 2, 298, 35, SS_LEFT, WS_EX_TRANSPARENT\r
+    CONTROL         "", IDC_WAVEFORM, WC_STATIC, SS_BLACKFRAME, 1, 39, 301, 59\r
+    CONTROL         "", IDC_VIDEO, WC_STATIC, SS_BLACKFRAME, 1, 101, 218, 96\r
+}\r
+\r
+\r
+\r
+LANGUAGE LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN\r
+IDD_MAINDIALOG DIALOG 0, 0, 544, 285\r
+STYLE DS_3DLOOK | DS_CENTER | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_GROUP | WS_TABSTOP | WS_THICKFRAME | WS_SYSMENU\r
+EXSTYLE WS_EX_WINDOWEDGE | WS_EX_APPWINDOW\r
+CAPTION "Media Foundation \8dÄ\90\83e\83X\83g"\r
+FONT 9, "\83\81\83C\83\8a\83I"\r
+{\r
+    PUSHBUTTON      "\83t\83@\83C\83\8b", IDC_FILE, 5, 5, 40, 14 ,WS_DISABLED\r
+    PUSHBUTTON      "\8dÄ\90¶", IDC_PLAY, 48, 5, 40, 14, WS_DISABLED\r
+    PUSHBUTTON      "\88ê\8e\9e\92â\8e~", IDC_PAUSE, 91, 5, 40, 14, WS_DISABLED\r
+    PUSHBUTTON      "\92â\8e~", IDC_STOP, 134, 5, 40, 14, WS_DISABLED\r
+    CONTROL         "", IDC_SLIDER, TRACKBAR_CLASS, WS_TABSTOP | WS_DISABLED | TBS_BOTH | TBS_NOTICKS, 2, 24, 535, 15\r
+    AUTOCHECKBOX    "\83\8a\83s\81[\83g", IDC_REPEAT_CHECK, 179, 8, 43, 8, WS_DISABLED\r
+    CONTROL         "", IDC_TAB, WC_TABCONTROL, 0, 5, 40, 535, 245\r
+}\r
+\r
+\r
+\r
+LANGUAGE LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN\r
+IDD_SEQ DIALOG 0, 0, 504, 284\r
+STYLE DS_CENTER | DS_SHELLFONT | WS_VISIBLE | WS_CHILDWINDOW\r
+FONT 9, "\83\81\83C\83\8a\83I"\r
+{\r
+    EDITTEXT        IDC_EDIT1, 50, 5, 445, 12, NOT WS_BORDER | ES_AUTOHSCROLL | ES_WANTRETURN\r
+    LTEXT           "Song Name", IDC_STATIC, 5, 5, 45, 10, SS_LEFT\r
+    SCROLLBAR       IDC_SCROLLBAR1, 491, 95, 10, 174, SBS_VERT\r
+    LTEXT           "Comment", IDC_STATIC, 5, 15, 34, 8, SS_LEFT\r
+    EDITTEXT        IDC_EDIT2, 50, 15, 445, 12, NOT WS_BORDER | ES_AUTOHSCROLL\r
+    LTEXT           "Tempo", IDC_STATIC, 5, 25, 40, 10, SS_LEFT\r
+    EDITTEXT        IDC_EDIT3, 50, 25, 50, 12, NOT WS_BORDER | ES_AUTOHSCROLL\r
+    LTEXT           "Key", IDC_STATIC, 105, 25, 14, 8, SS_LEFT\r
+    EDITTEXT        IDC_EDIT4, 145, 25, 50, 12, NOT WS_BORDER | ES_AUTOHSCROLL\r
+    LTEXT           "Key", IDC_STATIC, 5, 40, 14, 8, SS_LEFT\r
+    CONTROL         "", IDC_SEQ_AREA, WC_STATIC, SS_BLACKFRAME, 39, 76, 434, 143\r
+}\r
+\r
+\r
+\r
+//\r
+// String Table resources\r
+//\r
+LANGUAGE LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN\r
+STRINGTABLE\r
+{\r
+    IDS_STRING1                   "\83T\83\93\83v\83\8b\83e\83L\83X\83g"\r
+}\r
+\r
+\r
+\r
+//\r
+// Icon resources\r
+//\r
+LANGUAGE LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN\r
+IDI_ICON1          ICON           "directx.ico"\r
diff --git a/mfsample/winmain.cpp b/mfsample/winmain.cpp
new file mode 100644 (file)
index 0000000..3aede80
--- /dev/null
@@ -0,0 +1,15 @@
+#include "stdafx.h"
+#include "application.h"
+
+
+//#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
+/** WinMain */
+int APIENTRY _tWinMain(HINSTANCE hInstance,
+                     HINSTANCE hPrevInstance,
+                     LPTSTR    lpCmdLine,
+                     int       nCmdShow)
+{
+       
+  return sf::application::instance()
+    ->execute( hInstance,hPrevInstance,lpCmdLine,nCmdShow);
+}