FCT
载入中...
搜索中...
未找到
Utils.cpp
浏览该文件的文档.
1#include "Utils.h"
2namespace FCT
3{
4#ifdef _WIN32
5 std::wstring stringToWString(const std::string& str) {
6 if (str.empty()) return std::wstring();
7
8 int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
9 std::wstring wstrTo(size_needed, 0);
10 MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed);
11 return wstrTo;
12 }
13#endif
14
15 void ShowErrorDialog(const std::string& title, const std::string& message) {
16#ifdef _WIN32
17 std::wstring wTitle = stringToWString(title);
18 std::wstring wMessage = stringToWString(message);
19 MessageBoxW(nullptr, wMessage.c_str(), wTitle.c_str(), MB_OK | MB_ICONERROR);
20#else
21 std::cerr << "[ERROR] " << title << ": " << message << std::endl;
22#endif
23 }
24
25 void ShowWarningDialog(const std::string& title, const std::string& message) {
26#ifdef _WIN32
27 std::wstring wTitle = stringToWString(title);
28 std::wstring wMessage = stringToWString(message);
29 MessageBoxW(nullptr, wMessage.c_str(), wTitle.c_str(), MB_OK | MB_ICONWARNING);
30#else
31 std::cerr << "[WARNING] " << title << ": " << message << std::endl;
32#endif
33 }
34
35 bool ShowConfirmDialog(const std::string& title, const std::string& message) {
36#ifdef _WIN32
37 std::wstring wTitle = stringToWString(title);
38 std::wstring wMessage = stringToWString(message);
39 int result = MessageBoxW(nullptr, wMessage.c_str(), wTitle.c_str(), MB_YESNO | MB_ICONQUESTION);
40 return result == IDYES;
41#else
42 std::cout << "[CONFIRM] " << title << ": " << message << " (y/n): ";
43 char response;
44 std::cin >> response;
45 return response == 'y' || response == 'Y';
46#endif
47 }
48
49 void ShowInfoDialog(const std::string& title, const std::string& message) {
50#ifdef _WIN32
51 std::wstring wTitle = stringToWString(title);
52 std::wstring wMessage = stringToWString(message);
53 MessageBoxW(nullptr, wMessage.c_str(), wTitle.c_str(), MB_OK | MB_ICONINFORMATION);
54#else
55 std::cout << "[INFO] " << title << ": " << message << std::endl;
56#endif
57 }
58}
void ShowErrorDialog(const std::string &title, const std::string &message)
显示错误对话框
bool ShowConfirmDialog(const std::string &title, const std::string &message)
显示确认对话框
void ShowInfoDialog(const std::string &title, const std::string &message)
显示信息对话框
void ShowWarningDialog(const std::string &title, const std::string &message)
显示警告对话框