[windows] add binding exceptions messagebox notifications, update exceptions handling code

Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
R4SAS 2020-05-05 02:36:34 +03:00
parent d991cc3b96
commit 42d4781a96
No known key found for this signature in database
GPG key ID: 66F6C87B98EBCFE2
9 changed files with 160 additions and 97 deletions

View file

@ -23,6 +23,11 @@
#include <syslog.h>
#endif
#ifdef WIN32_APP
#include <windows.h>
#include "Win32/Win32App.h"
#endif
enum LogLevel
{
eLogNone = 0,
@ -197,4 +202,42 @@ void LogPrint (LogLevel level, TArgs&&... args) noexcept
log.Append(msg);
}
#ifdef WIN32_APP
/**
* @brief Show message box for user with message in it
* @param level Message level (eLogError, eLogInfo, ...)
* @param args Array of message parts
*/
template<typename... TArgs>
void ShowMessageBox (LogLevel level, TArgs&&... args) noexcept
{
// fold message to single string
std::stringstream ss("");
#if (__cplusplus >= 201703L) // C++ 17 or higher
(LogPrint (ss, std::forward<TArgs>(args)), ...);
#else
LogPrint (ss, std::forward<TArgs>(args)...);
#endif
HWND hWnd = FindWindow (I2PD_WIN32_CLASSNAME, TEXT("i2pd"));
if (!hWnd) hWnd = NULL;
UINT uType;
switch (level) {
case eLogError :
case eLogWarning :
uType = MB_ICONWARNING;
break;
case eLogNone :
case eLogInfo :
case eLogDebug :
default :
uType = MB_ICONINFORMATION;
break;
}
MessageBox( hWnd, TEXT(ss.str ().c_str ()), TEXT("i2pd"), uType | MB_TASKMODAL | MB_OK );
}
#endif // WIN32_APP
#endif // LOG_H__