OSDN Git Service

Merge pull request #993 from iks3/fix-imp-food
[hengbandforosx/hengbandosx.git] / src / main-win / main-win-utils.cpp
1 /*!
2  * @file main-win-utils.cpp
3  * @brief Windows版固有実装(ユーティリティー)
4  */
5
6 #include "main-win/main-win-utils.h"
7 #include "cmd-io/cmd-process-screen.h"
8 #include "locale/language-switcher.h"
9 #include "main-win/main-win-define.h"
10 #include "system/angband-version.h"
11
12 /*!
13  * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
14  * @details
15  * 特定の名前のミューテックスオブジェクトの所有権取得を試みる。
16  * 取得できない場合は他に変愚蛮怒のプロセスが起動しているとみなす。
17  * 取得したミューテックスのハンドルは明示的な解放は行わず、プロセス終了時にOSが解放する。
18  * @retval true 他に変愚蛮怒のプロセスが起動している
19  * @retval false 他に変愚蛮怒のプロセスは起動していない
20  */
21 bool is_already_running(void)
22 {
23     [[maybe_unused]] HANDLE hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
24     if (GetLastError() == ERROR_ALREADY_EXISTS) {
25         return true;
26     }
27
28     return false;
29 }
30
31 /*!
32  * @brief (Windows固有)画面をHTMLファイルに保存する
33  * @details
34  * ファイル保存ダイアログを表示し、指定のファイルに画面内容を保存する。
35  * @param hWnd ダイアログの親にするウインドウのハンドル
36  */
37 void save_screen_as_html(HWND hWnd)
38 {
39     std::vector<WCHAR> buf(MAIN_WIN_MAX_PATH + 1);
40     OPENFILENAMEW ofnw;
41
42     memset(&ofnw, 0, sizeof(ofnw));
43     ofnw.lStructSize = sizeof(ofnw);
44     ofnw.hwndOwner = hWnd;
45     ofnw.lpstrFilter = L"HTML Files (*.html)\0*.html\0";
46     ofnw.nFilterIndex = 1;
47     ofnw.lpstrFile = &buf[0];
48     ofnw.nMaxFile = MAIN_WIN_MAX_PATH;
49     ofnw.lpstrDefExt = L"html";
50     ofnw.lpstrInitialDir = NULL;
51     ofnw.lpstrTitle = _(L"HTMLでスクリーンダンプを保存", L"Save screen dump as HTML.");
52     ofnw.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
53
54     if (GetSaveFileNameW(&ofnw)) {
55         do_cmd_save_screen_html_aux(to_multibyte(&buf[0]).c_str(), 0);
56     }
57 }
58
59 /*!
60  * @brief 対象ファイルを選択した状態でエクスプローラーを開く
61  * @param filename 対象ファイル
62  */
63 void open_dir_in_explorer(char *filename) {
64     std::string str = "/select," + std::string(filename);
65     ShellExecuteW(NULL, NULL, L"explorer.exe", to_wchar(str.c_str()).wc_str(), NULL, SW_SHOWNORMAL);
66 }