OSDN Git Service

[Refactor] main-win.cpp処理の分割
authorshimitei <shimitei@gmail.com>
Tue, 27 Apr 2021 13:11:53 +0000 (22:11 +0900)
committershimitei <shimitei@gmail.com>
Thu, 29 Apr 2021 04:26:33 +0000 (13:26 +0900)
「画面をHTMLで保存」、重複起動チェックの処理をmain-win.cppからmain-win-utils.cppへ移動した。

Hengband/Hengband/Hengband.vcxproj
Hengband/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/main-win.cpp
src/main-win/main-win-utils.cpp [new file with mode: 0644]
src/main-win/main-win-utils.h [moved from src/main-win/string-win.h with 88% similarity]

index b631ec2..168b1c2 100644 (file)
     <ClCompile Include="..\..\src\cmd-action\cmd-tunnel.cpp" />\r
     <ClCompile Include="..\..\src\action\movement-execution.cpp" />\r
     <ClCompile Include="..\..\src\main-win\graphics-win.cpp" />\r
+    <ClCompile Include="..\..\src\main-win\main-win-utils.cpp" />\r
     <ClCompile Include="..\..\src\store\cmd-store.cpp" />\r
     <ClCompile Include="..\..\src\cmd-io\cmd-floor.cpp" />\r
     <ClCompile Include="..\..\src\cmd-io\cmd-lore.cpp" />\r
     <ClInclude Include="..\..\src\main-win\graphics-win.h" />\r
     <ClInclude Include="..\..\src\main-win\string-win.h" />\r
     <ClInclude Include="..\..\src\player-status\player-hand-types.h" />\r
+    <ClInclude Include="..\..\src\main-win\main-win-utils.h" />\r
     <ClInclude Include="..\..\src\store\cmd-store.h" />\r
     <ClInclude Include="..\..\src\cmd-io\cmd-floor.h" />\r
     <ClInclude Include="..\..\src\cmd-io\cmd-lore.h" />\r
     <Error Condition="!Exists('..\packages\Microsoft.NetFramework.Analyzers.3.0.0\build\Microsoft.NetFramework.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NetFramework.Analyzers.3.0.0\build\Microsoft.NetFramework.Analyzers.props'))" />\r
     <Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.3.0.0\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.3.0.0\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props'))" />\r
   </Target>\r
-</Project>
\ No newline at end of file
+</Project>\r
index 903ac96..dee6765 100644 (file)
     <ClCompile Include="..\..\src\hpmp\hp-mp-regenerator.cpp">\r
       <Filter>hpmp</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\..\src\main-win\main-win-utils.cpp">\r
+      <Filter>main-win</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="..\..\src\combat\shoot.h">\r
     <ClInclude Include="..\..\src\store\store-key-processor.h">\r
       <Filter>store</Filter>\r
     </ClInclude>\r
-    <ClInclude Include="..\..\src\main-win\string-win.h">\r
+    <ClInclude Include="..\..\src\main-win\main-win-utils.h">\r
       <Filter>main-win</Filter>\r
     </ClInclude>\r
     <ClInclude Include="..\..\src\main-win\graphics-win.h">\r
   <ItemGroup>\r
     <ResourceCompile Include="..\..\src\angband.rc" />\r
   </ItemGroup>\r
-</Project>
\ No newline at end of file
+</Project>\r
index 8551f65..7c22557 100644 (file)
@@ -928,8 +928,9 @@ EXTRA_hengband_SOURCES = \
        main-win/main-win-music.cpp main-win/main-win-music.h \
        main-win/main-win-sound.cpp main-win/main-win-sound.h \
        main-win/main-win-tokenizer.cpp main-win/main-win-tokenizer.h \
+       main-win/main-win-utils.cpp main-win/main-win-utils.h \
        main-win/main-win-windows.h \
-       main-win/string-win.h wall.bmp \
+       wall.bmp \
        stdafx.cpp stdafx.h
 
 EXTRA_DIST = \
index f4c8cc7..294e750 100644 (file)
@@ -3,7 +3,6 @@
  * @brief Windows版固有実装(メインエントリポイント含む)
  * @date 2018/03/16
  * @author Hengband Team
- * @todo main関数を含むファイルの割に長過ぎる。main-win-utils.cなどといった形で分割したい
  * @details
  *
  * <h3>概要</h3>
@@ -82,7 +81,6 @@
 
 #ifdef WINDOWS
 
-#include "cmd-io/cmd-process-screen.h"
 #include "cmd-io/cmd-save.h"
 #include "cmd-visual/cmd-draw.h"
 #include "core/game-play.h"
 #include "main-win/main-win-menuitem.h"
 #include "main-win/main-win-music.h"
 #include "main-win/main-win-sound.h"
-#include "main-win/string-win.h"
+#include "main-win/main-win-utils.h"
 #include "main/angband-initializer.h"
 #include "main/sound-of-music.h"
 #include "monster-floor/monster-lite.h"
 #include "save/save.h"
-#include "system/angband-version.h"
 #include "system/angband.h"
 #include "system/player-type-definition.h"
 #include "system/system-variables.h"
