From: shimitei Date: Tue, 27 Apr 2021 13:11:53 +0000 (+0900) Subject: [Refactor] main-win.cpp処理の分割 X-Git-Tag: vmacos3.0.0-alpha52~215^2~1^2~2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=caf2ee1197267b1b49d190731e9e2b93048cd858;p=hengbandforosx%2Fhengbandosx.git [Refactor] main-win.cpp処理の分割 「画面をHTMLで保存」、重複起動チェックの処理をmain-win.cppからmain-win-utils.cppへ移動した。 --- diff --git a/Hengband/Hengband/Hengband.vcxproj b/Hengband/Hengband/Hengband.vcxproj index b631ec2fc..168b1c2dc 100644 --- a/Hengband/Hengband/Hengband.vcxproj +++ b/Hengband/Hengband/Hengband.vcxproj @@ -268,6 +268,7 @@ + @@ -937,6 +938,7 @@ + @@ -1869,4 +1871,4 @@ - \ No newline at end of file + diff --git a/Hengband/Hengband/Hengband.vcxproj.filters b/Hengband/Hengband/Hengband.vcxproj.filters index 903ac96a3..dee676558 100644 --- a/Hengband/Hengband/Hengband.vcxproj.filters +++ b/Hengband/Hengband/Hengband.vcxproj.filters @@ -2262,6 +2262,9 @@ hpmp + + main-win + @@ -4851,7 +4854,7 @@ store - + main-win @@ -5089,4 +5092,4 @@ - \ No newline at end of file + diff --git a/src/Makefile.am b/src/Makefile.am index 8551f658b..7c225571e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 = \ diff --git a/src/main-win.cpp b/src/main-win.cpp index f4c8cc7f3..294e750c6 100644 --- a/src/main-win.cpp +++ b/src/main-win.cpp @@ -3,7 +3,6 @@ * @brief Windows版固有実装(メインエントリポイント含む) * @date 2018/03/16 * @author Hengband Team - * @todo main関数を含むファイルの割に長過ぎる。main-win-utils.cなどといった形で分割したい * @details * *

概要

@@ -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" @@ -106,12 +104,11 @@ #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 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 index 000000000..c6bc6c11c --- /dev/null +++ b/src/main-win/main-win-utils.cpp @@ -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 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); + } +} diff --git a/src/main-win/string-win.h b/src/main-win/main-win-utils.h similarity index 88% rename from src/main-win/string-win.h rename to src/main-win/main-win-utils.h index 97b94a64e..b4debced8 100644 --- a/src/main-win/string-win.h +++ b/src/main-win/main-win-utils.h @@ -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 /*! - * @brief 文字列をワイド文字列へ変換するクラス + * @brief マルチバイト文字列をワイド文字列へ変換するクラス */ class to_wchar { public: @@ -106,3 +106,6 @@ protected: } } }; + +bool is_already_running(void); +void save_screen_as_html(HWND hWnd);