2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "platform/MessagePrinter.h"
11 #include "CompileInfo.h"
12 #include "rendering/dx/DeviceResources.h"
13 #include "rendering/dx/RenderContext.h"
14 #include "utils/log.h"
15 #include "windowing/win10/WinSystemWin10DX.h"
17 #include "platform/win32/CharsetConverter.h"
19 #include <winrt/Windows.ApplicationModel.Core.h>
20 #include <winrt/Windows.UI.Popups.h>
22 int WINAPI
MessageBox(void* hWnd
, const char* lpText
, const char* lpCaption
, UINT uType
)
24 using namespace winrt::Windows::ApplicationModel::Core
;
26 auto coreWindow
= CoreApplication::MainView().CoreWindow();
30 auto wText
= KODI::PLATFORM::WINDOWS::ToW(lpText
);
31 auto wCaption
= KODI::PLATFORM::WINDOWS::ToW(lpCaption
);
33 auto handler
= winrt::Windows::UI::Core::DispatchedHandler([wText
, wCaption
]()
35 // Show the message dialog
36 auto msg
= winrt::Windows::UI::Popups::MessageDialog(wText
, wCaption
);
37 // Set the command to be invoked when a user presses 'ESC'
38 msg
.CancelCommandIndex(1);
42 if (coreWindow
.Dispatcher().HasThreadAccess())
45 coreWindow
.Dispatcher().RunAsync(winrt::Windows::UI::Core::CoreDispatcherPriority::Normal
, handler
);
50 void CMessagePrinter::DisplayMessage(const std::string
& message
)
52 MessageBox(NULL
, message
.c_str(), CCompileInfo::GetAppName(), MB_OK
| MB_ICONINFORMATION
);
55 void CMessagePrinter::DisplayWarning(const std::string
& warning
)
57 MessageBox(NULL
, warning
.c_str(), CCompileInfo::GetAppName(), MB_OK
| MB_ICONWARNING
);
60 void CMessagePrinter::DisplayError(const std::string
& error
)
62 MessageBox(NULL
, error
.c_str(), CCompileInfo::GetAppName(), MB_OK
| MB_ICONERROR
);
65 void CMessagePrinter::DisplayHelpMessage(const std::vector
<std::pair
<std::string
, std::string
>>& help
)
67 //very crude implementation, pretty it up when possible
69 for (const auto& line
: help
)
71 message
.append(line
.first
+ "\t" + line
.second
+ "\r\n");
74 MessageBox(NULL
, message
.c_str(), CCompileInfo::GetAppName(), MB_OK
| MB_ICONINFORMATION
);