diff --git a/main.c b/main.c index 0505855..5263e08 100644 --- a/main.c +++ b/main.c @@ -357,6 +357,8 @@ StopAllOpenVPN() { int i; + RemoveTrayIcon(); + /* Stop all connections started by us -- we leave persistent ones * at their current state. Use the disconnect menu to put them into * hold state before exit, if desired. @@ -849,6 +851,8 @@ ShowSettingsDialog() void CloseApplication(HWND hwnd, BOOL ask_user) { + /* Do not let user access main menu through tray icon */ + RemoveTrayIcon(); /* Show a message if any non-persistent connections are active */ for (connection_t *c = o.chead; c && ask_user; c = c->next) { @@ -861,6 +865,9 @@ CloseApplication(HWND hwnd, BOOL ask_user) /* Ask for confirmation if still connected */ if (ShowLocalizedMsgEx(MB_YESNO|MB_TOPMOST, o.hWnd, _T("Exit OpenVPN"), IDS_NFO_ACTIVE_CONN_EXIT) == IDNO) { + /* recreate the tray icon */ + ShowTrayIcon(); + CheckAndSetTrayIcon(); return; } break; /* show the above message box only once */ diff --git a/tray.c b/tray.c index dd0a21b..f1b9c81 100644 --- a/tray.c +++ b/tray.c @@ -388,15 +388,23 @@ OnNotifyTray(LPARAM lParam) } } +void +RemoveTrayIcon() +{ + if (ni.hWnd) + { + Shell_NotifyIcon(NIM_DELETE, &ni); + CLEAR(ni); + } +} void OnDestroyTray() { DestroyMenu(hMenu); - Shell_NotifyIcon(NIM_DELETE, &ni); + RemoveTrayIcon(); } - void ShowTrayIcon() { diff --git a/tray.h b/tray.h index b6f5a94..3f4e69b 100644 --- a/tray.h +++ b/tray.h @@ -50,6 +50,7 @@ void CreatePopupMenus(); void OnNotifyTray(LPARAM); void OnDestroyTray(void); void ShowTrayIcon(); +void RemoveTrayIcon(); void SetTrayIcon(conn_state_t); void SetMenuStatus(connection_t *, conn_state_t); void SetServiceMenuStatus();