From 0a08765d73660db671dff815b3b2ca20bb4a9667 Mon Sep 17 00:00:00 2001 From: Mikhail Titov Date: Mon, 14 Mar 2016 02:35:15 -0500 Subject: [PATCH] Win32: hide to tray, webconsole menu item Standard icon works for me on Windows 8 --- Win32/Resource.rc | 1 - Win32/Win32App.cpp | 51 +++++++++++++++++++++++++++++++++--------- Win32/ictoopie_16.ico | Bin 1150 -> 0 bytes Win32/resource.h | 2 +- build/CMakeLists.txt | 9 ++++++-- 5 files changed, 48 insertions(+), 15 deletions(-) delete mode 100644 Win32/ictoopie_16.ico diff --git a/Win32/Resource.rc b/Win32/Resource.rc index 56868181..e10ec496 100644 --- a/Win32/Resource.rc +++ b/Win32/Resource.rc @@ -53,7 +53,6 @@ END // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. MAINICON ICON "ictoopie.ico" -IDI_ICON1 ICON "ictoopie_16.ico" #endif // English (United States) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/Win32/Win32App.cpp b/Win32/Win32App.cpp index c997b266..cd9a8f34 100644 --- a/Win32/Win32App.cpp +++ b/Win32/Win32App.cpp @@ -1,12 +1,14 @@ #include #include #include -//#include "../Daemon.h" +#include "../Config.h" #include "resource.h" #include "Win32App.h" #define ID_ABOUT 2000 #define ID_EXIT 2001 +#define ID_CONSOLE 2002 +#define ID_APP 2003 #define ID_TRAY_ICON 2050 #define WM_TRAYICON (WM_USER + 1) @@ -18,10 +20,12 @@ namespace win32 static void ShowPopupMenu (HWND hWnd, POINT *curpos, int wDefaultItem) { HMENU hPopup = CreatePopupMenu(); - InsertMenu (hPopup, 0, MF_BYPOSITION | MF_STRING, ID_ABOUT, "About..."); - InsertMenu (hPopup, 1, MF_BYPOSITION | MF_STRING, ID_EXIT , "Exit"); - SetMenuDefaultItem (hPopup, ID_ABOUT, FALSE); - SetFocus (hWnd); + InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_CONSOLE, "Open &console"); + InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_APP, "Show app"); + InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_ABOUT, "&About..."); + InsertMenu (hPopup, -1, MF_BYPOSITION | MF_SEPARATOR, NULL, NULL); + InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_EXIT, "E&xit"); + SetMenuDefaultItem (hPopup, ID_CONSOLE, FALSE); SendMessage (hWnd, WM_INITMENUPOPUP, (WPARAM)hPopup, 0); POINT p; @@ -44,10 +48,11 @@ namespace win32 nid.cbSize = sizeof(nid); nid.hWnd = hWnd; nid.uID = ID_TRAY_ICON; - nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; + nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_INFO; nid.uCallbackMessage = WM_TRAYICON; - nid.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE (IDI_ICON1)); + nid.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE (MAINICON)); strcpy (nid.szTip, "i2pd"); + strcpy (nid.szInfo, "i2pd is running"); Shell_NotifyIcon(NIM_ADD, &nid ); } @@ -88,14 +93,39 @@ namespace win32 PostMessage (hWnd, WM_CLOSE, 0, 0); return 0; } + case ID_CONSOLE: + { + 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); + ShellExecute(NULL, "open", buf, NULL, NULL, SW_SHOWNORMAL); + return 0; + } + case ID_APP: + { + ShowWindow(hWnd, SW_SHOW); + return 0; + } } break; } + case WM_SYSCOMMAND: + { + switch (wParam) + { + case SC_MINIMIZE: + { + ShowWindow(hWnd, SW_HIDE); + return 0; + } + } + } case WM_TRAYICON: { - SetForegroundWindow (hWnd); switch (lParam) { + case WM_LBUTTONUP: case WM_RBUTTONUP: { SetForegroundWindow (hWnd); @@ -127,15 +157,14 @@ namespace win32 wclx.cbClsExtra = 0; wclx.cbWndExtra = 0; wclx.hInstance = hInst; - wclx.hIcon = LoadIcon (hInst, IDI_APPLICATION); - wclx.hIconSm = LoadIcon (hInst, IDI_APPLICATION); + wclx.hIcon = LoadIcon (hInst, MAKEINTRESOURCE(MAINICON)); wclx.hCursor = LoadCursor (NULL, IDC_ARROW); wclx.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); wclx.lpszMenuName = NULL; wclx.lpszClassName = I2PD_WIN32_CLASSNAME; RegisterClassEx (&wclx); // create new window - if (!CreateWindow(I2PD_WIN32_CLASSNAME, TEXT("i2pd"), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 250, 150, NULL, NULL, hInst, NULL)) + if (!CreateWindow(I2PD_WIN32_CLASSNAME, TEXT("i2pd"), WS_OVERLAPPEDWINDOW, 100, 100, 250, 150, NULL, NULL, hInst, NULL)) { MessageBox(NULL, "Failed to create main window", TEXT("Warning!"), MB_ICONERROR | MB_OK | MB_TOPMOST); return false; diff --git a/Win32/ictoopie_16.ico b/Win32/ictoopie_16.ico deleted file mode 100644 index 525646c351db354f366a1a912c0471c2b9c71193..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1150 zcmai!T`b#C7{*T#TEzN=i>1*qHY-|esLu|G>U>ngQj*z(8P;ve>U-2k%|^x$#V*u0 zTV$gm3o}eI*&^I-S+b8vwq&u%E)W-<{h5n@Y~ek5&ikDAyuXuka}FU4YOvXanuR3C ziV!D4$Z1MciK_gqQ;Eo^y`w^-(PVMC+)YQm<4>VbxF!~h*Zj}=uSuoS4TVC{d=y_@ zT^+|4@S#YLg?F$woL!s|c`*{sZqA_i-lKT2MBGziEQR^285La>2u}z{$6N>Wy?TiJ zM5|$;VaE?)db}Sw*ccFIpE(C7Jzhz}!eD)3fVjzw4tR?s`KCR$kTeuB?tm|fhf}@@Ees?2SZ4G&yg(7tfMk+^ zs5A2ADnq4`&QDKIGafYD=Lh*p+tXPZ6j@b)b>ktVK02rb<J~%pN+|sxR z?puKKlG4l$IFz>>`3ON!$jV?(w>7<=?kja#FZ-n2ZM)Zi?a(UNQ`=y_+JW8kU$B1z zuyXF)~LtmRZjRF^0+!AS=19M^n%*ic~=0!M!#lJ7eySDqRkBrKa zA_ti)A~!HO{he=O+ER*Itt+^myZbHt6YJD#+LH~H_ccr1P`|HrD(}`m)3nz|aa%5g F`~i^{J6iw% diff --git a/Win32/resource.h b/Win32/resource.h index 7bb73d38..a8309c8b 100644 --- a/Win32/resource.h +++ b/Win32/resource.h @@ -2,7 +2,7 @@ // Microsoft Visual C++ generated include file. // Used by Resource.rc // -#define IDI_ICON1 101 +#define MAINICON 101 // Next default values for new objects // diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index f863bd69..76963026 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -11,6 +11,7 @@ option(WITH_BINARY "Build binary" ON) option(WITH_STATIC "Static build" OFF) option(WITH_UPNP "Include support for UPnP client" OFF) option(WITH_PCH "Use precompiled header" OFF) +option(WITH_GUI "Include GUI (currently MS Windows only)" ON) # paths set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules" ) @@ -157,7 +158,11 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonLinux.cpp") elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR MSYS) list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonWin32.cpp") - list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/Win32/Win32App.cpp") + if (WITH_GUI) + list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/Win32/Win32App.cpp") + set_source_files_properties("${CMAKE_SOURCE_DIR}/DaemonWin32.cpp" + PROPERTIES COMPILE_DEFINITIONS WIN32_APP) + endif () list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/Win32/Win32Service.cpp") list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/Win32/Resource.rc") endif () @@ -310,7 +315,7 @@ include(GNUInstallDirs) if (WITH_BINARY) add_executable ( "${PROJECT_NAME}" ${DAEMON_SRC} ) - if (WIN32) + if (WIN32 AND WITH_GUI) set_target_properties("${PROJECT_NAME}" PROPERTIES WIN32_EXECUTABLE TRUE ) endif() if(NOT MSVC)