@@ -1980,24 +1977,7 @@ static void process_menus(player_type *player_ptr, WORD wCmd)
         break;
     }
     case IDM_DUMP_SCREEN_HTML: {
-        OPENFILENAMEW ofnw;
-        std::vector<WCHAR> buf(MAIN_WIN_MAX_PATH + 1);
-        memset(&ofnw, 0, sizeof(ofnw));
-        ofnw.lStructSize = sizeof(ofnw);
-        ofnw.hwndOwner = data[0].w;
-        ofnw.lpstrFilter = L"HTML Files (*.html)\0*.html\0";
-        ofnw.nFilterIndex = 1;
-        ofnw.lpstrFile = &buf[0];
-        ofnw.nMaxFile = MAIN_WIN_MAX_PATH;
-        ofnw.lpstrDefExt = L"html";
-        ofnw.lpstrInitialDir = NULL;
-        ofnw.lpstrTitle = _(L"HTMLでスクリーンダンプを保存", L"Save screen dump as HTML.");
-        ofnw.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
-
-        if (GetSaveFileNameW(&ofnw)) {
-            do_cmd_save_screen_html_aux(to_multibyte(&buf[0]).c_str(), 0);
-        }
-
+        save_screen_as_html(data[0].w);
         break;
     }
     }
@@ -2127,7 +2107,7 @@ static void handle_app_active(HWND hWnd, UINT uMsg, WPARAM wParam, [[maybe_unuse
 }
 
 /*!
- * @todo WNDCLASSに影響があるのでplayer_type*の追加は保留
+ * @brief メインウインドウ用ウインドウプロシージャ
  */
 LRESULT PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
@@ -2434,7 +2414,7 @@ LRESULT PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
 }
 
 /*!
- * @todo WNDCLASSに影響があるのでplayer_type*の追加は保留
+ * @brief サブウインドウ用ウインドウプロシージャ
  */
 LRESULT PASCAL AngbandListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
@@ -2681,21 +2661,6 @@ static spoiler_output_status create_debug_spoiler(LPSTR cmd_line)
 }
 
 /*!
- * @todo よく見るとhMutexはちゃんと使われていない……?
- * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
- */
-static bool is_already_running(void)
-{
-    HANDLE hMutex;
-    hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
-    if (GetLastError() == ERROR_ALREADY_EXISTS) {
-        return TRUE;
-    }
-
-    return FALSE;
-}
-
-/*!
  * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
  */
 int WINAPI WinMain(_In_ HINSTANCE hInst, _In_opt_ HINSTANCE hPrevInst, _In_ LPSTR lpCmdLine, [[maybe_unused]] _In_ int nCmdShow)
diff --git a/src/main-win/main-win-utils.cpp b/src/main-win/main-win-utils.cpp
new file mode 100644 (file)
index 0000000..c6bc6c1
--- /dev/null
@@ -0,0 +1,57 @@
+/*!
+ * @file main-win-utils.cpp
+ * @brief Windows版固有実装(ユーティリティー)
+ */
+
+#include "main-win/main-win-utils.h"
+#include "cmd-io/cmd-process-screen.h"
+#include "locale/language-switcher.h"
+#include "main-win/main-win-define.h"
+#include "system/angband-version.h"
+
+/*!
+ * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
+ * @details
+ * 特定の名前のミューテックスオブジェクトの所有権取得を試みる。
+ * 取得できない場合は他に変愚蛮怒のプロセスが起動しているとみなす。
+ * 取得したミューテックスのハンドルは明示的な解放は行わず、プロセス終了時にOSが解放する。
+ * @retval true 他に変愚蛮怒のプロセスが起動している
+ * @retval false 他に変愚蛮怒のプロセスは起動していない
+ */
+bool is_already_running(void)
+{
+    [[maybe_unused]] HANDLE hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
+    if (GetLastError() == ERROR_ALREADY_EXISTS) {
+        return true;
+    }
+
+    return false;
+}
+
+/*!
+ * @brief (Windows固有)画面をHTMLファイルに保存する
+ * @details
+ * ファイル保存ダイアログを表示し、指定のファイルに画面内容を保存する。
+ * @param hWnd ダイアログの親にするウインドウのハンドル
+ */
+void save_screen_as_html(HWND hWnd)
+{
+    std::vector<WCHAR> buf(MAIN_WIN_MAX_PATH + 1);
+    OPENFILENAMEW ofnw;
+
+    memset(&ofnw, 0, sizeof(ofnw));
+    ofnw.lStructSize = sizeof(ofnw);
+    ofnw.hwndOwner = hWnd;
+    ofnw.lpstrFilter = L"HTML Files (*.html)\0*.html\0";
+    ofnw.nFilterIndex = 1;
+    ofnw.lpstrFile = &buf[0];
+    ofnw.nMaxFile = MAIN_WIN_MAX_PATH;
+    ofnw.lpstrDefExt = L"html";
+    ofnw.lpstrInitialDir = NULL;
+    ofnw.lpstrTitle = _(L"HTMLでスクリーンダンプを保存", L"Save screen dump as HTML.");
+    ofnw.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
+
+    if (GetSaveFileNameW(&ofnw)) {
+        do_cmd_save_screen_html_aux(to_multibyte(&buf[0]).c_str(), 0);
+    }
+}
similarity index 88%
rename from src/main-win/string-win.h
rename to src/main-win/main-win-utils.h
index 97b94a6..b4debce 100644 (file)
@@ -1,7 +1,7 @@
 #pragma once
 /*!
- * @file string-win.h
- * @brief Windows版固有実装(文字列)ヘッダ
+ * @file main-win-utils.h
+ * @brief Windows版固有実装(ユーティリティー)ヘッダ
  */
 
 #include "term/z-virt.h"
@@ -9,7 +9,7 @@
 #include <windows.h>
 
 /*!
- * @brief 文字列をワイド文字列へ変換するクラス
+ * @brief マルチバイト文字列をワイド文字列へ変換するクラス
  */
 class to_wchar {
 public:
@@ -106,3 +106,6 @@ protected:
         }
     }
 };
+
+bool is_already_running(void);
+void save_screen_as_html(HWND hWnd);