OSDN Git Service

最初のコミット
authorSFPGMR <sfpg@git.sourceforge.jp>
Sat, 25 Jun 2011 21:54:52 +0000 (06:54 +0900)
committerSFPGMR <sfpg@git.sourceforge.jp>
Sat, 25 Jun 2011 21:54:52 +0000 (06:54 +0900)
55 files changed:
.gitignore [new file with mode: 0644]
SF.props [new file with mode: 0644]
dxgi_test.sln [new file with mode: 0644]
dxgi_test/DeclareDPIAware.manifest [new file with mode: 0644]
dxgi_test/application.cpp [new file with mode: 0644]
dxgi_test/application.h [new file with mode: 0644]
dxgi_test/audio_base.cpp [new file with mode: 0644]
dxgi_test/audio_base.h [new file with mode: 0644]
dxgi_test/base_window.cpp [new file with mode: 0644]
dxgi_test/base_window.h [new file with mode: 0644]
dxgi_test/code_converter.cpp [new file with mode: 0644]
dxgi_test/code_converter.h [new file with mode: 0644]
dxgi_test/dout.h [new file with mode: 0644]
dxgi_test/dpi.cpp [new file with mode: 0644]
dxgi_test/dpi.h [new file with mode: 0644]
dxgi_test/dxgi_test.vcxproj [new file with mode: 0644]
dxgi_test/dxgi_test.vcxproj.filters [new file with mode: 0644]
dxgi_test/dxgi_test.vcxproj.user [new file with mode: 0644]
dxgi_test/exception.cpp [new file with mode: 0644]
dxgi_test/exception.h [new file with mode: 0644]
dxgi_test/icon.cpp [new file with mode: 0644]
dxgi_test/icon.h [new file with mode: 0644]
dxgi_test/icon.svg [new file with mode: 0644]
dxgi_test/icon1.ico [new file with mode: 0644]
dxgi_test/icon1_1.ico [new file with mode: 0644]
dxgi_test/icon2.ico [new file with mode: 0644]
dxgi_test/icon_16.png [new file with mode: 0644]
dxgi_test/icon_256.png [new file with mode: 0644]
dxgi_test/icon_32.png [new file with mode: 0644]
dxgi_test/icon_48.png [new file with mode: 0644]
dxgi_test/jumplist.cpp [new file with mode: 0644]
dxgi_test/jumplist.h [new file with mode: 0644]
dxgi_test/logger.cpp [new file with mode: 0644]
dxgi_test/logger.h [new file with mode: 0644]
dxgi_test/message_loop.h [new file with mode: 0644]
dxgi_test/minitimer.rc [new file with mode: 0644]
dxgi_test/resource.h [new file with mode: 0644]
dxgi_test/sf_com.h [new file with mode: 0644]
dxgi_test/sf_memory.h [new file with mode: 0644]
dxgi_test/sf_windows.cpp [new file with mode: 0644]
dxgi_test/sf_windows.h [new file with mode: 0644]
dxgi_test/singleton.h [new file with mode: 0644]
dxgi_test/start.ico [new file with mode: 0644]
dxgi_test/stdafx.cpp [new file with mode: 0644]
dxgi_test/stdafx.h [new file with mode: 0644]
dxgi_test/stop.ico [new file with mode: 0644]
dxgi_test/taskbar.cpp [new file with mode: 0644]
dxgi_test/taskbar.h [new file with mode: 0644]
dxgi_test/timer.cpp [new file with mode: 0644]
dxgi_test/timer.h [new file with mode: 0644]
dxgi_test/toplevel_window.cpp [new file with mode: 0644]
dxgi_test/toplevel_window.h [new file with mode: 0644]
dxgi_test/wasapi.cpp [new file with mode: 0644]
dxgi_test/wasapi.h [new file with mode: 0644]
dxgi_test/winmain.cpp [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..d08b7db
--- /dev/null
@@ -0,0 +1,5 @@
+*.sdf
+*.suo
+Debug/
+Release/
+ipch/
\ No newline at end of file
diff --git a/SF.props b/SF.props
new file mode 100644 (file)
index 0000000..62d8181
--- /dev/null
+++ b/SF.props
@@ -0,0 +1,24 @@
+<?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\boost\include\boost-1_46_1;H:\libs\xbyak\xbyak;H:\libs\zlib125\zlib-1.2.5;H:\libs\lpng150\lpng150;$(IncludePath)</IncludePath>
+  </PropertyGroup>
+  <PropertyGroup>
+    <LibraryPath>H:\libs\boost\lib;H:\libs\zlib125\zlib-1.2.5;$(LibraryPath)</LibraryPath>
+  </PropertyGroup>
+  <ItemDefinitionGroup>
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>
+      <PrecompiledHeader>Use</PrecompiledHeader>
+      <RuntimeTypeInfo>true</RuntimeTypeInfo>
+      <Optimization>MaxSpeed</Optimization>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+      <EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
+    </ClCompile>
+  </ItemDefinitionGroup>
+  <ItemGroup />
+</Project>
\ No newline at end of file
diff --git a/dxgi_test.sln b/dxgi_test.sln
new file mode 100644 (file)
index 0000000..90311ea
--- /dev/null
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual C++ Express 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dxgi_test", "dxgi_test\dxgi_test.vcxproj", "{454B96E9-B255-4909-A167-7DFA3E4873A5}"
+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
+               {454B96E9-B255-4909-A167-7DFA3E4873A5}.Debug|Win32.ActiveCfg = Debug|x64
+               {454B96E9-B255-4909-A167-7DFA3E4873A5}.Debug|Win32.Build.0 = Debug|x64
+               {454B96E9-B255-4909-A167-7DFA3E4873A5}.Debug|x64.ActiveCfg = Debug|x64
+               {454B96E9-B255-4909-A167-7DFA3E4873A5}.Debug|x64.Build.0 = Debug|x64
+               {454B96E9-B255-4909-A167-7DFA3E4873A5}.Release|Win32.ActiveCfg = Release|x64
+               {454B96E9-B255-4909-A167-7DFA3E4873A5}.Release|x64.ActiveCfg = Release|x64
+               {454B96E9-B255-4909-A167-7DFA3E4873A5}.Release|x64.Build.0 = Release|x64
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
+       EndGlobalSection
+EndGlobal
diff --git a/dxgi_test/DeclareDPIAware.manifest b/dxgi_test/DeclareDPIAware.manifest
new file mode 100644 (file)
index 0000000..96e65a5
--- /dev/null
@@ -0,0 +1,7 @@
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"  xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
+   <asmv3:application>
+     <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
+       <dpiAware>true</dpiAware>
+     </asmv3:windowsSettings>
+   </asmv3:application>
+ </assembly>
\ No newline at end of file
diff --git a/dxgi_test/application.cpp b/dxgi_test/application.cpp
new file mode 100644 (file)
index 0000000..19be347
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+  ==============================================================================
+
+   This file is part of the mini timer
+   Copyright 2005-10 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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 "sf_memory.h"
+#include "icon.h"
+#include "toplevel_window.h"
+#include "message_loop.h"
+#include "sf_com.h"
+#include "application.h"
+
+#ifndef HINST_THISCOMPONENT
+EXTERN_C IMAGE_DOS_HEADER __ImageBase;
+#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase)
+#endif
+
+
+
+namespace sf {
+#ifdef _DEBUG
+  std::wstring application::app_id_(L"SF.MiniTimerDebug");
+#else
+  std::wstring application::app_id_(L"SF.MiniTimer");
+#endif
+application::application()
+{
+  instance_handle_ = HINST_THISCOMPONENT;
+}
+
+int application::execute(HINSTANCE hInstance,
+                     HINSTANCE hPrevInstance,
+                     LPTSTR    lpCmdLine,
+                     int       nCmdShow)
+{
+#ifdef _DEBUG
+  ::_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF);
+#endif
+  UNREFERENCED_PARAMETER(hPrevInstance);
+       UNREFERENCED_PARAMETER(lpCmdLine);
+  std::wcout.imbue(std::locale(""));
+
+  // 2\8fd\8bN\93®\82Ì\96h\8e~
+       SECURITY_DESCRIPTOR sd;
+       InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
+       SetSecurityDescriptorDacl(&sd, TRUE, 0, FALSE);     
+       SECURITY_ATTRIBUTES sec_attr;
+       sec_attr.nLength = sizeof (sec_attr);
+       sec_attr.lpSecurityDescriptor = &sd;
+       sec_attr.bInheritHandle = TRUE; 
+#ifdef _DEBUG 
+  sf::handle_holder handle(::CreateMutex(&sec_attr, FALSE, _T("wintimer_mutex_debug")));
+#else
+  sf::handle_holder handle(::CreateMutex(&sec_attr, FALSE, _T("wintimer_mutex")));
+#endif
+
+       if(NULL == handle.get() || ::GetLastError() == ERROR_ALREADY_EXISTS)
+       {
+    return 0;
+       }
+
+  // COM\82Ì\8f\89\8aú\89»
+  sf::com_initialize init();
+
+  // \83A\83v\83\8a\83P\81[\83V\83\87\83\93ID\82Ì\93o\98^
+  sf::throw_if_err<application::exception>()(SetCurrentProcessExplicitAppUserModelID(app_id_.c_str()));
+  
+  // \83E\83B\83\93\83h\83E\82Ì\8dì\90¬
+  sf::toplevel_window_ptr 
+    window(
+      sf::create_toplevel_window(
+        std::wstring(L"DXGI\83e\83X\83g"),std::wstring(L"DXGI\83e\83X\83g")));
+  
+  // \83\81\83b\83Z\81[\83W\83\8b\81[\83v\82Ì\8eÀ\8ds
+  WPARAM ret = sf::run_message_loop()();
+  return ret;
+}
+
+}
+
diff --git a/dxgi_test/application.h b/dxgi_test/application.h
new file mode 100644 (file)
index 0000000..36ca352
--- /dev/null
@@ -0,0 +1,55 @@
+#pragma once
+/*
+  ==============================================================================
+
+   This file is part of the mini timer
+   Copyright 2005-10 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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 "singleton.h"
+#include "exception.h"
+namespace sf {
+class application : public singleton<application>
+{
+public:
+  struct exception
+    : public sf::win32_error_exception 
+  {
+    exception(uint32_t hr) : win32_error_exception(hr) {};
+    exception() : win32_error_exception() {} ;
+  };
+
+  application();
+  ~application(){};
+  
+  int execute(HINSTANCE hInstance,
+                     HINSTANCE hPrevInstance,
+                     LPTSTR    lpCmdLine,
+                     int       nCmdShow);
+  
+
+  std::wstring& app_id(){return app_id_;};
+  HINSTANCE instance_handle() {return instance_handle_;};
+
+private:
+  static std::wstring app_id_;
+  HINSTANCE instance_handle_;
+  int return_code_;
+};
+}
+
diff --git a/dxgi_test/audio_base.cpp b/dxgi_test/audio_base.cpp
new file mode 100644 (file)
index 0000000..c395e21
--- /dev/null
@@ -0,0 +1,24 @@
+#include "StdAfx.h"
+#include "audio_base.h"
+/*
+  ==============================================================================
+
+   Copyright 2005-11 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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
+
+  ==============================================================================
+*/
+
diff --git a/dxgi_test/audio_base.h b/dxgi_test/audio_base.h
new file mode 100644 (file)
index 0000000..226e178
--- /dev/null
@@ -0,0 +1,29 @@
+#pragma once
+/*
+  ==============================================================================
+
+   Copyright 2005-11 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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 audio_base : boost::noncopyable
+{
+
+};
+}
+
diff --git a/dxgi_test/base_window.cpp b/dxgi_test/base_window.cpp
new file mode 100644 (file)
index 0000000..865ae33
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+  ==============================================================================
+
+   This file is part of the mini timer
+   Copyright 2005-10 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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/dxgi_test/base_window.h b/dxgi_test/base_window.h
new file mode 100644 (file)
index 0000000..0168469
--- /dev/null
@@ -0,0 +1,67 @@
+#pragma once
+/*
+  ==============================================================================
+
+   This file is part of the mini timer
+   Copyright 2005-10 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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 {
+/** window \83x\81[\83X\83N\83\89\83X */
+
+struct rect {
+  uint32_t width;
+  uint32_t height;
+};
+
+struct base_window : boost::noncopyable
+{
+  typedef boost::signals2::signal<void ()> on_render_type;
+
+  on_render_type on_render;
+  
+  // \90\82ÌWindow\83n\83\93\83h\83\8b\82ð\95Ô\82·\81B
+  virtual void * raw_handle() const = 0;
+  // \83E\83B\83\93\83h\83E\82ð\90\90¬\82·\82é
+  virtual void create() = 0;
+//  virtual void show(uint32_t show_flag) = 0;
+  // \83E\83B\83\93\83h\83E\82ð\95\\8e¦\82·\82é
+  virtual void show() = 0;
+  // \83E\83B\83\93\83h\83E\82ª\8d¡\95\\8e¦\82³\82ê\82Ä\82¢\82é\82©\82ð\95Ô\82·
+  virtual bool is_show() = 0;
+  // \83E\83B\83\93\83h\83E\82ð\89B\82·
+  virtual void hide() = 0;
+  //virtual void activate() = 0;
+  //virtual bool is_activate() = 0;
+  //virtual void deactivate() = 0;
+  //virtual void 
+  //virtual void size(uint32_t width,uint32_t height); 
+  //virtual rect size(); 
+
+  virtual void text(std::wstring& text) = 0;
+  //virtual std::wstring text() = 0;
+
+  virtual void update() = 0;
+
+protected:
+  virtual ~base_window() {};
+
+};
+
+}
+
diff --git a/dxgi_test/code_converter.cpp b/dxgi_test/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/dxgi_test/code_converter.h b/dxgi_test/code_converter.h
new file mode 100644 (file)
index 0000000..0132f8e
--- /dev/null
@@ -0,0 +1,79 @@
+#pragma once
+
+
+/** @file
+ *  @author S.F. (Satoshi Fujiwara)
+ *  @brief wchar_t <--> char の変換ユーティリティ
+ *  引数として文字列を引き渡す際、変換が必要な場合、下記のようにアダプタ的に使用することを想定している。
+ *  std::wstring a(L"abcd");
+ *  std::wstring b((sf::code_converter<wcha_t,char>(a)));
+ *
+ * 後、ATLコード差し替え用のtypedefも用意している。
+ *  これは、アダプタとしての利用のみに限定される。
+ *  sf::ct2a hoge_(L"abcef"); // 想定していない(動作する場合もあるし、ダメな場合もある)
+ */
+
+namespace sf 
+{
+    /** 雛形 */
+    template <typename SrcChar,typename DestChar>
+    struct code_converter
+    {
+    public:
+        explicit code_converter(SrcChar* p);
+        explicit code_converter(std::basic_string<SrcChar> & p);
+        operator DestChar*();
+    };
+
+    /** char -> wchar_tへの変換 */
+    template <>
+    struct code_converter<char,wchar_t>
+    {
+        explicit code_converter(const char* p);
+        explicit code_converter(const std::string& p);
+
+        operator wchar_t*() const {return m_dest.get();}
+    private:
+        boost::scoped_array<wchar_t> m_dest;
+    };
+
+    /** wchar_t -> char */
+    template <>
+    struct code_converter<wchar_t,char>
+    {
+        explicit code_converter(const wchar_t* p);
+        explicit code_converter(const std::wstring& p);
+        operator char* () const {return m_dest.get();}
+    private:
+        boost::scoped_array<char> m_dest;
+    };
+
+    /** ATLコード差し替えのためのエイリアス */
+    typedef sf::code_converter<char,wchar_t> ca2w;
+
+    /** ATLコード差し替えのためのエイリアス */
+    typedef sf::code_converter<wchar_t,char> cw2a;
+
+    #ifdef _UNICODE
+
+        /** ATLコード差し替えのためのエイリアス */
+        typedef sf::code_converter<char,wchar_t> ca2t;
+        /** ATLコード差し替えのためのエイリアス */
+        typedef sf::code_converter<wchar_t,char> ct2a;
+
+        /** ATLコード差し替えのためのエイリアス */
+        inline const wchar_t* ct2w(const wchar_t* p) { return p;};
+        /** ATLコード差し替えのためのエイリアス */
+        inline const wchar_t* cw2t(const wchar_t* p) { return p;};
+
+    #else
+
+        /** ATLコード差し替えのためのエイリアス */
+        inline const char* ct2a(const char* p) { return p;};
+        /** ATLコード差し替えのためのエイリアス */
+        inline const char* ca2t(const char* p) { return p;};
+
+    #endif
+}
+
+
diff --git a/dxgi_test/dout.h b/dxgi_test/dout.h
new file mode 100644 (file)
index 0000000..a7dbe01
--- /dev/null
@@ -0,0 +1,78 @@
+#pragma once
+
+/* http://vision.kuee.kyoto-u.ac.jp/~nob/doc/win32/win32.html#doc1_42 
+       \82æ\82è\94q\8eØ
+*/
+
+
+#ifndef STDX_DSTREAM_H
+
+#define STDX_DSTREAM_H
+
+namespace sf
+{
+  
+// VC++ \82Å STLport \82¾\82Æ using std::char_traits; \82Ý\82½\82¢\82È\82Ì\82ª\95K\97v\82©\82à
+template <typename Ch_T, typename Tr_T = std::char_traits<Ch_T> >
+class basic_dbg_streambuf: public std::basic_stringbuf<Ch_T, Tr_T>
+{
+public:
+  basic_dbg_streambuf()
+    {
+#ifndef STDX_DSTREAM_BUFFERING
+      setbuf(0,0);
+#endif
+    }
+
+  virtual ~basic_dbg_streambuf()
+    {
+      sync();
+    }
+
+protected:
+  int sync(void)
+    {
+      dbg_out(str().c_str());
+      pbump(static_cast<int>(pbase() - pptr()));
+      return 0;
+    }
+
+  void dbg_out(const Ch_T*);
+};
+
+template <>
+inline void basic_dbg_streambuf<char>::dbg_out(const char *str)
+{
+  ::OutputDebugStringA(str);
+}
+
+template <>
+inline void basic_dbg_streambuf<wchar_t>::dbg_out(const wchar_t *str)
+{
+  ::OutputDebugStringW(str);
+}
+
+template <typename Ch_T, typename Tr_T = std::char_traits<Ch_T> >
+class basic_dbg_ostream: public std::basic_ostream<Ch_T, Tr_T>
+{
+public:
+  basic_dbg_ostream() : std::basic_ostream<Ch_T, Tr_T>(new basic_dbg_streambuf<Ch_T, Tr_T>())
+    {
+    }
+
+  virtual ~basic_dbg_ostream()
+    {
+      // flush(); // \95s\97v\82ç\82µ\82¢\81Dhttp://www.tietew.jp/cppll/archive/607
+      delete rdbuf();
+    }
+};
+
+typedef basic_dbg_streambuf<wchar_t>  wdbg_streambuf;
+typedef basic_dbg_ostream<wchar_t> wdstream;
+
+// \82±\82ê\82ð\92è\8b`\82µ\82Ä\82¨\82­\82Æ\81C dout \82Ì\90é\8c¾\82ª\82¢\82ç\82È\82­\82È\82é\81D
+static wdstream wdout;
+
+}
+
+#endif // STDX_DSTREAM_
\ No newline at end of file
diff --git a/dxgi_test/dpi.cpp b/dxgi_test/dpi.cpp
new file mode 100644 (file)
index 0000000..13dc2d0
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+  ==============================================================================
+
+   This file is part of the mini timer
+   Copyright 2005-10 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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/dxgi_test/dpi.h b/dxgi_test/dpi.h
new file mode 100644 (file)
index 0000000..b9612a2
--- /dev/null
@@ -0,0 +1,83 @@
+#pragma once
+/*
+  ==============================================================================
+
+   This file is part of the mini timer
+   Copyright 2005-10 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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{
+  class dpi
+  {
+  public:
+    dpi() : init_(false), dpi_x_(96), dpi_y_(96) { }
+    // \89æ\96Ê\82Ì DPI \82ð\8eæ\93¾\82µ\82Ü\82·\81B
+    int dpix() { init(); return dpi_x_; }
+    int dpiy() { init(); return dpi_y_; }
+
+    // \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
+    int scale_x(int x) { init(); return MulDiv(x, dpi_x_, 96); }
+    int scale_y(int y) { init(); return MulDiv(y, dpi_y_, 96); }
+    int unscale_x(int x) { init(); return MulDiv(x, 96, dpi_x_); }
+    int unscale_y(int y) { init(); return MulDiv(y, 96, dpi_y_); }
+
+    // \89æ\96Ê\83T\83C\83Y (\91\8a\91Î\83s\83N\83Z\83\8b\92P\88Ê) \82ð\8b\81\82ß\82Ü\82·\81B
+    int scaled_screen_width() { return scaled_system_metrix_x(SM_CXSCREEN); }
+    int scaled_screen_height() { return scaled_system_metrix_y(SM_CYSCREEN); }
+
+    // \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
+    void scale_rect(RECT *rect_ptr)
+    {
+      rect_ptr->left = scale_x(rect_ptr->left);
+      rect_ptr->right = scale_x(rect_ptr->right);
+      rect_ptr->top = scale_y(rect_ptr->top);
+      rect_ptr->bottom = scale_y(rect_ptr->bottom);
+    }
+
+    // \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ð
+    // \8am\94F\82µ\82Ü\82·\81B
+    bool is_resolution_at_least(int xmin, int ymin) 
+    { 
+      return (scaled_screen_width() >= xmin) && (scaled_screen_height() >= ymin); 
+    }
+    // \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
+    int point_to_pixels(int pt) { return MulDiv(pt, dpi_y_, 72); }
+    // \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
+    void invalidate() { init_ = false; }
+  private:
+    void init();
+
+    int scaled_system_metrix_x(int nIndex) 
+    { 
+      init(); 
+      return MulDiv(GetSystemMetrics(nIndex), 96, dpi_x_); 
+    }
+
+    int scaled_system_metrix_y(int nIndex) 
+    { 
+      init(); 
+      return MulDiv(GetSystemMetrics(nIndex), 96, dpi_y_); 
+    }
+
+  private:
+    bool init_;
+    int dpi_x_;
+    int dpi_y_;
+  };
+}
diff --git a/dxgi_test/dxgi_test.vcxproj b/dxgi_test/dxgi_test.vcxproj
new file mode 100644 (file)
index 0000000..98a127f
--- /dev/null
@@ -0,0 +1,130 @@
+<?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|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{454B96E9-B255-4909-A167-7DFA3E4873A5}</ProjectGuid>
+    <RootNamespace>dxgi_test</RootNamespace>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>Unicode</CharacterSet>
+    <PlatformToolset>Windows7.1SDK</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+    <PlatformToolset>Windows7.1SDK</PlatformToolset>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="..\SF.props" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="..\SF.props" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <IncludePath>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;$(IncludePath)</IncludePath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <LibraryPath>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x64;$(LibraryPath)</LibraryPath>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+      <StructMemberAlignment>16Bytes</StructMemberAlignment>
+      <AdditionalOptions>/Zm110 %(AdditionalOptions)</AdditionalOptions>
+      <DisableLanguageExtensions>false</DisableLanguageExtensions>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+    <Manifest>
+      <AdditionalManifestFiles>DeclareDPIAware.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
+    </Manifest>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>false</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClInclude Include="application.h" />
+    <ClInclude Include="audio_base.h" />
+    <ClInclude Include="base_window.h" />
+    <ClInclude Include="code_converter.h" />
+    <ClInclude Include="dout.h" />
+    <ClInclude Include="dpi.h" />
+    <ClInclude Include="exception.h" />
+    <ClInclude Include="icon.h" />
+    <ClInclude Include="jumplist.h" />
+    <ClInclude Include="logger.h" />
+    <ClInclude Include="message_loop.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="taskbar.h" />
+    <ClInclude Include="timer.h" />
+    <ClInclude Include="toplevel_window.h" />
+    <ClInclude Include="wasapi.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="application.cpp" />
+    <ClCompile Include="audio_base.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="jumplist.cpp" />
+    <ClCompile Include="logger.cpp" />
+    <ClCompile Include="sf_windows.cpp" />
+    <ClCompile Include="stdafx.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="taskbar.cpp" />
+    <ClCompile Include="timer.cpp" />
+    <ClCompile Include="toplevel_window.cpp" />
+    <ClCompile Include="wasapi.cpp" />
+    <ClCompile Include="winmain.cpp" />
+  </ItemGroup>
+  <ItemGroup>
+    <ResourceCompile Include="minitimer.rc" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="icon1.ico" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file
diff --git a/dxgi_test/dxgi_test.vcxproj.filters b/dxgi_test/dxgi_test.vcxproj.filters
new file mode 100644 (file)
index 0000000..b75e9c7
--- /dev/null
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <ClInclude Include="code_converter.h" />
+    <ClInclude Include="exception.h" />
+    <ClInclude Include="logger.h" />
+    <ClInclude Include="singleton.h" />
+    <ClInclude Include="toplevel_window.h" />
+    <ClInclude Include="taskbar.h" />
+    <ClInclude Include="base_window.h" />
+    <ClInclude Include="sf_com.h">
+      <Filter>windows</Filter>
+    </ClInclude>
+    <ClInclude Include="sf_memory.h">
+      <Filter>windows</Filter>
+    </ClInclude>
+    <ClInclude Include="sf_windows.h">
+      <Filter>windows</Filter>
+    </ClInclude>
+    <ClInclude Include="dout.h">
+      <Filter>windows</Filter>
+    </ClInclude>
+    <ClInclude Include="stdafx.h">
+      <Filter>windows</Filter>
+    </ClInclude>
+    <ClInclude Include="message_loop.h">
+      <Filter>windows</Filter>
+    </ClInclude>
+    <ClInclude Include="application.h" />
+    <ClInclude Include="jumplist.h" />
+    <ClInclude Include="icon.h" />
+    <ClInclude Include="timer.h" />
+    <ClInclude Include="resource.h" />
+    <ClInclude Include="dpi.h" />
+    <ClInclude Include="audio_base.h" />
+    <ClInclude Include="wasapi.h">
+      <Filter>windows</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="code_converter.cpp" />
+    <ClCompile Include="base_window.cpp" />
+    <ClCompile Include="sf_windows.cpp">
+      <Filter>windows</Filter>
+    </ClCompile>
+    <ClCompile Include="toplevel_window.cpp">
+      <Filter>windows</Filter>
+    </ClCompile>
+    <ClCompile Include="winmain.cpp">
+      <Filter>windows</Filter>
+    </ClCompile>
+    <ClCompile Include="logger.cpp">
+      <Filter>windows</Filter>
+    </ClCompile>
+    <ClCompile Include="exception.cpp">
+      <Filter>windows</Filter>
+    </ClCompile>
+    <ClCompile Include="stdafx.cpp">
+      <Filter>windows</Filter>
+    </ClCompile>
+    <ClCompile Include="taskbar.cpp">
+      <Filter>windows</Filter>
+    </ClCompile>
+    <ClCompile Include="application.cpp" />
+    <ClCompile Include="jumplist.cpp" />
+    <ClCompile Include="icon.cpp" />
+    <ClCompile Include="timer.cpp" />
+    <ClCompile Include="dpi.cpp" />
+    <ClCompile Include="audio_base.cpp" />
+    <ClCompile Include="wasapi.cpp">
+      <Filter>windows</Filter>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <Filter Include="windows">
+      <UniqueIdentifier>{ac651b31-e7cb-4909-a4cd-059605cc42dd}</UniqueIdentifier>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ResourceCompile Include="minitimer.rc" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="icon1.ico">
+      <Filter>windows</Filter>
+    </None>
+  </ItemGroup>
+</Project>
\ No newline at end of file
diff --git a/dxgi_test/dxgi_test.vcxproj.user b/dxgi_test/dxgi_test.vcxproj.user
new file mode 100644 (file)
index 0000000..ace9a86
--- /dev/null
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+</Project>
\ No newline at end of file
diff --git a/dxgi_test/exception.cpp b/dxgi_test/exception.cpp
new file mode 100644 (file)
index 0000000..3030979
--- /dev/null
@@ -0,0 +1,95 @@
+#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_BUFFER_SIZE_ERROR,L"AUDCLNT_E_BUFFER_SIZE_ERROR")
+       (AUDCLNT_S_BUFFER_EMPTY,L"AUDCLNT_S_BUFFER_EMPTY")
+       (AUDCLNT_S_THREAD_ALREADY_REGISTERED,L"AUDCLNT_S_THREAD_ALREADY_REGISTERED");
+       
+
+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();
+               }
+
+       }
+};
+
+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();
+       //Logger::outputDebugPrintf(L"Win32 Error %x %s",hresult_,mem.Get() );
+};
+
+}
\ No newline at end of file
diff --git a/dxgi_test/exception.h b/dxgi_test/exception.h
new file mode 100644 (file)
index 0000000..b8cb9d8
--- /dev/null
@@ -0,0 +1,39 @@
+#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_;}
+       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();}}
+  };
+
+}
\ No newline at end of file
diff --git a/dxgi_test/icon.cpp b/dxgi_test/icon.cpp
new file mode 100644 (file)
index 0000000..b03c446
--- /dev/null
@@ -0,0 +1,264 @@
+/*
+  ==============================================================================
+
+   This file is part of the mini timer
+   Copyright 2005-11 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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 "icon.h"
+#include "application.h"
+
+namespace sf {
+  bitmap_holder icon::default_mono_bitmap(CreateBitmap(32,32,1,1,NULL));
+
+  icon::icon(uint32_t id) 
+    : icon_((HICON)::LoadImageW(application::instance()->instance_handle(),MAKEINTRESOURCE(id),IMAGE_ICON,0,0,LR_DEFAULTCOLOR))
+  {
+
+  };
+
+  icon::icon(icon_holder& ic)
+  {
+    icon_.reset(::CopyIcon(ic.get()));
+    analyze();
+  }
+
+  icon::icon(icon_holder&& ic)
+  {
+    std::swap(ic,icon_);
+    analyze();
+  }
+
+  icon::icon(bitmap_holder& bmp_color,int width,int height) 
+    : width_(width),height_(height)
+  {
+    BITMAP bmp;
+    ICONINFO ii;
+    ::GetObjectW(bmp_color.get(),sizeof(BITMAP),&bmp);
+    bits_per_pixel_ = bmp.bmBitsPixel;
+
+    ii.fIcon = TRUE;
+    ii.xHotspot = 0;
+    ii.yHotspot = 0;
+    ii.hbmColor = bmp_color.get();
+
+    if(width == 32 && height == 32){
+      ii.hbmMask = default_mono_bitmap.get();
+      icon_.reset(::CreateIconIndirect(&ii));
+    } else {
+      bitmap_holder hmb(::CreateBitmap(width,height,1,1,NULL));
+      ii.hbmMask = hmb.get();
+      icon_.reset(::CreateIconIndirect(&ii));
+    }
+
+  }
+
+  icon::icon(ID2D1BitmapPtr& ptr)
+  {
+    ID2D1FactoryPtr factory;
+    ptr->GetFactory(&factory);
+
+    D2D1_SIZE_U size(ptr->GetPixelSize());
+    // ビットマップヘッダのセットアップ
+    BITMAPV5HEADER bi = {0};
+    bi.bV5Size           = sizeof(BITMAPV5HEADER);
+    bi.bV5Width           = size.width;
+    bi.bV5Height          = size.height;
+    bi.bV5Planes = 1;
+    bi.bV5BitCount = 32;
+    bi.bV5Compression = BI_BITFIELDS;
+    bi.bV5RedMask   =  0x00FF0000;
+    bi.bV5GreenMask =  0x0000FF00;
+    bi.bV5BlueMask  =  0x000000FF;
+    bi.bV5AlphaMask =  0xFF000000; 
+
+    // デスクトップHDCの取得
+    get_dc dc(NULL);
+    
+    // DIBセクションの作成
+    void *bits;// 得られるビットマップ
+    bitmap_holder bmp(
+      ::CreateDIBSection(
+        dc.get(),reinterpret_cast<BITMAPINFO *>(&bi),DIB_RGB_COLORS,&bits,NULL,0));
+    { 
+      // 互換DCの作成
+      compatible_dc cdc(dc.get());
+      {
+        // 描画先への切り替え
+        select_object s(cdc.get(),bmp.get());
+
+        // DC互換レンダーターゲットのセットアップ
+        D2D1_RENDER_TARGET_PROPERTIES 
+          props = D2D1::RenderTargetProperties(
+          D2D1_RENDER_TARGET_TYPE_DEFAULT,
+          D2D1::PixelFormat(
+              DXGI_FORMAT_B8G8R8A8_UNORM,
+              D2D1_ALPHA_MODE_PREMULTIPLIED),
+          0,
+          0,
+          D2D1_RENDER_TARGET_USAGE_NONE,
+          D2D1_FEATURE_LEVEL_DEFAULT
+        );
+
+        ID2D1DCRenderTargetPtr dcr;
+        throw_if_err<>()(factory->CreateDCRenderTarget(&props,&dcr));
+        RECT rect = {0,0,size.width,size.height};
+        // 互換DCへのバインド
+        throw_if_err<>()(dcr->BindDC(cdc.get(),&rect));
+        dcr->DrawBitmap(ptr);
+      }
+    }
+    icon(bmp,size.width,size.height);
+  };
+
+
+  icon::icon(boost::filesystem3::wpath& path)
+  {
+    icon_.reset(
+      reinterpret_cast<HICON>(
+        LoadImageW(NULL,path.native().c_str(),IMAGE_ICON,0,0,LR_DEFAULTSIZE | LR_LOADFROMFILE)));
+  }
+
+  icon::~icon()
+  {
+
+  }
+
+  void icon::analyze()
+  {
+    ::ICONINFOEXW info;
+    ::GetIconInfoExW(icon_.get(),&info);
+    BITMAP bmp;
+    ::GetObjectW(info.hbmColor,sizeof(BITMAP),&bmp);
+    width_ = bmp.bmWidth;
+    height_ = bmp.bmHeight;
+    bits_per_pixel_ = bmp.bmBitsPixel;
+  }
+
+  icon& icon::operator= (icon& i)
+  {
+    BOOST_ASSERT(icon_ != i.icon_);
+    if(icon_ == i.icon_) return *this;
+    icon_.reset(::CopyIcon(i.icon_.get()));
+    width_ = i.width_;
+    height_ = i.height_;
+    bits_per_pixel_ = i.bits_per_pixel_;
+    return *this;
+  }
+
+  //icon_ptr icon::create_icon()
+  //{
+  //  // ビットマップヘッダのセットアップ
+  //  BITMAPV5HEADER bi = {0};
+  //  bi.bV5Size           = sizeof(BITMAPV5HEADER);
+  //  bi.bV5Width           = width_;
+  //  bi.bV5Height          = height_;
+  //  bi.bV5Planes = 1;
+  //  bi.bV5BitCount = 32;
+  //  bi.bV5Compression = BI_BITFIELDS;
+  //  bi.bV5RedMask   =  0x00FF0000;
+  //  bi.bV5GreenMask =  0x0000FF00;
+  //  bi.bV5BlueMask  =  0x000000FF;
+  //  bi.bV5AlphaMask =  0xFF000000; 
+
+  //  // デスクトップHDCの取得
+  //  get_dc dc(NULL);
+
+  //  // DIBセクションの作成
+  //  void *bits;// 得られるビットマップ
+  //  gdi_object<HBITMAP> bmp(
+  //    ::CreateDIBSection(
+  //      dc.get(),reinterpret_cast<BITMAPINFO *>(&bi),DIB_RGB_COLORS,&bits,NULL,0));
+  //  { 
+  //    // 互換DCの作成
+  //    compatible_dc cdc(dc.get());
+  //    {
+  //      // 描画先への切り替え
+  //      select_object s(cdc.get(),bmp);
+
+  //      // DC互換レンダーターゲットのセットアップ
+  //      D2D1_RENDER_TARGET_PROPERTIES 
+  //        props = D2D1::RenderTargetProperties(
+  //        D2D1_RENDER_TARGET_TYPE_DEFAULT,
+  //        D2D1::PixelFormat(
+  //            DXGI_FORMAT_B8G8R8A8_UNORM,
+  //            D2D1_ALPHA_MODE_PREMULTIPLIED),
+  //        0,
+  //        0,
+  //        D2D1_RENDER_TARGET_USAGE_NONE,
+  //        D2D1_FEATURE_LEVEL_DEFAULT
+  //      );
+
+  //      ID2D1DCRenderTargetPtr dcr;
+  //      throw_if_err<>()(factory_->CreateDCRenderTarget(&props,&dcr));
+  //      RECT rect = {0,0,w,h};
+  //      // 互換DCへのバインド
+  //      throw_if_err<>()(dcr->BindDC(cdc.get(),&rect));
+
+  //      // ブラシのセットアップ(背景の赤丸)
+  //      ID2D1SolidColorBrushPtr brush_e;
+  //      throw_if_err<>()(
+  //        dcr->CreateSolidColorBrush(
+  //          D2D1::ColorF(D2D1::ColorF::Red,0.8f), &brush_e));
+
+  //      // アイコンに描画する文字の生成
+  //      std::wstring t(L"S.F.\nTimer");
+  //      D2D1_RECT_F l = D2D1::RectF(0.0f,0.0f,width_,height_);
+  //      // Text Formatの作成
+  //      IDWriteTextFormatPtr f;
+  //      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,
+  //      10.0f,
+  //      L"ja-jp",
+  //      &f
+  //      );
+  //      f->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
+  //      f->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
+
+  //      // 文字描画用ブラシのセットアップ
+  //      ID2D1SolidColorBrushPtr brush;
+  //      dcr->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &brush);
+  //      // 描画開始
+  //      dcr->BeginDraw();
+  //      // ビットマップクリア
+  //      dcr->Clear(D2D1::ColorF(D2D1::ColorF::Black,0.0f));
+  //      // 赤丸を描く
+  //      dcr->FillEllipse(D2D1::Ellipse(D2D1::Point2F(16.0f,16.0f),14,14),brush_e);
+  //      // テキストを表示する
+  //      dcr->DrawTextW(t.c_str(),t.size(),f,&l,brush);
+  //      // 描画終了
+  //      dcr->EndDraw();
+  //    }
+  //  }
+  //}
+}
diff --git a/dxgi_test/icon.h b/dxgi_test/icon.h
new file mode 100644 (file)
index 0000000..35a77e5
--- /dev/null
@@ -0,0 +1,99 @@
+#pragma once
+/*
+  ==============================================================================
+
+   This file is part of the mini timer
+   Copyright 2005-11 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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 icon_deleter {
+  typedef HICON pointer;
+  void operator ()(HICON handle) {
+      if (handle) {
+          ::DestroyIcon(handle);
+      }
+  }
+};
+
+typedef std::unique_ptr<HICON,icon_deleter> icon_holder;
+
+/** 
+
+*/
+struct icon
+{
+public:
+  icon(){};
+  explicit icon(uint32_t id);
+  explicit icon(icon_holder& ic);
+  explicit icon(icon_holder&& ic);
+  icon(bitmap_holder& bmp_color,int width = ::GetSystemMetrics(SM_CXICON),int height = ::GetSystemMetrics(SM_CYICON));
+  icon(ID2D1BitmapPtr& ptr);
+  icon(boost::filesystem3::wpath& path);
+  
+  virtual ~icon();
+
+  HICON get() const {return icon_.get();};
+
+  icon(icon& i) : width_(i.width_),height_(i.height_),bits_per_pixel_(i.bits_per_pixel_)
+  {
+    icon_.reset(::CopyIcon(i.icon_.get()));
+  }
+
+  icon(icon&& i) : width_(i.width_),height_(i.height_),bits_per_pixel_(i.bits_per_pixel_)
+  {
+    std::swap(icon_,i.icon_);
+  }
+
+  icon& operator= (icon&& i) 
+  {
+    BOOST_ASSERT(icon_ != i.icon_);
+    if(icon_ == i.icon_) return *this;
+    std::swap(icon_,i.icon_);
+    width_ = i.width_;
+    height_ = i.height_;
+    bits_per_pixel_ = i.bits_per_pixel_;
+    return *this;
+  }
+
+  icon& operator= (icon& i);
+
+  void swap(icon& i)
+  {
+    std::swap(icon_,i.icon_);
+    std::swap(width_,i.width_);
+    std::swap(height_,i.height_);
+    std::swap(bits_per_pixel_,i.bits_per_pixel_);
+  }
+
+private:
+
+  void analyze();
+  //ID2D1DCRenderTargetPtr dcr_;
+  //ID2D1BitmapPtr bitmap_;
+  int width_;
+  int height_;
+  int bits_per_pixel_;
+  icon_holder icon_;
+  static bitmap_holder default_mono_bitmap; 
+ };
+}
+
diff --git a/dxgi_test/icon.svg b/dxgi_test/icon.svg
new file mode 100644 (file)
index 0000000..040123e
--- /dev/null
@@ -0,0 +1,151 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:xlink="http://www.w3.org/1999/xlink"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="16px"
+   height="16px"
+   id="svg10"
+   version="1.1"
+   inkscape:version="0.48+devel r10194"
+   inkscape:export-filename="H:\satoshi_documents\documents\Visual Studio 2010\Projects\wintimer\wintimer\icon_32.png"
+   inkscape:export-xdpi="180"
+   inkscape:export-ydpi="180"
+   sodipodi:docname="icon.svg">
+  <defs
+     id="defs12">
+    <linearGradient
+       inkscape:collect="always"
+       id="linearGradient939">
+      <stop
+         style="stop-color:#000000;stop-opacity:1;"
+         offset="0"
+         id="stop941" />
+      <stop
+         style="stop-color:#000000;stop-opacity:0;"
+         offset="1"
+         id="stop943" />
+    </linearGradient>
+    <linearGradient
+       inkscape:collect="always"
+       id="linearGradient788">
+      <stop
+         style="stop-color:#000000;stop-opacity:1;"
+         offset="0"
+         id="stop790" />
+      <stop
+         style="stop-color:#000000;stop-opacity:0;"
+         offset="1"
+         id="stop792" />
+    </linearGradient>
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient788"
+       id="linearGradient794"
+       x1="8.2440586"
+       y1="10.188615"
+       x2="14.41584"
+       y2="5.0529704"
+       gradientUnits="userSpaceOnUse" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient820-2"
+       id="linearGradient830-5"
+       x1="6.3519807"
+       y1="1.2034652"
+       x2="10.541584"
+       y2="1.2034652"
+       gradientUnits="userSpaceOnUse" />
+    <linearGradient
+       inkscape:collect="always"
+       id="linearGradient820-2">
+      <stop
+         style="stop-color:#000000;stop-opacity:1;"
+         offset="0"
+         id="stop822-3" />
+      <stop
+         style="stop-color:#000000;stop-opacity:0;"
+         offset="1"
+         id="stop824-1" />
+    </linearGradient>
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient939"
+       id="linearGradient945"
+       x1="-3.1339901"
+       y1="4.5123761"
+       x2="10.43201"
+       y2="4.5123761"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="translate(5.0905941,3.6490099)" />
+  </defs>
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="22.197802"
+     inkscape:cx="11.542017"
+     inkscape:cy="8"
+     inkscape:current-layer="layer1"
+     showgrid="true"
+     inkscape:grid-bbox="true"
+     inkscape:document-units="px"
+     inkscape:window-width="789"
+     inkscape:window-height="621"
+     inkscape:window-x="21"
+     inkscape:window-y="29"
+     inkscape:window-maximized="0" />
+  <metadata
+     id="metadata15">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title />
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     id="layer1"
+     inkscape:label="Layer 1"
+     inkscape:groupmode="layer">
+    <path
+       style="fill:#fb9d1d;stroke:#000000;stroke-width:0.94099999999999995;stroke-opacity:1;fill-opacity:1;opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
+       d="M 6.34375 0.625 L 6.34375 1.78125 L 7.40625 1.78125 L 7.40625 2.75 L 9.21875 2.75 L 9.21875 1.78125 L 10.53125 1.78125 L 10.53125 0.625 L 6.34375 0.625 z M 8.21875 2.875 C 4.7315827 2.875 1.90625 5.7003327 1.90625 9.1875 C 1.90625 12.674667 4.7315827 15.5 8.21875 15.5 C 11.705917 15.5 14.53125 12.674667 14.53125 9.1875 C 14.53125 5.7003327 11.705917 2.875 8.21875 2.875 z "
+       id="path798" />
+    <path
+       sodipodi:type="arc"
+       style="fill:#fb1d2a;fill-opacity:1;stroke:none"
+       id="path871"
+       sodipodi:cx="11.352475"
+       sodipodi:cy="11.945544"
+       sodipodi:rx="3.1534653"
+       sodipodi:ry="3.1084158"
+       d="m 11.322958,8.8372646 a 3.1534653,3.1084158 0 0 1 1.274049,5.9643834 l -1.244532,-2.856104 z"
+       transform="matrix(1.8916043,0,0,1.9007513,-13.296607,-13.487748)"
+       sodipodi:start="4.7030286"
+       sodipodi:end="7.4482889" />
+    <path
+       sodipodi:type="arc"
+       style="fill:#fb9d1d;stroke:#000000;stroke-opacity:1;fill-opacity:1"
+       id="path869"
+       sodipodi:cx="8.5368814"
+       sodipodi:cy="8.8821783"
+       sodipodi:rx="0.87846535"
+       sodipodi:ry="0.90099013"
+       d="m 9.4153468,8.8821783 a 0.87846535,0.90099013 0 1 1 -1.7569307,0 0.87846535,0.90099013 0 1 1 1.7569307,0 z"
+       transform="translate(-0.27029703,0.09009902)" />
+  </g>
+</svg>
diff --git a/dxgi_test/icon1.ico b/dxgi_test/icon1.ico
new file mode 100644 (file)
index 0000000..ec79951
Binary files /dev/null and b/dxgi_test/icon1.ico differ
diff --git a/dxgi_test/icon1_1.ico b/dxgi_test/icon1_1.ico
new file mode 100644 (file)
index 0000000..6a1cbf9
Binary files /dev/null and b/dxgi_test/icon1_1.ico differ
diff --git a/dxgi_test/icon2.ico b/dxgi_test/icon2.ico
new file mode 100644 (file)
index 0000000..787726f
Binary files /dev/null and b/dxgi_test/icon2.ico differ
diff --git a/dxgi_test/icon_16.png b/dxgi_test/icon_16.png
new file mode 100644 (file)
index 0000000..a996b7d
Binary files /dev/null and b/dxgi_test/icon_16.png differ
diff --git a/dxgi_test/icon_256.png b/dxgi_test/icon_256.png
new file mode 100644 (file)
index 0000000..f4cf5a7
Binary files /dev/null and b/dxgi_test/icon_256.png differ
diff --git a/dxgi_test/icon_32.png b/dxgi_test/icon_32.png
new file mode 100644 (file)
index 0000000..9dd2bde
Binary files /dev/null and b/dxgi_test/icon_32.png differ
diff --git a/dxgi_test/icon_48.png b/dxgi_test/icon_48.png
new file mode 100644 (file)
index 0000000..ff691c2
Binary files /dev/null and b/dxgi_test/icon_48.png differ
diff --git a/dxgi_test/jumplist.cpp b/dxgi_test/jumplist.cpp
new file mode 100644 (file)
index 0000000..5bab20e
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+  ==============================================================================
+
+   This file is part of the mini timer
+   Copyright 2005-10 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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/dxgi_test/jumplist.h b/dxgi_test/jumplist.h
new file mode 100644 (file)
index 0000000..8c8f61b
--- /dev/null
@@ -0,0 +1,32 @@
+#pragma once
+/*
+  ==============================================================================
+
+   This file is part of the mini timer
+   Copyright 2005-10 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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/dxgi_test/logger.cpp b/dxgi_test/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/dxgi_test/logger.h b/dxgi_test/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/dxgi_test/message_loop.h b/dxgi_test/message_loop.h
new file mode 100644 (file)
index 0000000..28c5e56
--- /dev/null
@@ -0,0 +1,70 @@
+#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_;
+       };
+}
diff --git a/dxgi_test/minitimer.rc b/dxgi_test/minitimer.rc
new file mode 100644 (file)
index 0000000..622e768
Binary files /dev/null and b/dxgi_test/minitimer.rc differ
diff --git a/dxgi_test/resource.h b/dxgi_test/resource.h
new file mode 100644 (file)
index 0000000..cab18d3
--- /dev/null
@@ -0,0 +1,4 @@
+
+#define IDI_ICON1                               100
+#define THUMB_START 101
+#define THUMB_STOP 102
diff --git a/dxgi_test/sf_com.h b/dxgi_test/sf_com.h
new file mode 100644 (file)
index 0000000..8aab1f1
--- /dev/null
@@ -0,0 +1,100 @@
+#pragma once
+/*
+  ==============================================================================
+
+   This file is part of the Shooting3
+   Copyright 2005-11 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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 
+{
+    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 = NULL,unsigned int init = 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/dxgi_test/sf_memory.h b/dxgi_test/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/dxgi_test/sf_windows.cpp b/dxgi_test/sf_windows.cpp
new file mode 100644 (file)
index 0000000..3d74e70
--- /dev/null
@@ -0,0 +1,187 @@
+#include "stdafx.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 "exception.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 
+{
+  LRESULT base_win32_window::window_proc(HWND hwnd,uint32_t message, WPARAM wParam, LPARAM lParam)
+  {
+
+    LRESULT 結果 = 0;
+    switch (message)
+    {
+    case WM_CREATE:
+      {
+        // TODO:
+        //create_device();
+        break;
+      }
+    case WM_SIZE:
+      {
+        //if (render_target_)
+        //{
+        //     D2D1_SIZE_U size;
+        //     size.width = lParam & 0xFFFF;
+        //     size.height = (lParam >> 16) & 0xFFFF; ;
+
+        //     // Note: This method can fail, but it's okay to ignore the
+        //     // error here -- it will be repeated on the next call to
+        //     // EndDraw.
+        //     //render_target_->Resize(size);
+        //}
+      }
+    case WM_PAINT:
+      {
+        //create_device();
+
+        paint_struct begin_paint(hwnd);
+
+        //if (!(render_target_->CheckWindowState() & D2D1_WINDOW_STATE_OCCLUDED))
+        //{
+        //     // Retrieve the size of the render target.
+        //     D2D1_SIZE_F renderTargetSize = render_target_->GetSize();
+        //     try {
+        //             //render_target_->BeginDraw();
+        //             base_->on_render();
+        //             //THROW_IFERR(render_target_->EndDraw());
+        //     } catch (sf::win32_error_exception& e )
+        //     {
+        //             if(e.hresult() == D2DERR_RECREATE_TARGET)
+        //             {
+        //                     discard_device();
+        //             } else {
+        //                     throw;
+        //             }
+        //     }
+        //}
+        return FALSE;
+      }
+    case WM_DISPLAYCHANGE:
+      {
+        ::InvalidateRect(hwnd, NULL, FALSE);
+      }
+    case WM_ERASEBKGND:
+      {
+        return FALSE;
+      }
+    case WM_MOUSEMOVE:
+      {
+        //                                     on_mouse_move(GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam),wParam); 
+      }
+    case WM_LBUTTONDOWN:
+      {
+      }
+    }
+    return ::DefWindowProcW(hwnd,message,wParam,lParam);
+  };
+  
+  void base_win32_window::register_class (
+    const wchar_t * menu_name,
+    uint32_t        style ,
+    boost::int32_t     cbClsExtra,
+    HICON       hIcon ,
+    HCURSOR     hCursor,
+    HBRUSH      hbrBackground ,
+    HICON       hIconSm
+    )          
+  {
+    wnd_class_.reset(new sf::window_class_ex(menu_name,name_,HINST_THISCOMPONENT,thunk_proc_,style,cbClsExtra,hIcon,hCursor,hbrBackground,hIconSm));
+  }
+
+  /** デフォルト設定 */
+  void base_win32_window::register_class()
+  {
+    wnd_class_.reset(new sf::window_class_ex(0,name_,HINST_THISCOMPONENT,thunk_proc_));
+  }
+
+  void base_win32_window::create_window()
+  {
+    // Create the application window.
+    //
+    // Because the CreateWindow function takes its size in pixels, we
+    // obtain the system DPI and use it to scale the window size.
+    //FLOAT dpiX, dpiY;
+    //factory_->GetDesktopDpi(&dpiX, &dpiY);
+
+
+    // Windowを作成する
+    CreateWindow(
+      name_.c_str(),
+      title_.c_str(),
+      WS_OVERLAPPEDWINDOW,
+      CW_USEDEFAULT,
+      CW_USEDEFAULT,
+      static_cast<uint32_t>(dpi_.scale_x(width_)),
+      static_cast<uint32_t>(dpi_.scale_y(height_)),
+      NULL,
+      NULL,
+      HINST_THISCOMPONENT,
+      this
+      );
+    ::GetWindowPlacement(hwnd_,&wp_);
+  }
+
+  //void base_win32_window::show() 
+  //{
+  //  //HRESULT hr = S_OK;
+  //  //BOOL enable;
+  //  //DwmIsCompositionEnabled (&enable);
+  //  //if(enable){
+  //  //   //Create and populate the BlurBehind structre
+  //  //   DWM_BLURBEHIND bb = {0};
+  //  //   //Enable Blur Behind and Blur Region;
+  //  //   bb.dwFlags = DWM_BB_ENABLE;
+  //  //   bb.fEnable = true;
+  //  //   bb.hRgnBlur = NULL;
+
+  //  //   //Enable Blur Behind
+  //  //   hr = DwmEnableBlurBehindWindow(hwnd_, &bb);
+  //  //}
+  //  ::ShowWindow(hwnd_,SW_SHOW);
+  //  ::GetWindowPlacement(&wp_);
+  //}
+
+
+  void base_win32_window::update() {::UpdateWindow(hwnd_);}
+
+  base_win32_window::~base_win32_window()
+  {
+
+  }
+
+  base_win32_window::base_win32_window(const std::wstring& title,const std::wstring& name,bool fit_to_display,float width,float height)
+    : title_(title),name_(name),fit_to_display_(fit_to_display),width_(width),height_(height),thunk_(this,base_win32_window::WndProc),hwnd_(0)
+  {
+    memset(&wp_,0,sizeof(wp_));
+    wp_.length = sizeof(WINDOWPLACEMENT);
+    thunk_proc_ = (WNDPROC)thunk_.getCode();
+    //create_device_independent_resources();
+  }
+
+  //ID2D1FactoryPtr base_win32_window::factory() { return impl_->factory();};
+  //ID2D1HwndRenderTargetPtr base_win32_window::render_target() { return impl_->render_target();};
+  //IDWriteFactoryPtr base_win32_window::write_factory() {return impl_->write_factory();};
+}
+
diff --git a/dxgi_test/sf_windows.h b/dxgi_test/sf_windows.h
new file mode 100644 (file)
index 0000000..276d966
--- /dev/null
@@ -0,0 +1,459 @@
+#pragma once
+/*
+*/
+// Windows Header Files:
+#include "exception.h"
+#include "base_window.h"
+#include "dpi.h"
+#define XBYAK64
+#include "xbyak.h"
+// DLLのリンク
+#pragma comment(lib,"d2d1.lib")
+#pragma comment(lib,"winmm.lib")
+#pragma comment(lib,"dwrite.lib")
+#pragma comment(lib,"dwmapi.lib")
+
+//#include "input.h"
+
+// Direct Write
+
+_COM_SMARTPTR_TYPEDEF(IDWriteFactory , __uuidof(IDWriteFactory));
+_COM_SMARTPTR_TYPEDEF(IDWriteGdiInterop , __uuidof(IDWriteGdiInterop));
+_COM_SMARTPTR_TYPEDEF(IDWriteFontFace , __uuidof(IDWriteFontFace));
+_COM_SMARTPTR_TYPEDEF(IDWriteFont , __uuidof(IDWriteFont));
+_COM_SMARTPTR_TYPEDEF(IDWriteFontFamily , __uuidof(IDWriteFontFamily));
+_COM_SMARTPTR_TYPEDEF(IDWriteFontCollection , __uuidof(IDWriteFontCollection));
+_COM_SMARTPTR_TYPEDEF(IDWriteLocalizedStrings , __uuidof(IDWriteLocalizedStrings));
+_COM_SMARTPTR_TYPEDEF(IDWriteTextFormat, __uuidof(IDWriteTextFormat));
+_COM_SMARTPTR_TYPEDEF(IDWriteTextLayout, __uuidof(IDWriteTextLayout));
+
+// Direct2D
+
+_COM_SMARTPTR_TYPEDEF(ID2D1Factory,__uuidof(ID2D1Factory));
+_COM_SMARTPTR_TYPEDEF(ID2D1HwndRenderTarget , __uuidof(ID2D1HwndRenderTarget));
+_COM_SMARTPTR_TYPEDEF(ID2D1BitmapRenderTarget , __uuidof(ID2D1BitmapRenderTarget));
+_COM_SMARTPTR_TYPEDEF(ID2D1GdiInteropRenderTarget , __uuidof(ID2D1GdiInteropRenderTarget));
+_COM_SMARTPTR_TYPEDEF(ID2D1DCRenderTarget , __uuidof(ID2D1DCRenderTarget));
+_COM_SMARTPTR_TYPEDEF(ID2D1PathGeometry , __uuidof(ID2D1PathGeometry));
+_COM_SMARTPTR_TYPEDEF(ID2D1LinearGradientBrush , __uuidof(ID2D1LinearGradientBrush));
+_COM_SMARTPTR_TYPEDEF(ID2D1GradientStopCollection , __uuidof(ID2D1GradientStopCollection));
+_COM_SMARTPTR_TYPEDEF(ID2D1SolidColorBrush , __uuidof(ID2D1SolidColorBrush));
+_COM_SMARTPTR_TYPEDEF(ID2D1BitmapBrush , __uuidof(ID2D1BitmapBrush));
+_COM_SMARTPTR_TYPEDEF(ID2D1Bitmap , __uuidof(ID2D1Bitmap));
+
+// WIC
+
+_COM_SMARTPTR_TYPEDEF(IWICImagingFactory, __uuidof(IWICImagingFactory));
+_COM_SMARTPTR_TYPEDEF(IWICBitmapDecoder,__uuidof(IWICBitmapDecoder));
+_COM_SMARTPTR_TYPEDEF(IWICBitmapFrameDecode,__uuidof(IWICBitmapFrameDecode));
+_COM_SMARTPTR_TYPEDEF(IWICStream,__uuidof(IWICStream));
+_COM_SMARTPTR_TYPEDEF(IWICFormatConverter,__uuidof(IWICFormatConverter));
+_COM_SMARTPTR_TYPEDEF(IWICBitmapScaler,__uuidof(IWICBitmapScaler));
+_COM_SMARTPTR_TYPEDEF(ITaskbarList3,__uuidof(ITaskbarList3));
+
+// DXGI 
+
+_COM_SMARTPTR_TYPEDEF(IDXGISwapChain,__uuidof(IDXGISwapChain));
+_COM_SMARTPTR_TYPEDEF(IDXGIFactory1,__uuidof(IDXGIFactory1));
+_COM_SMARTPTR_TYPEDEF(IDXGIAdapter1,__uuidof(IDXGIAdapter1));
+_COM_SMARTPTR_TYPEDEF(IDXGIDevice1,__uuidof(IDXGIDevice1));
+_COM_SMARTPTR_TYPEDEF(IDXGIKeyedMutex,__uuidof(IDXGIKeyedMutex));
+_COM_SMARTPTR_TYPEDEF(IDXGIObject,__uuidof(IDXGIObject));
+_COM_SMARTPTR_TYPEDEF(IDXGIDeviceSubObject,__uuidof(IDXGIDeviceSubObject));
+_COM_SMARTPTR_TYPEDEF(IDXGISurface1,__uuidof(IDXGISurface1));
+_COM_SMARTPTR_TYPEDEF(IDXGIOutput,__uuidof(IDXGIOutput));
+//_COM_SMARTPTR_TYPEDEF(IDXGI,__uuidof(IDXGI));
+//_COM_SMARTPTR_TYPEDEF(IDXGI,__uuidof(IDXGI));
+
+// Direct3D
+
+_COM_SMARTPTR_TYPEDEF(ID3D11Device,__uuidof(ID3D11Device));
+_COM_SMARTPTR_TYPEDEF(ID3D11DeviceContext,__uuidof(ID3D11DeviceContext));
+_COM_SMARTPTR_TYPEDEF(ID3D11RenderTargetView,__uuidof(ID3D11RenderTargetView));
+_COM_SMARTPTR_TYPEDEF(ID3D11VertexShader,__uuidof(ID3D11VertexShader));
+_COM_SMARTPTR_TYPEDEF(ID3D11PixelShader,__uuidof(ID3D11PixelShader));
+_COM_SMARTPTR_TYPEDEF(ID3D11InputLayout,__uuidof(ID3D11InputLayout));
+_COM_SMARTPTR_TYPEDEF(ID3D11Buffer,__uuidof(ID3D11Buffer));
+_COM_SMARTPTR_TYPEDEF(ID3D11Texture2D,__uuidof(ID3D11Texture2D));
+_COM_SMARTPTR_TYPEDEF(ID3DBlob,__uuidof(ID3DBlob));
+
+template <class COM_SMART_PTR > inline void safe_release(COM_SMART_PTR& ptr)
+{
+  if(ptr)
+  {
+    ptr.Release();
+  }
+};
+
+namespace sf{
+
+ /* inline template <class Exc = win32_error_exception> void throw_if_err<>()(HRESULT hr)
+  {
+    if(hr != S_OK){throw Exc(hr);}
+  };*/
+
+
+  ID2D1BitmapPtr load_bitmap_from_file(
+    ID2D1HwndRenderTargetPtr render_target,
+    IWICImagingFactoryPtr wic_factory,
+    std::wstring uri,
+    uint32_t destination_width = 0,
+    uint32_t destination_height = 0
+    );
+
+  /** WNDCLASSEXラッパクラス */
+  struct window_class_ex
+  {
+    window_class_ex(
+      const wchar_t*  menu_name ,
+      const std::wstring&  class_name ,
+      HINSTANCE   hInstance = NULL,
+      WNDPROC     lpfnWndProc = ::DefWindowProcW,
+      uint32_t        style = CS_HREDRAW | CS_VREDRAW,
+      boost::int32_t     cbClsExtra  = 0,
+      HICON       hIcon = ::LoadIcon(NULL,IDI_APPLICATION),
+      HCURSOR     hCursor = ::LoadCursor(NULL, IDC_ARROW),
+      HBRUSH      hbrBackground = ::CreateSolidBrush(0xff000000),
+      HICON       hIconSm = NULL
+      ) : is_register_(false)
+    {
+
+      if(::GetClassInfoExW(hInstance,class_name.c_str(),&wndclass_) == 0)
+      {
+        if(::GetLastError() == ERROR_CLASS_DOES_NOT_EXIST)
+        { 
+          ::ZeroMemory(&wndclass_,sizeof(wndclass_));
+          wndclass_.lpszMenuName = (LPCWSTR)menu_name;
+          wndclass_.lpszClassName = class_name.c_str();
+          wndclass_.cbSize = sizeof(::WNDCLASSEXW);
+          wndclass_.cbWndExtra = sizeof(LONG_PTR);
+          wndclass_.hInstance = hInstance;
+          wndclass_.lpfnWndProc = lpfnWndProc;
+          wndclass_.style = style;
+          wndclass_.cbClsExtra = cbClsExtra;
+          wndclass_.hIcon = hIcon;
+          wndclass_.hCursor = hCursor;
+          wndclass_.hbrBackground = hbrBackground;
+          wndclass_.hIconSm = hIconSm;
+          atom_ = ::RegisterClassExW(&wndclass_) ;
+          BOOST_ASSERT(atom_ != 0);
+          is_register_ = true;
+        } else {
+          throw win32_error_exception();
+        }
+      } else {
+        is_register_ = false;
+      }
+    };
+
+    ~window_class_ex()
+    {
+      if(is_register_){
+        ::UnregisterClassW(wndclass_.lpszClassName,wndclass_.hInstance);
+      }
+    }
+
+  private:
+    bool is_register_;
+    ATOM atom_;
+    ::WNDCLASSEXW wndclass_;
+  };
+
+  struct get_dc {
+    get_dc(HWND hwnd) : hwnd_(hwnd),hdc_(GetDC(hwnd)) {}
+    HDC get(){return hdc_;}
+    ~get_dc(){::ReleaseDC(hwnd_,hdc_);}
+  private:
+    HDC hdc_;
+    HWND hwnd_;
+  };
+
+  struct compatible_dc {
+    compatible_dc(HDC hdc) : hdc_(::CreateCompatibleDC(hdc)){}; 
+    ~compatible_dc(){::DeleteDC(hdc_);};
+    HDC get() { return hdc_;};
+  private:
+    HDC hdc_;
+  };
+
+  struct ref_dc {
+    ref_dc(HDC& hdc) : hdc_(hdc) {};
+    ~ref_dc(){};
+    HDC get() { return hdc_;};
+  private:
+    HDC& hdc_;
+  };
+
+  struct d2_dc {
+    d2_dc(ID2D1GdiInteropRenderTargetPtr& ptr,D2D1_DC_INITIALIZE_MODE mode) :hdc_(0),ptr_(ptr)
+    {
+      hr_ = ptr->GetDC(mode,&hdc_);
+    };
+    ~d2_dc(){ptr_->ReleaseDC(NULL);};
+    HDC get() { return hdc_;};
+  private:
+    HRESULT hr_;
+    HDC hdc_;
+    ID2D1GdiInteropRenderTargetPtr& ptr_;
+  };
+
+  template <typename Holder>
+  struct device_context
+  {
+    explicit device_context(Holder* holder) : holder_(holder){};
+    ~device_context() {}
+    operator HDC(){return holder_->get();}
+  private:
+    std::unique_ptr<Holder> holder_;
+  };
+
+  //struct handle_holder : boost::noncopyable
+  //{
+  //  explicit handle_holder(HANDLE handle) : handle_(handle) {};
+  //  ~handle_holder(){if(handle_) ::CloseHandle(handle_);}
+  //  operator HANDLE(){return handle_;}
+  //private:
+  //  HANDLE handle_;
+  //};
+
+
+  struct HBITMAP_deleter {
+    typedef HBITMAP pointer;
+    void operator ()(HBITMAP handle) {
+        if (handle) {
+           ::DeleteObject(handle);
+        }
+    }
+  };
+
+  //template <typename Handle,typename Handle_Deleter>
+  //struct handle_holder {
+  //  typedef boost::unique_ptr<Handle,Handle_Deleter> holder_type;
+  //  handle_holder(Handle handle) : holder_(handle) {}
+  //  operator Handle(){return holder_->get();}
+  //private:
+  //  holder_type holder_;
+  //};
+
+  typedef std::unique_ptr<HBITMAP,HBITMAP_deleter> bitmap_holder;
+
+  typedef device_context<d2_dc> d2_dc_type;
+
+  struct paint_struct 
+  {
+    paint_struct(HWND hwnd) : hwnd_(hwnd)
+    {
+      ::BeginPaint(hwnd,&paintstruct_);
+    }
+    ~paint_struct() {::EndPaint(hwnd_,&paintstruct_);}
+    PAINTSTRUCT* operator->(){return &paintstruct_;}
+  private:
+    HWND hwnd_;
+    PAINTSTRUCT paintstruct_;
+  };
+
+  // GDI オブジェクト管理テンプレート
+  template <class GdiObject> 
+    struct gdi_object: boost::noncopyable
+  {
+    explicit gdi_object(GdiObject obj) : gdiobj_(obj) {}
+    ~gdi_object(){::DeleteObject(gdiobj_);}
+    operator GdiObject(){return gdiobj_;}
+  private:
+    GdiObject gdiobj_;
+  };
+
+  //
+  struct select_object 
+  {
+    select_object(HDC dc,HGDIOBJ o) : dc_(dc),o_(::SelectObject(dc,o)) {}
+    ~select_object(){::SelectObject(dc_,o_);}
+  private:
+    HDC dc_;
+    HGDIOBJ o_;
+  };
+  
+  // Direct2D BeginDrawヘルパ関数
+  template <typename T >
+  struct begin_draw
+  {
+    typedef std::function<void(HRESULT hr)> err_handler_type;
+
+    begin_draw(T& render_target,err_handler_type& handler)
+      : render_target_(render_target) ,
+        is_end_(false),handler_(handler)
+    {render_target->BeginDraw();}
+
+    ~begin_draw(){ 
+      HRESULT hr = S_OK;
+      hr = render_target_->EndDraw();
+      if( hr != S_OK)
+      {
+        handler_(hr);
+      }
+    }
+  private:
+    T& render_target_;
+    err_handler_type handler_;
+  };
+
+  struct mouse
+  {
+    mouse() : x_(0.0f),y_(0.0f),left_button_(false),middle_button_(false),right_button_(false){}
+  private:
+    float x_,y_;
+    bool left_button_,middle_button_,right_button_;
+  };
+
+
+  /** window ベースクラス */
+  struct base_win32_window : public base_window 
+  {
+    typedef boost::signals2::signal<LRESULT (HWND,uint32_t,WPARAM, LPARAM) > on_message_type;
+    on_message_type on_message;
+    
+    operator HWND() const {return hwnd_;};
+    
+    virtual void * raw_handle() const {return hwnd_;};
+//    virtual void show(uint32_t show_flag);
+
+    virtual void show() {
+      ::ShowWindow(hwnd_,SW_SHOW);
+      ::GetWindowPlacement(hwnd_,&wp_);
+    }
+
+    // Window を画面から隠す
+    virtual bool is_show() {
+      return ( wp_.showCmd == SW_SHOWMAXIMIZED 
+        || wp_.showCmd == SW_SHOWMINIMIZED
+        || wp_.showCmd == SW_SHOWNORMAL );
+    };
+
+    //
+    virtual void hide()
+    {
+      ::ShowWindow(hwnd_,SW_HIDE);
+      ::GetWindowPlacement(hwnd_,&wp_);
+    };
+
+    virtual void text(std::wstring& text)
+    {
+      ::SetWindowTextW(*this,text.c_str());
+    };
+
+    virtual void update();
+
+  protected:
+    
+    base_win32_window(
+      const std::wstring& title,
+      const std::wstring& name,bool fit_to_display,
+      float width,float height);
+    
+    ~base_win32_window();
+
+    void register_class (
+      const wchar_t* menu_name,
+      uint32_t style, 
+      boost::int32_t     cbClsExtra  = 0,
+      HICON       hIcon = ::LoadIcon(NULL,IDI_APPLICATION),
+      HCURSOR     hCursor = ::LoadCursor(NULL, IDC_ARROW),
+      HBRUSH      hbrBackground = ::CreateSolidBrush(0xff000000),
+      HICON       hIconSm = NULL
+      );               
+
+    /** デフォルト設定 */
+    void register_class();
+    void create_window();
+
+    // SetWindowLong API
+    void set_long(int index,long data)
+    {
+      SetLastError(0);
+      if(::SetWindowLongW(hwnd_,index,data) == 0)
+      {
+        long err = 0;
+        if( (err = GetLastError()) != 0){
+          SetLastError(err);
+          throw sf::win32_error_exception();
+        }
+      };
+    }
+
+    bool invalidate_rect(bool erase = false,const RECT * rect_ptr = 0)
+    {
+      return ::InvalidateRect(*this,rect_ptr,erase) == TRUE;
+    }
+
+  public:
+    virtual LRESULT window_proc(HWND hwnd,uint32_t message, WPARAM wParam, LPARAM lParam);
+  protected:
+    static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+    {
+      base_win32_window* ptr = reinterpret_cast<base_win32_window*>(hwnd);
+      hwnd = ptr->hwnd_;
+      return ptr->window_proc(hwnd,message,wParam,lParam);
+    };
+
+    // thisとhwndをつなぐthunkクラス
+    struct hwnd_this_thunk : public Xbyak::CodeGenerator {
+      hwnd_this_thunk(base_win32_window* impl,WNDPROC proc)
+      {
+        // rcxにhwndが格納されているので、それをimpl->hwndに保存
+        mov(qword[&(impl->hwnd_)],rcx);
+        // 代わりにthisのアドレスをrcxに格納
+        mov(rcx,(LONG_PTR)impl);
+        // r10にproc(Window プロシージャ)へのアドレスを格納
+        mov(r10,(LONG_PTR)proc);
+        // Window プロシージャへへジャンプ
+        jmp(r10);
+      }
+    };
+
+    HWND hwnd_;
+    hwnd_this_thunk thunk_;
+    std::wstring title_;
+    std::wstring name_;
+    float width_,height_;
+    bool fit_to_display_;
+    std::shared_ptr<sf::window_class_ex> wnd_class_;
+    WNDPROC thunk_proc_;
+    dpi dpi_;
+    WINDOWPLACEMENT wp_;
+   };
+  
+  struct av_mm_thread_characteristics
+  {
+    av_mm_thread_characteristics(std::wstring& str) : task_name_(str)
+    {
+      handle_ = ::AvSetMmThreadCharacteristicsW(str.c_str(),(LPDWORD)&task_index_);
+    }
+
+    bool set_priority(AVRT_PRIORITY p){return (::AvSetMmThreadPriority(handle_,p) == TRUE);}
+
+    ~av_mm_thread_characteristics()
+    {
+      ::AvRevertMmThreadCharacteristics(handle_);
+    }
+
+  private:
+    std::wstring task_name_;
+    uint32_t task_index_;
+    HANDLE handle_;
+    std::wstring title_;
+    std::wstring name_;
+    float width_,height_;
+    bool fit_to_display_;
+    WINDOWPLACEMENT wp_;//
+  };
+
+  struct widget
+  {
+    void draw();
+    float x_,y_;
+  };
+
+  typedef sf::begin_draw<ID2D1BitmapRenderTargetPtr> begin_draw_bitmap;
+  typedef sf::begin_draw<ID2D1HwndRenderTargetPtr> begin_draw_hwnd;
+  
+}
\ No newline at end of file
diff --git a/dxgi_test/singleton.h b/dxgi_test/singleton.h
new file mode 100644 (file)
index 0000000..424df3f
--- /dev/null
@@ -0,0 +1,55 @@
+#pragma once
+/*
+  ==============================================================================
+
+   This file is part of the mini timer
+   Copyright 2005-7 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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/dxgi_test/start.ico b/dxgi_test/start.ico
new file mode 100644 (file)
index 0000000..92cf4ab
Binary files /dev/null and b/dxgi_test/start.ico differ
diff --git a/dxgi_test/stdafx.cpp b/dxgi_test/stdafx.cpp
new file mode 100644 (file)
index 0000000..afed109
--- /dev/null
@@ -0,0 +1,8 @@
+// stdafx.cpp : 標準インクルードのみを含むソース ファイルです。
+// STed2.pch は、プリコンパイル済みヘッダーになります。
+//  stdafx.obj にはプリコンパイル型情報が含まれます。
+
+#include "stdafx.h"
+
+// TODO: このファイルではなく、STDAFX.H で必要な
+// 追加ヘッダーを参照してください。
diff --git a/dxgi_test/stdafx.h b/dxgi_test/stdafx.h
new file mode 100644 (file)
index 0000000..e01b651
--- /dev/null
@@ -0,0 +1,149 @@
+// stdafx.h : 標準のシステム インクルード ファイルのインクルード ファイル、または
+// 参照回数が多く、かつあまり変更されない、プロジェクト専用のインクルード ファイル
+// を記述します。
+//
+
+
+#pragma once
+#include <SDKDDKVer.h>
+
+#ifndef UNICODE
+#define UNICODE
+#endif
+// STL
+#define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers
+//
+// Modify the following defines if you have to target a platform prior to the ones specified below.
+// Refer to MSDN for the latest info on corresponding values for different platforms.
+#ifndef WINVER              // Allow use of features specific to Windows 7 or later.
+#define WINVER 0x0700       // Change this to the appropriate value to target other versions of Windows.
+#endif
+
+#ifndef _WIN32_WINNT        // Allow use of features specific to Windows 7 or later.
+#define _WIN32_WINNT 0x0700 // Change this to the appropriate value to target other versions of Windows.
+#endif
+#define DIRECTINPUT_VERSION 0x0800
+#include <stdint.h>
+#include <tchar.h>
+#include <iostream>
+#include <fstream>
+#include <exception>
+#include <memory>
+#include <string>
+#include <map>
+#include <locale>
+#include <fstream>
+#include <algorithm>
+#include <functional>
+
+// Boost
+//#include <boost/archive/xml_woarchive.hpp>
+//#include <boost/archive/xml_wiarchive.hpp>
+//#include <boost/archive/text_woarchive.hpp>
+//#include <boost/archive/text_wiarchive.hpp>
+//#include <boost/archive/text_oarchive.hpp>
+//#include <boost/archive/text_iarchive.hpp>
+//#include <boost/archive/binary_woarchive.hpp>
+//#include <boost/archive/binary_wiarchive.hpp>
+//#include <boost/archive/binary_oarchive.hpp>
+//#include <boost/archive/binary_iarchive.hpp>
+
+//#include <boost/serialization/export.hpp>
+//#include <boost/serialization/is_abstract.hpp>
+//#include <boost/serialization/version.hpp>
+//#include <boost/serialization/serialization.hpp>
+//#include <boost/serialization/split_member.hpp>
+//#include <boost/serialization/string.hpp>
+//#include <boost/serialization/shared_ptr.hpp>
+//#include <boost/serialization/vector.hpp>
+//#include <boost/serialization/nvp.hpp>
+//#include <boost/serialization/void_cast.hpp>
+
+#include <boost/scoped_ptr.hpp> 
+#include <boost/scoped_array.hpp> 
+#include <boost/shared_ptr.hpp> 
+#include <boost/shared_array.hpp> 
+#include <boost/intrusive_ptr.hpp>
+#include <boost/format.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/array.hpp>
+#include <boost/thread.hpp>
+#include <boost/optional.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
+#include <boost/variant.hpp>
+#include <boost/any.hpp>
+#include <boost/signals2.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/ptr_container/ptr_container.hpp>
+#include <boost/thread/condition.hpp>
+//#include <boost/serialization/ptr_vector.hpp>
+#include <boost/ptr_container/ptr_array.hpp>
+#include <boost/ptr_container/serialize_ptr_container.hpp>
+//#include "serialization.h"
+#include <boost/filesystem/path.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/convenience.hpp>
+#include <boost/filesystem/fstream.hpp>
+#include "sf_com.h"
+//#include <d3d10_1.h>
+//#include <d3d10.h>
+//#include <d3d11.h>
+//#include <d3dx10.h>
+//#include <d3dx11.h>
+#include "dinput.h"
+#include <wincodec.h>
+#include <windows.h>
+#include <windowsx.h>
+#include <wincodec.h>
+#include <wincodecsdk.h>
+
+#include <comdef.h>
+#include "avrt.h"
+#include "mmsystem.h"
+
+// Direct Input
+
+#include "dinput.h"
+
+
+// DXGI
+
+#include "dxgi.h"
+
+// Direct3D
+
+#include "d3d11.h"
+#include "d3dx11.h"
+//#include <d3dx11effect.h>
+//#include <d3dxGlobal.h>
+#include <d3dcompiler.h>
+#include <xnamath.h>
+
+// Direct2D
+
+#include <d2d1.h>
+#include <d2d1helper.h>
+
+// Direct Write
+
+#include <dwrite.h>
+
+// DWM
+
+#include "dwmapi.h" 
+#include "Shobjidl.h"
+
+#include <wincodec.h>
+#include <wincodecsdk.h>
+
+//#include "exception.h"
+//#include "singleton.h"
+//#include "code_converter.h"
+//#include "logger.h"
+
+
+// TODO: プログラムに必要な追加ヘッダーをここで参照してください。
+#include "code_converter.h"
+#include "logger.h"
+#include "dout.h"
diff --git a/dxgi_test/stop.ico b/dxgi_test/stop.ico
new file mode 100644 (file)
index 0000000..e1cd8af
Binary files /dev/null and b/dxgi_test/stop.ico differ
diff --git a/dxgi_test/taskbar.cpp b/dxgi_test/taskbar.cpp
new file mode 100644 (file)
index 0000000..175e7c9
--- /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_()(taskbar_.CreateInstance(CLSID_TaskbarList));
+  }
+  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:
+  _COM_SMARTPTR_TYPEDEF(ITaskbarList4,__uuidof(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/dxgi_test/taskbar.h b/dxgi_test/taskbar.h
new file mode 100644 (file)
index 0000000..d1ae873
--- /dev/null
@@ -0,0 +1,161 @@
+#pragma once
+
+/*
+  ==============================================================================
+
+   This file is part of the mini timer
+   Copyright 2005-10 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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 "exception.h"
+#include "icon.h"
+
+namespace sf
+{
+  
+  ///** インターフェース */
+  //struct thumb_button : boost::noncopyable
+  //{
+  //  typedef std::shared_ptr<thumb_button> ptr;
+  //  static ptr create_thumb_button();
+  //  virtual void show()  = 0;
+  //  virtual void hide()  = 0;
+  //  virtual void enable() = 0;
+  //  virtual void disable() = 0;
+  //private:
+  //  thumb_button();
+  //};
+
+  struct taskbar;
+
+  /** サムネイルボタン管理 */
+  struct thumb_button_manager
+  {
+    friend struct taskbar;
+    // Thumb Buttonは最大7個まで
+    static const int THUMB_BUTTON_MAX = 7;
+
+    // THUMBBUTTON構造体操作クラス
+    struct thumb_button {
+
+      // コンストラクタ
+      thumb_button(uint32_t id ,const icon& i,const std::wstring& tool_tip,THUMBBUTTON& t) : thumb_(t)
+      {
+        BOOST_ASSERT(tool_tip.size() < 259);
+        memset(&thumb_,0,sizeof(THUMBBUTTON));
+        thumb_.dwMask = THB_ICON | THB_TOOLTIP | THB_FLAGS;
+        thumb_.hIcon = i.get();
+        thumb_.iId = id;
+        std::copy(tool_tip.begin(),tool_tip.end(),thumb_.szTip);
+        //thumb_.szTip = const_cast<wchar_t*>(tool_tip_.c_str());
+      }
+      
+      // 今回はプロパティ・チェイニングなアクセス方法にしてみた。
+      /** アイコン */
+      thumb_button& set_icon(icon& ic) {thumb_.hIcon = ic.get(); return *this;};
+      /** IDのセット */
+      thumb_button& id(uint32_t v) {thumb_.iId = v; return *this;}
+      /** ツールチップ */
+      thumb_button& tool_tip(const std::wstring& v) {
+        BOOST_ASSERT(v.size() < 259);
+        std::copy(v.begin(),v.end(),thumb_.szTip);
+        thumb_.szTip[v.size()] = L'\0';
+        return *this;
+      }
+      /** 有効化・無効化 */
+      thumb_button& enable(bool v){v?(thumb_.dwFlags &= ~THBF_ENABLED):(thumb_.dwFlags |= THBF_DISABLED); return *this;}
+      /** クリックされたらサムネイルを閉じるか */
+      thumb_button& dismission_click(bool v){ v?(thumb_.dwFlags |= THBF_DISMISSONCLICK):(thumb_.dwFlags &= ~THBF_DISMISSONCLICK); return *this;}
+      /** ボタンの外枠を描画するかどうか */
+      thumb_button& no_background(bool v){v?(thumb_.dwFlags |= THBF_NOBACKGROUND):(thumb_.dwFlags &= ~THBF_NOBACKGROUND);return *this;}
+      /** 隠すか・表示するか */
+      thumb_button& hidden(bool v){v?(thumb_.dwFlags |= THBF_HIDDEN):(thumb_.dwFlags &= ~ THBF_HIDDEN);return *this;}
+      /** ボタンアクションを起こすかどうか。ボタンを通知目的で使用する際に用いる。*/
+      thumb_button& no_interacive(bool v){v?(thumb_.dwFlags |= THBF_NONINTERACTIVE):(thumb_.dwFlags &= ~THBF_NONINTERACTIVE);return *this;}
+
+    private:
+      THUMBBUTTON& thumb_;
+    };
+    
+    thumb_button_manager() : is_added(false) {}
+
+    // Thumb Buttonは7個までに制限されている
+    thumb_button&  add_thumb_button(uint32_t id,const icon& i,const std::wstring& str)
+    {
+      // 事前条件
+      BOOST_ASSERT(thumb_buttons_.size() < 7 && is_added == false);
+      if(!is_added){
+        thumbbuttons_.push_back(THUMBBUTTON());
+        thumb_buttons_.push_back(thumb_button(id,i,str, (thumbbuttons_.at(thumbbuttons_.size() - 1))));
+      }
+      return thumb_buttons_.at(thumb_buttons_.size() - 1);
+    }
+
+    thumb_button& at(uint32_t i){
+      BOOST_ASSERT(i < thumb_buttons_.size());
+      return thumb_buttons_.at(i);
+    }
+
+    size_t size() const {return thumb_buttons_.size();}
+  private:
+    mutable bool is_added;
+    // メモリ配列を合わせるためにこうした。
+    std::vector<THUMBBUTTON> thumbbuttons_;
+    std::vector<thumb_button> thumb_buttons_;
+    //typedef boost::ptr_vector<thumb_button> thumb_buttons;
+  };
+
+  /** タスクバーAPIのラップクラス。本来であればインターフェースにする方が良いかもしれないけれど */
+  struct taskbar : boost::noncopyable
+  {
+    struct exception
+     : public sf::win32_error_exception 
+    {
+      exception(uint32_t hr) : win32_error_exception(hr) {};
+      exception() : win32_error_exception() {} ;
+    };
+
+     taskbar();
+    ~taskbar();
+    void create();
+    void discard();
+    void overlay_icon(const sf::base_window& w,const icon& ic,const std::wstring& description);
+    void progress_state(const sf::base_window& w,int state);
+    void progress_value(const sf::base_window& w,boost::uint64_t completed, boost::uint64_t total);
+
+    void add_thumb_buttons(const sf::base_window& w,const thumb_button_manager& tm);
+    void update_thumb_buttons(const sf::base_window& w,const thumb_button_manager& tm);
+    bool is_create() const;
+
+    static long register_message();
+
+    static const int none;
+    static const int indeterminate;
+    static const int normal;
+    static const int error;
+    static const int paused;
+
+  private:
+    struct impl;
+    std::shared_ptr<impl> impl_;
+    friend struct impl;
+  };
+
+}
+
diff --git a/dxgi_test/timer.cpp b/dxgi_test/timer.cpp
new file mode 100644 (file)
index 0000000..f468e20
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+  ==============================================================================
+
+   This file is part of the mini timer
+   Copyright 2005-11 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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::stop()
+{
+  if(timer_id_)
+  {
+    ::KillTimer(reinterpret_cast<HWND>(window_.raw_handle()),(UINT_PTR)&timer_id_);
+    timer_id_ = 0;
+  }
+};
+
+}
diff --git a/dxgi_test/timer.h b/dxgi_test/timer.h
new file mode 100644 (file)
index 0000000..81298c0
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+  ==============================================================================
+
+   This file is part of the mini timer
+   Copyright 2005-11 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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 stop();
+  ~timer(){stop();};
+private:
+  sf::base_window& window_;
+  uint32_t timer_id_;
+  uint32_t timeout_;
+};
+}
+
diff --git a/dxgi_test/toplevel_window.cpp b/dxgi_test/toplevel_window.cpp
new file mode 100644 (file)
index 0000000..d5c6dd1
--- /dev/null
@@ -0,0 +1,559 @@
+#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 "toplevel_window.h"
+#include "icon.h"
+#include "timer.h"
+#include "exception.h"
+
+#pragma comment( lib, "dxguid.lib" )
+#pragma comment( lib, "d3d11.lib" )
+#pragma comment( lib, "d3dx11.lib" )
+#pragma comment( lib, "dxgi.lib" )
+#pragma comment( lib, "d3dx9.lib" )   
+#pragma comment( lib, "Shlwapi.lib" ) 
+
+#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 
+{
+
+HRESULT EnableBlurBehind(HWND hwnd)
+{
+  HRESULT hr = S_OK;
+
+  //Create and populate the BlurBehind structre
+  DWM_BLURBEHIND bb = {0};
+  //Enable Blur Behind and Blur Region;
+  bb.dwFlags = DWM_BB_ENABLE;
+  bb.fEnable = true;
+  bb.hRgnBlur = NULL;
+
+  //Enable Blur Behind
+  hr = DwmEnableBlurBehindWindow(hwnd, &bb);
+  if (SUCCEEDED(hr))
+  {
+    //do more things
+  }
+  return hr;
+}
+struct toplevel_window::impl : public base_win32_window
+{
+
+  impl(const std::wstring& menu_name,const std::wstring& name,bool fit_to_display,float width = 160,float height = 100) 
+    : base_win32_window(menu_name,name,fit_to_display,width,height) , timer_(*this,1000)/*wm_task_bar_create_(0),result_time_(INTERVAL_SEC1),status_(active)*/
+  {
+    on_render.connect(boost::bind(&impl::render,this));
+  };
+
+  ~impl(){
+    safe_release(dxgi_factory_);
+    safe_release(factory_);
+    safe_release(write_factory_);
+  };
+
+
+
+  // -------------------------------------------------------------------
+  // ウィンドウプロシージャ
+  // -------------------------------------------------------------------
+  LRESULT window_proc(HWND hwnd,uint32_t message, WPARAM wParam, LPARAM lParam){
+    switch (message)
+    {
+    case WM_CREATE:
+      {
+        // TODO:
+        create_device();
+        //MARGINS mgn = {-1,0,0,0};//let,right,top,bottom
+        //HRESULT hr = DwmExtendFrameIntoClientArea(hwnd_, &mgn);
+      }
+      break;
+    case WM_SIZE:
+      {
+        //if (render_target_)
+        //{
+        //     D2D1_SIZE_U size;
+        //     size.width = lParam & 0xFFFF;
+        //     size.height = (lParam >> 16) & 0xFFFF; ;
+
+        //     // Note: This method can fail, but it's okay to ignore the
+        //     // error here -- it will be repeated on the next call to
+        //     // EndDraw.
+        //     render_target_->Resize(size);
+        //}
+      }
+      break;
+    case WM_PAINT:
+      {
+        //create_device();
+
+        { 
+          paint_struct begin_paint(hwnd);
+          //CloseHandle(cb);
+          // 描画コードの呼び出し
+          render();
+
+        }
+
+//        ::ShowWindow(hwnd_,SW_MINIMIZE);
+      }
+      return FALSE;
+    case WM_DISPLAYCHANGE:
+      {
+        invalidate_rect();
+      }
+      break;
+    case WM_ERASEBKGND:
+      {
+//        return FALSE;
+      }
+      break;
+    case WM_MOUSEMOVE:
+      {
+        //                                     on_mouse_move(GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam),wParam); 
+      }
+      break;
+    case WM_LBUTTONDOWN:
+      {
+      }
+      break;
+    case WM_TIMER:
+      {
+
+      }
+    case WM_DWMCOMPOSITIONCHANGED:
+      {
+        //MARGINS mgn = {-1,0,0,0};//let,right,top,bottom
+        //HRESULT hr = DwmExtendFrameIntoClientArea(hwnd_, &mgn);
+      }
+      break;
+    case WM_COMMAND:
+      //if(HIWORD(wParam) == THBN_CLICKED ){
+      //  switch(LOWORD(wParam)){
+      //  case THUMB_START:
+      //    {
+      //      if(status_ != stop)
+      //      {
+      //        update_status(stop);
+      //      } else {
+      //        update_status(active);
+      //      }
+      //    }
+      //    break;
+      //  }
+      //}
+      break;
+        //::SetTimer(hwnd_,(UINT_PTR)&timer_id_,1000,NULL);
+    }
+
+    if(message == WM_CLOSE)
+    {
+      // timer_.stop();
+      // 後始末
+      discard_device();
+      // レンダーターゲットのリリース
+      //safe_release(dcr_);
+      safe_release(render_target_);
+      // Windowの破棄
+      BOOL ret(::DestroyWindow(hwnd));
+      BOOST_ASSERT(ret != 0);
+    }
+
+    if(message == WM_DESTROY)
+    {
+      ::PostQuitMessage(0);
+      return 0;
+    }
+
+    return ::DefWindowProcW(hwnd,message,wParam,lParam);
+  }
+  
+  virtual void create(){
+    create_device_independent_resources();
+//    icon_ = create_icon();
+    register_class(this->name_.c_str(),CS_HREDRAW | CS_VREDRAW ,0);
+    create_window();
+
+    // 半透明ウィンドウを有効にする。
+    //BOOL dwmEnable;
+    //DwmIsCompositionEnabled (&dwmEnable); 
+    //if (dwmEnable) EnableBlurBehind(*this);
+
+  };
+
+  virtual void discard_device()
+  {
+    safe_release(render_target_);
+  }
+
+  virtual void create_device(){
+    //         入力_.reset(new input(HINST_THISCOMPONENT,hwnd_));
+    HRESULT hr = S_OK;
+
+    //ウィンドウの現在の幅、高さを求める
+    RECT rc;
+    GetClientRect( hwnd_, &rc );
+    uint32_t width = rc.right - rc.left;
+    uint32_t height = rc.bottom - rc.top;
+
+    {
+      //wic_imaging_factory_.CreateInstance(CLSID_WICImagingFactory);
+      //                       bitmap_ = load_bitmap_from_file(render_target_,wic_imaging_factory_,L"myship.png");
+    }
+
+
+    if(!render_target_)
+    {
+      RECT 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(hwnd_, size,D2D1_PRESENT_OPTIONS_IMMEDIATELY),
+        &render_target_
+        ));
+      // Create a DC render target 
+      //D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(
+      //       D2D1_RENDER_TARGET_TYPE_DEFAULT,
+      //       D2D1::PixelFormat(
+      //               DXGI_FORMAT_B8G8R8A8_UNORM,
+      //               D2D1_ALPHA_MODE_IGNORE
+      //               ) , 0.0, 0.0,
+      //       D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE
+      //       );
+
+      //THROW_IFERR(factory_->CreateDCRenderTarget(
+      //       &props,
+      //       &render_target_
+      //       ));
+    }
+  }
+
+  virtual void create_device_independent_resources()
+  {
+
+    // DXGI Factory の 生成
+
+    if(!dxgi_factory_)
+    {
+      THROW_IFERR(CreateDXGIFactory1(dxgi_factory_.GetIID(),reinterpret_cast<void**>(&dxgi_factory_)));
+      get_dxgi_information();
+    }
+
+    // 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_
+        ));
+#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_)
+        ));
+    }
+
+
+    //wic_imaging_factory_.CreateInstance(CLSID_WICImagingFactory);
+
+    //thunk_proc_ = (WNDPROC)thunk_.getCode();
+    layout_rect_ = D2D1::RectF(0.0f,0.0f,width_,height_);
+    // 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 render(){
+
+    static int t = 0;
+
+    if (render_target_)
+    {
+      ++t;
+      // Retrieve the size of the render target.
+      D2D1_SIZE_F renderTargetSize = render_target_->GetSize();
+      try {
+        render_target_->BeginDraw();
+        render_target_->Clear(D2D1::ColorF(0,0.0f));
+//        render_target_->FillRectangle(D2D1::RectF(0.0f,0.0f,renderTargetSize.width,renderTargetSize.height),);
+         
+//          (D2D1::ColorF(0,1.0f));
+        render_target_->SetTransform(D2D1::Matrix3x2F::Identity());
+        ID2D1SolidColorBrushPtr brush;
+        render_target_->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::OrangeRed), &brush);
+
+        std::wstring m(L"TEST");
+        render_target_->DrawTextW(
+          m.c_str(),
+          m.size(),
+          write_text_format_,
+          layout_rect_, 
+          brush);
+        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;
+      }
+    }
+  }
+
+  void create_window()
+  {
+
+    // Windowを作成する
+    CreateWindowEx(
+      WS_EX_APPWINDOW | WS_EX_TOPMOST,
+      name_.c_str(),
+      title_.c_str(),
+      WS_OVERLAPPEDWINDOW ,
+      CW_USEDEFAULT,
+      CW_USEDEFAULT,
+      static_cast<uint32_t>(dpi_.scale_x(width_)),
+      static_cast<uint32_t>(dpi_.scale_x(height_)),
+      NULL,
+      NULL,
+      HINST_THISCOMPONENT,
+      this
+      );
+  };
+
+  void get_dxgi_information()
+  {
+    int i = 0;
+    while(1){
+      IDXGIAdapter1Ptr adapter;
+      HRESULT hr = dxgi_factory_->EnumAdapters1(i,&adapter);
+      if(hr == DXGI_ERROR_NOT_FOUND)
+      {
+        break;
+      }
+      DXGI_ADAPTER_DESC1 desc;
+      adapter->GetDesc1(&desc);
+      adapter->CheckInterfaceSupport();
+      wdout << desc.Description << std::endl;
+      wdout << desc.DedicatedVideoMemory << std::endl;
+      IDXGIDevice1Ptr device;
+
+      uint32_t oi = 0;
+      while(1)
+      {
+        IDXGIOutputPtr output;        
+        if(adapter->EnumOutputs(oi,&output) == DXGI_ERROR_NOT_FOUND){
+          break;
+        }
+        DXGI_OUTPUT_DESC output_desc;
+        output->GetDesc(&output_desc); 
+//        output->
+        wdout << output_desc.DeviceName << std::endl; 
+        oi++;
+      }
+
+      adapter.Release();
+      ++i;
+    }
+  }
+private:
+  //long wm_task_bar_create_;
+  //sf::taskbar taskbar_;
+  sf::timer timer_;
+
+  IDXGIFactory1Ptr dxgi_factory_;
+  //IDXGISwapChainPtr; 
+  ID2D1FactoryPtr factory_;
+  ID2D1HwndRenderTargetPtr render_target_;
+  IDWriteFactoryPtr write_factory_;
+  IWICImagingFactoryPtr wic_imaging_factory_;
+  IDWriteTextFormatPtr write_text_format_;
+  IDXGISwapChainPtr swap_chain_;
+  std::wstring dxgi_info_;
+
+  D2D1_RECT_F layout_rect_;
+  D2D1_SIZE_U icon_size_;
+};
+
+  //
+  // Creates a Direct2D bitmap from the specified
+  // file name.
+  //
+  ID2D1BitmapPtr load_bitmap_from_file(
+    ID2D1HwndRenderTargetPtr render_target,
+    IWICImagingFactoryPtr wic_factory,
+    std::wstring uri,
+    uint32_t destination_width,
+    uint32_t destination_height
+    )
+  {
+    HRESULT hr = S_OK;
+
+    IWICBitmapDecoderPtr decoder;
+    IWICBitmapFrameDecodePtr decoder_source;
+    IWICStreamPtr stream;
+    IWICFormatConverterPtr converter;
+    IWICBitmapScalerPtr scaler;
+    ID2D1BitmapPtr bitmap;
+
+    THROW_IFERR(wic_factory->CreateDecoderFromFilename(
+      uri.c_str(),
+      NULL,
+      GENERIC_READ,
+      WICDecodeMetadataCacheOnLoad,
+      &decoder
+      ));
+
+    // Create the initial frame.
+    THROW_IFERR(decoder->GetFrame(0, &decoder_source));
+
+    // Convert the image format to 32bppPBGRA
+    // (DXGI_FORMAT_B8G8R8A8_UNORM + D2D1_ALPHA_MODE_PREMULTIPLIED).
+    THROW_IFERR(hr = wic_factory->CreateFormatConverter(&converter));
+
+    // If a new width or height was specified, create an
+    // IWICBitmapScaler and use it to resize the image.
+    if (destination_width != 0 || destination_height != 0)
+    {
+      uint32_t originalWidth, originalHeight;
+      THROW_IFERR(decoder_source->GetSize((UINT*)&originalWidth, (UINT*)&originalHeight));
+      if (destination_width == 0)
+      {
+        FLOAT scalar = static_cast<FLOAT>(destination_height) / static_cast<FLOAT>(originalHeight);
+        destination_width = static_cast<uint32_t>(scalar * static_cast<FLOAT>(originalWidth));
+      }
+      else if (destination_height == 0)
+      {
+        FLOAT scalar = static_cast<FLOAT>(destination_width) / static_cast<FLOAT>(originalWidth);
+        destination_height = static_cast<uint32_t>(scalar * static_cast<FLOAT>(originalHeight));
+      }
+
+      THROW_IFERR(wic_factory->CreateBitmapScaler(&scaler));
+      THROW_IFERR(scaler->Initialize(
+        decoder_source,
+        destination_width,
+        destination_height,
+        WICBitmapInterpolationModeCubic
+        ));
+      THROW_IFERR(converter->Initialize(
+        scaler.GetInterfacePtr(),
+        GUID_WICPixelFormat32bppPBGRA,
+        WICBitmapDitherTypeNone,
+        NULL,
+        0.f,
+        WICBitmapPaletteTypeMedianCut
+        ));
+    }
+    else // Don't scale the image.
+    {
+      THROW_IFERR(converter->Initialize(
+        decoder_source.GetInterfacePtr(),
+        GUID_WICPixelFormat32bppPBGRA,
+        WICBitmapDitherTypeNone,
+        NULL,
+        0.f,
+        WICBitmapPaletteTypeMedianCut
+        ));
+    }
+
+    // Create a Direct2D bitmap from the WIC bitmap.
+    THROW_IFERR(render_target->CreateBitmapFromWicBitmap(
+      converter.GetInterfacePtr(),
+      NULL,
+      &bitmap
+      ));
+
+    return bitmap;
+  }
+
+  toplevel_window::toplevel_window(const std::wstring& menu_name,const std::wstring& name,bool fit_to_display,float width ,float height)
+    : impl_(new impl(menu_name,name,fit_to_display,width,height))
+  {
+
+  };
+
+  void * toplevel_window::raw_handle() const {return impl_->raw_handle();};
+  void toplevel_window::create(){impl_->create();};
+  void toplevel_window::show(){impl_->show();};
+  void toplevel_window::hide(){impl_->hide();};
+  bool toplevel_window::is_show(){return impl_->is_show();};
+  void toplevel_window::text(std::wstring& text){impl_->text(text);};
+  void toplevel_window::update(){impl_->update();};
+
+ toplevel_window_ptr create_toplevel_window
+    (
+    const std::wstring& menu_name,
+    const std::wstring& name,
+    const uint32_t show_flag,
+    bool fit_to_display,
+    float width,
+    float height
+    )
+  {
+    toplevel_window* p = new toplevel_window(menu_name,name,fit_to_display,width,height);
+    p->create();
+    p->show();
+    p->update();
+    return toplevel_window_ptr(p);
+  }
+  
+}
+
diff --git a/dxgi_test/toplevel_window.h b/dxgi_test/toplevel_window.h
new file mode 100644 (file)
index 0000000..be81cd3
--- /dev/null
@@ -0,0 +1,55 @@
+#pragma once
+/*
+*/
+// Windows Header Files:
+#include "base_window.h"
+#include "taskbar.h"
+namespace sf
+{
+
+  struct toplevel_window;
+  typedef std::shared_ptr<toplevel_window> toplevel_window_ptr;
+
+  /** toplevel_window を生成する関数 */
+  toplevel_window_ptr create_toplevel_window (
+    const std::wstring& menu_name,
+    const std::wstring& name,
+    const uint32_t show_flag = SW_SHOW,
+    bool fit_to_display = false,
+    float width = 640,
+    float height = 480
+    );
+
+  /** toplevel ウィンドウクラス */
+  /* このクラスは、create_toplevel_window 関数からのみ生成可能 */
+  struct toplevel_window : public base_window
+  {
+
+    friend   toplevel_window_ptr create_toplevel_window
+      (
+      const std::wstring& menu_name,
+      const std::wstring& name,
+      const uint32_t show_flag,
+      bool fit_to_display ,
+      float width ,
+      float height 
+      );
+
+    ~toplevel_window(){};
+    void * raw_handle() const;
+    void create();
+    void toplevel_window::show();
+    bool toplevel_window::is_show();
+    void toplevel_window::hide();
+
+    void text(std::wstring& text);
+    void update();
+
+  private:
+    struct impl;
+    toplevel_window(const std::wstring& menu_name,const std::wstring& name,bool fit_to_display,float width = 800 ,float height = 600);
+    // 実装部
+    std::shared_ptr<impl> impl_;
+  };
+}
\ No newline at end of file
diff --git a/dxgi_test/wasapi.cpp b/dxgi_test/wasapi.cpp
new file mode 100644 (file)
index 0000000..d0dea0c
--- /dev/null
@@ -0,0 +1,196 @@
+/*
+  ==============================================================================
+
+   Copyright 2005-11 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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 "sf_memory.h"
+#include "audio_base.h"
+#include "wasapi.h"
+
+#define THROW_IF_ERR(x) sf::throw_if_err<>()(x)
+
+namespace sf{
+  wasapi_shared_timer::wasapi_shared_timer() 
+    : is_enabled_(false),buffer_control_event_(::CreateEventEx(NULL, NULL, 0, EVENT_MODIFY_STATE | SYNCHRONIZE))
+  {
+    if(buffer_control_event_ == NULL)
+    {
+      return;
+    }
+
+    try {
+//      thread_priority_.set_priority(AVRT_PRIORITY_NORMAL);
+
+      // WASAPI\82Ì\8f\89\8aú\89»\8f\88\97\9d
+
+      // IMMDeviceEnumerator\82Ì\8eæ\93¾
+      THROW_IF_ERR(
+        CoCreateInstance(
+          __uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER,
+          IID_PPV_ARGS(&device_enumerator_)));
+      
+      // \83f\83t\83H\83\8b\83g\82Ì\83I\81[\83f\83B\83I\83f\83o\83C\83X\82ð\8eæ\93¾\82·\82é
+      THROW_IF_ERR(
+        device_enumerator_
+          ->GetDefaultAudioEndpoint(eRender,eMultimedia,&current_device_)
+       );
+
+      // \83I\81[\83f\83B\83I\83N\83\89\83C\83A\83\93\83g\82ð\8eæ\93¾
+      THROW_IF_ERR(
+        current_device_
+          ->Activate(__uuidof(IAudioClient), CLSCTX_INPROC_SERVER,
+          NULL, reinterpret_cast<void **>(&audio_client_))
+        );
+
+      // \83t\83H\81[\83}\83b\83g\92è\8b`
+      audio_client_->GetMixFormat(&mix_format_);
+      WAVEFORMATEXTENSIBLE *waveFormatExtensible = reinterpret_cast<WAVEFORMATEXTENSIBLE *>((WAVEFORMATEX*)mix_format_.get());
+      waveFormatExtensible->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
+      waveFormatExtensible->Format.wBitsPerSample = 16;
+      waveFormatExtensible->Format.nBlockAlign = (mix_format_->wBitsPerSample / 8) * mix_format_->nChannels;
+      waveFormatExtensible->Format.nAvgBytesPerSec = waveFormatExtensible->Format.nSamplesPerSec*waveFormatExtensible->Format.nBlockAlign;
+      waveFormatExtensible->Samples.wValidBitsPerSample = 16;
+
+      //mix_format_->wFormatTag = WAVE_FORMAT_PCM;
+      //mix_format_->wBitsPerSample = 16;
+      //mix_format_->nBlockAlign = (mix_format_->wBitsPerSample / 8) * mix_format_->nChannels;
+      //mix_format_->nAvgBytesPerSec = mix_format_->nSamplesPerSec*mix_format_->nBlockAlign;
+     sf::co_task_memory<WAVEFORMATEX>  alt_format;
+      THROW_IF_ERR(
+        audio_client_->IsFormatSupported(
+        AUDCLNT_SHAREMODE_SHARED,mix_format_.get(),&alt_format));
+
+      // \8dÄ\90\83N\83\89\83C\83A\83\93\83g\82Ì\8f\89\8aú\89»
+
+      REFERENCE_TIME buffer_period =  latency_ms_ /* ms */ * 10000 ;
+
+      REFERENCE_TIME buffer_duration = buffer_period * periods_per_buffer_;
+
+      THROW_IF_ERR(audio_client_->Initialize(AUDCLNT_SHAREMODE_SHARED, 
+                                            AUDCLNT_STREAMFLAGS_NOPERSIST, 
+                                            buffer_duration, 
+                                            buffer_period,
+                                            mix_format_.get(), 
+                                            NULL));
+
+
+      // \83o\83b\83t\83@\83T\83C\83Y\82Ì\8eæ\93¾
+      THROW_IF_ERR(audio_client_->GetBufferSize(&buffer_size_));
+
+      // \8dÄ\90\83N\83\89\83C\83A\83\93\83g\82Ì\8eæ\93¾
+      THROW_IF_ERR(audio_client_->GetService(IID_PPV_ARGS(&audio_render_client_)));
+
+      // 
+      num_of_frames_ = mix_format_->nBlockAlign;
+
+      is_enabled_ = true;
+    } catch (win32_error_exception& e)
+    {
+      exception_holder_.reset(new win32_error_exception(e.hresult()));
+      is_enabled_ = false;
+    } catch(...) {
+      is_enabled_ = false;
+    }
+  }
+
+  wasapi_shared_timer::~wasapi_shared_timer()
+  {
+
+      // WASAPI\82Ì\8fI\97¹\8f\88\97\9d
+    if(audio_client_)
+    {
+      audio_client_->Stop();
+      audio_client_.Release();
+    }
+  }
+
+  void wasapi_shared_timer::create_wave_data(){
+    // \83T\83C\83\93\94g\82Ì\90\90¬
+    boost::uint32_t buffer_size_in_bytes = buffer_size_ * mix_format_->nBlockAlign;
+    size_t render_data_length = mix_format_->nSamplesPerSec * 10 /* \95b */ * mix_format_->nBlockAlign / sizeof(short);
+    tone_buffer_.reserve(render_data_length);
+
+    double sampleIncrement = (440 /* Hz */ * (M_PI * 2.0)) / (double)mix_format_->nSamplesPerSec;
+    double theta = 0.0;
+
+    for (size_t i = 0 ; i < render_data_length ; i += mix_format_->nChannels)
+    {
+        double sinValue = sin( theta );
+        for(size_t j = 0 ;j < mix_format_->nChannels; j++)
+        {
+            tone_buffer_.push_back((short)(sinValue * _I16_MAX));
+        }
+        theta += sampleIncrement;
+    }
+  };
+
+  void wasapi_shared_timer::play()
+  {
+    BYTE* buffer;
+    boost::uint32_t pos = 0;
+    const size_t inc  = (buffer_size_ * num_of_frames_) / (sizeof(short) * periods_per_buffer_);
+    const size_t buffer_in_periods = buffer_size_ / periods_per_buffer_;
+    
+    // \83T\83C\83\93\94g\82ð\90\90¬\82·\82é
+    create_wave_data();
+
+    // \8dÅ\8f\89\82É\83o\83b\83t\83@\82ð\96\84\82ß\82é
+    THROW_IF_ERR(audio_render_client_->GetBuffer(buffer_size_,&buffer));
+    ::CopyMemory(buffer,(BYTE*)&(tone_buffer_[pos]),buffer_size_ * num_of_frames_);
+
+    // \83\8c\83C\83e\83\93\83V\8e\9e\8aÔ*\83o\83b\83t\83@\90\94\95ª\90i\82ß\82é
+    pos += inc * periods_per_buffer_;
+    THROW_IF_ERR(audio_render_client_->ReleaseBuffer(buffer_size_,0));
+
+    // \8dÄ\90\8aJ\8en
+    THROW_IF_ERR(audio_client_->Start());
+
+    // \8dÄ\90\83\8b\81[\83v
+    while(pos < tone_buffer_.size())
+    {
+      // \83\8c\83C\83e\83\93\83V\8e\9e\8aÔ\82¾\82¯\91Ò\82Â
+      Sleep(latency_ms_);
+      uint32_t padding;
+      uint32_t frames_available;
+      // \83p\83f\83B\83\93\83O\82ð\8b\81\82ß\82é\81B
+      THROW_IF_ERR(audio_client_->GetCurrentPadding(&padding));
+      frames_available = buffer_size_ - padding;
+
+      // \83p\83f\83B\83\93\83O\82ð\8f\9c\82¢\82½\95\94\95ª\82Ì\83o\83b\83t\83@\82ð\96\84\82ß\82é\81B
+      // \83p\83f\83B\83\93\83O\82ð\8f\9c\82¢\82½\95\94\95ª\82Ì\83T\83C\83Y\82ªbuffer_in_periods\82æ\82è\8f¬\82³\82¢\8fê\8d\87\82Í\82Â\82¬\82É\82Ü\82í\82·\81B
+      // \83p\83f\83B\83\93\83O\82ð\8f\9c\82¢\82½\95\94\95ª\82ð\88ê\8bC\82É\96\84\82ß\82æ\82¤\82Æ\82µ\82½\82¯\82Ç\82Å\82«\82È\82©\82Á\82½\81B\81B
+      while(pos < tone_buffer_.size() && (buffer_in_periods <= frames_available) ) 
+      {
+        THROW_IF_ERR(audio_render_client_->GetBuffer(buffer_in_periods,&buffer));
+        ::CopyMemory(buffer,(BYTE*)&(tone_buffer_[pos]),buffer_in_periods *  num_of_frames_);
+        THROW_IF_ERR(audio_render_client_->ReleaseBuffer(buffer_in_periods,0));
+        // \83\8c\83C\83e\83\93\83V\8e\9e\8aÔ\82¾\82¯\90i\82ß\82é
+        pos += inc;
+        // \83p\83f\83B\83\93\83O\82ð\8dÄ\93x\8b\81\82ß\82é
+        THROW_IF_ERR(audio_client_->GetCurrentPadding(&padding));
+        frames_available = buffer_size_ - padding;
+      }
+    }
+
+    //\8dÄ\90\92â\8e~
+    THROW_IF_ERR(audio_client_->Stop());
+  }
+}
diff --git a/dxgi_test/wasapi.h b/dxgi_test/wasapi.h
new file mode 100644 (file)
index 0000000..76ba5c5
--- /dev/null
@@ -0,0 +1,86 @@
+#pragma once
+/*
+  ==============================================================================
+
+   Copyright 2005-11 by Satoshi Fujiwara.
+
+   mini timer 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.
+
+   mini timer 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 mini timer; 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
+
+  ==============================================================================
+*/
+// WASAPI
+#include "exception.h"
+#include <mmdeviceapi.h>
+#include <AudioClient.h>
+#include <audiopolicy.h>
+
+#define _USE_MATH_DEFINES
+#include <math.h>
+#include <limits.h>
+#pragma comment(lib, "winmm.lib")
+#pragma comment(lib, "Avrt.lib")
+
+#include "audio_base.h"
+
+// COM Pointer \92è\8b`
+_COM_SMARTPTR_TYPEDEF(IMMDeviceEnumerator,__uuidof(IMMDeviceEnumerator));
+_COM_SMARTPTR_TYPEDEF(IMMDevice,__uuidof(IMMDevice));
+_COM_SMARTPTR_TYPEDEF(IAudioClient,__uuidof(IAudioClient));
+_COM_SMARTPTR_TYPEDEF(IAudioRenderClient,__uuidof(IAudioRenderClient));
+
+namespace sf {
+
+struct device_manager
+{
+  IMMDeviceEnumeratorPtr mm_device_enumerator;
+};
+
+
+/// WASAPI\8f\88\97\9d\83N\83\89\83X
+struct wasapi_shared_timer : public audio_base
+{
+  wasapi_shared_timer();
+  virtual ~wasapi_shared_timer();
+
+  bool is_enabled () const {return is_enabled_;}
+  /// \83e\83X\83g\97\83T\83C\83\93\94g\83f\81[\83^\82Ì\90\90¬
+  void create_wave_data();
+
+  /// \83T\83E\83\93\83h\8dÄ\90\8f\88\97\9d
+  void play();
+
+  win32_error_exception* const result() {return exception_holder_.get(); }
+
+private:
+  IMMDeviceEnumeratorPtr device_enumerator_;
+  IMMDevicePtr current_device_;
+  IAudioClientPtr audio_client_;
+  IAudioRenderClientPtr audio_render_client_;
+  handle_holder buffer_control_event_;
+  co_task_memory<WAVEFORMATEX> mix_format_;
+  bool is_enabled_;
+  boost::shared_ptr<win32_error_exception> exception_holder_;
+  boost::uint32_t num_of_frames_;
+  boost::uint32_t buffer_size_;
+  std::vector<short> tone_buffer_;
+
+  // \8dÄ\90\83\8c\83C\83e\83\93\83V
+  static const uint32_t latency_ms_ = 50;/* ms */
+  // \83o\83b\83t\83@\92\86\82Ì\8bæ\90Ø\82è\90\94\81i\83\8c\83C\83e\83\93\83V\8e\9e\8aÔ\82ª\89½\8cÂ\82 \82é\82©\81j
+  static const uint32_t periods_per_buffer_ = 4;
+};
+}
+
diff --git a/dxgi_test/winmain.cpp b/dxgi_test/winmain.cpp
new file mode 100644 (file)
index 0000000..987a48c
--- /dev/null
@@ -0,0 +1,12 @@
+#include "stdafx.h"
+#include "application.h";
+/** WinMain */
+int APIENTRY _tWinMain(HINSTANCE hInstance,
+                     HINSTANCE hPrevInstance,
+                     LPTSTR    lpCmdLine,
+                     int       nCmdShow)
+{
+       
+  return sf::application::instance()
+    ->execute( hInstance,hPrevInstance,lpCmdLine,nCmdShow);
+}