From 59f99ea9bb0af9429f2922b13e2d9f3b0fc83eb5 Mon Sep 17 00:00:00 2001 From: Mikhail Titov Date: Mon, 14 Mar 2016 14:02:32 -0500 Subject: [PATCH 1/2] Ask to minimize on Win32app close This closes #413 --- Config.cpp | 1 + Win32/Win32App.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Config.cpp b/Config.cpp index 15c8ad67..caec7e20 100644 --- a/Config.cpp +++ b/Config.cpp @@ -126,6 +126,7 @@ namespace config { #ifdef _WIN32 ("svcctl", value()->default_value(""), "Windows service management ('install' or 'remove')") ("insomnia", value()->zero_tokens()->default_value(false), "Prevent system from sleeping") + ("close", value()->default_value("ask"), "On close action") // minimize, exit, ask TODO: add custom validator or something #endif ; diff --git a/Win32/Win32App.cpp b/Win32/Win32App.cpp index cd9a8f34..269cc1ce 100644 --- a/Win32/Win32App.cpp +++ b/Win32/Win32App.cpp @@ -119,6 +119,29 @@ namespace win32 ShowWindow(hWnd, SW_HIDE); return 0; } + case SC_CLOSE: + { + std::string close; i2p::config::GetOption("close", close); + if (0 == close.compare("ask")) + switch(::MessageBox(hWnd, "Would you like to minimize instead of exiting?" + " You can add 'close' configuration option. Valid values are: ask, minimize, exit.", + "Minimize instead of exiting?", MB_ICONQUESTION | MB_YESNOCANCEL | MB_DEFBUTTON1)) + { + case IDYES: close = "minimize"; break; + case IDNO: close = "exit"; break; + default: return 0; + } + if (0 == close.compare("minimize")) + { + ShowWindow(hWnd, SW_HIDE); + return 0; + } + if (0 != close.compare("exit")) + { + ::MessageBox(hWnd, close.c_str(), "Unknown close action in config", MB_OK | MB_ICONWARNING); + return 0; + } + } } } case WM_TRAYICON: From 60befdb36e70ff5d831c2bfe7d4d19d932f250b3 Mon Sep 17 00:00:00 2001 From: Mikhail Titov Date: Mon, 14 Mar 2016 15:12:56 -0500 Subject: [PATCH 2/2] VS2013 snprintf compatibility --- Win32/Win32App.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Win32/Win32App.cpp b/Win32/Win32App.cpp index 269cc1ce..985d9eec 100644 --- a/Win32/Win32App.cpp +++ b/Win32/Win32App.cpp @@ -4,6 +4,11 @@ #include "../Config.h" #include "resource.h" #include "Win32App.h" +#include + +#if defined(_MSC_VER) && _MSC_VER < 1900 +#define snprintf _snprintf +#endif #define ID_ABOUT 2000 #define ID_EXIT 2001 @@ -98,7 +103,7 @@ namespace win32 char buf[30]; std::string httpAddr; i2p::config::GetOption("http.address", httpAddr); uint16_t httpPort; i2p::config::GetOption("http.port", httpPort); - std::snprintf(buf, 30, "http://%s:%d", httpAddr.c_str(), httpPort); + snprintf(buf, 30, "http://%s:%d", httpAddr.c_str(), httpPort); ShellExecute(NULL, "open", buf, NULL, NULL, SW_SHOWNORMAL); return 0; }