LIBURANIA
GUI library (a wrapper of Win32 API) in C++
読み取り中…
検索中…
一致する文字列を見つけられません
system.h
[詳解]
1/*
2 * Copyright 2001-2021 oZ/acy (名賀月晃嗣)
3 * Redistribution and use in source and binary forms,
4 * with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
50#ifndef INCLUDE_GUARD_URANIA_SYSTEM_H
51#define INCLUDE_GUARD_URANIA_SYSTEM_H
52
53// windows.hのmin/maxマクロの抑止
54#ifndef NOMINMAX
55#define NOMINMAX
56#endif
57
58#include <windows.h>
59#include <string>
60#include <vector>
61#include "decl.h"
62
63
68{
69 friend class urania::WndBase;
70 friend class urania::Menu;
71
72private:
73 static HINSTANCE hi_S;
74
75private:
76 System() =delete; //インスタンス生成禁止
77
78public:
81 static void start(HINSTANCE hi)
82 {
83 hi_S = hi;
84 }
85
93 static void quit(int r)
94 {
95 ::PostQuitMessage(r);
96 }
97
105 static int messageLoop();
106
120 template<class Func_> static int messageLoop(Func_ f);
121
122
123 // メッセージボックス系
124
131 static void alert(const std::wstring& title, const std::wstring& msg)
132 {
133 ::MessageBox(NULL, msg.c_str(), title.c_str(), MB_OK | MB_ICONEXCLAMATION);
134 }
135
142 static void notify(const std::wstring& title, const std::wstring& msg)
143 {
144 ::MessageBox(NULL, msg.c_str(), title.c_str(), MB_OK);
145 }
146
154 static int askYesNoCancel(const std::wstring& title, const std::wstring& msg)
155 {
156 int res = ::MessageBox(NULL, msg.c_str(), title.c_str(), MB_YESNOCANCEL);
157 switch(res)
158 {
159 case IDYES:
160 return 1;
161 case IDNO:
162 return 0;
163 case IDCANCEL:
164 return 2;
165 default:
166 return 2; // キャンセル
167 }
168 }
169
177 static bool askYesNo(const std::wstring& title, const std::wstring& msg)
178 {
179 int res = ::MessageBox(NULL, msg.c_str(), title.c_str(), MB_YESNO);
180 if (res == IDYES)
181 return true;
182 else
183 return false;
184 }
185
186
187 // カーソル系
191 static void showCursor()
192 {
193 ::ShowCursor(TRUE);
194 }
198 static void hideCursor()
199 {
200 ::ShowCursor(FALSE);
201 }
202
204 static std::wstring getLongPathName(const std::wstring& path);
205
206 // コマンドライン引數を取得する。
207 // 廢用
208 //static std::vector<std::string> getCmdLineArgs();
209
210
212 static std::vector<std::wstring> getCmdLineArgsW();
213
216 static std::vector<std::wstring> getCmdLineArgsW(const wchar_t* cmdline);
217
218 // ワイド文字列・マルチバイト文字列變換 (Win32API使用)
220 static std::string strcpyWideToMultiByte(const std::wstring& ws);
222 static std::wstring strcpyMultiByteToWide(const std::string& ws);
223
224
226 static int getDesktopWidth()
227 {
228 RECT rc;
229 ::GetWindowRect(NULL, &rc);
230 return rc.right - rc.left;
231 }
232
234 static int getDesktopHeight()
235 {
236 RECT rc;
237 ::GetWindowRect(NULL, &rc);
238 return rc.bottom - rc.top;
239 }
240};
241
242
243
244
245template<class Func_>
246inline
248{
249 MSG msg;
250 bool idle = true;
251
252 for (;;) {
253 if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
254 if (msg.message == WM_QUIT) {
255 return msg.wParam;
256 //舊
257 //::PostQuitMessage(0);
258 //return;
259 }
260
261 ::TranslateMessage(&msg);
262 ::DispatchMessage(&msg);
263
264 idle = true;
265 }
266 else if (idle) {
267 if (!f())
268 idle = false;
269 }
270 else {
271 ::WaitMessage();
272 }
273 }
274
275 return -1; //到達不能の筈だが念の爲
276}
277
278
279
280
281#endif // INCLUDE_GUARD_URANIA_SYSTEM_H
メニューハンドル(HMENU)のラッパー
Definition menu.h:134
Definition system.h:68
static std::string strcpyWideToMultiByte(const std::wstring &ws)
ワイド文字列からマルチバイト文字列への變換
Definition sys-ws2mbs.cpp:41
static int getDesktopHeight()
デスクトップの高さの取得
Definition system.h:234
static bool askYesNo(const std::wstring &title, const std::wstring &msg)
二擇メッセージボックス
Definition system.h:177
static std::wstring getLongPathName(const std::wstring &path)
「長いファイル名」の取得
Definition getLongPath.cpp:43
static void alert(const std::wstring &title, const std::wstring &msg)
警告メッセージボックス
Definition system.h:131
static void start(HINSTANCE hi)
Definition system.h:81
static int askYesNoCancel(const std::wstring &title, const std::wstring &msg)
三擇メッセージボックス
Definition system.h:154
static void quit(int r)
終了指令
Definition system.h:93
static int getDesktopWidth()
デスクトップの幅の取得
Definition system.h:226
static int messageLoop()
メッセージループ
Definition msgloop.cpp:41
static std::vector< std::wstring > getCmdLineArgsW()
コマンドライン引數の取得
Definition getCLArgsW.cpp:45
static void showCursor()
カーソル表示化
Definition system.h:191
static void hideCursor()
カーソル非表示化
Definition system.h:198
static std::wstring strcpyMultiByteToWide(const std::string &ws)
マルチバイト文字列からワイド文字列への變換
Definition sys-mbs2ws.cpp:39
static void notify(const std::wstring &title, const std::wstring &msg)
通知用メッセージボックス
Definition system.h:142
HWND管理用基底クラス
Definition wbase.h:55
各種宣言