diff --git a/cmd/synergyc/CMSWindowsClientTaskBarReceiver.cpp b/cmd/synergyc/CMSWindowsClientTaskBarReceiver.cpp index 689cc307..f328a233 100644 --- a/cmd/synergyc/CMSWindowsClientTaskBarReceiver.cpp +++ b/cmd/synergyc/CMSWindowsClientTaskBarReceiver.cpp @@ -58,6 +58,12 @@ CMSWindowsClientTaskBarReceiver::CMSWindowsClientTaskBarReceiver( } CMSWindowsClientTaskBarReceiver::~CMSWindowsClientTaskBarReceiver() +{ + cleanup(); +} + +void +CMSWindowsClientTaskBarReceiver::cleanup() { ARCH->removeReceiver(this); for (UInt32 i = 0; i < kMaxState; ++i) { diff --git a/cmd/synergyc/CMSWindowsClientTaskBarReceiver.h b/cmd/synergyc/CMSWindowsClientTaskBarReceiver.h index 72d33be5..5c4d9cdf 100644 --- a/cmd/synergyc/CMSWindowsClientTaskBarReceiver.h +++ b/cmd/synergyc/CMSWindowsClientTaskBarReceiver.h @@ -33,6 +33,7 @@ public: virtual void runMenu(int x, int y); virtual void primaryAction(); virtual const Icon getIcon() const; + void cleanup(); protected: void copyLog() const; diff --git a/cmd/synergys/CMSWindowsServerTaskBarReceiver.cpp b/cmd/synergys/CMSWindowsServerTaskBarReceiver.cpp index 97ba1a36..00126806 100644 --- a/cmd/synergys/CMSWindowsServerTaskBarReceiver.cpp +++ b/cmd/synergys/CMSWindowsServerTaskBarReceiver.cpp @@ -57,7 +57,8 @@ CMSWindowsServerTaskBarReceiver::CMSWindowsServerTaskBarReceiver( ARCH->addReceiver(this); } -CMSWindowsServerTaskBarReceiver::~CMSWindowsServerTaskBarReceiver() +void +CMSWindowsServerTaskBarReceiver::cleanup() { ARCH->removeReceiver(this); for (UInt32 i = 0; i < kMaxState; ++i) { @@ -67,6 +68,11 @@ CMSWindowsServerTaskBarReceiver::~CMSWindowsServerTaskBarReceiver() destroyWindow(); } +CMSWindowsServerTaskBarReceiver::~CMSWindowsServerTaskBarReceiver() +{ + cleanup(); +} + void CMSWindowsServerTaskBarReceiver::showStatus() { diff --git a/cmd/synergys/CMSWindowsServerTaskBarReceiver.h b/cmd/synergys/CMSWindowsServerTaskBarReceiver.h index ab679077..22decc8d 100644 --- a/cmd/synergys/CMSWindowsServerTaskBarReceiver.h +++ b/cmd/synergys/CMSWindowsServerTaskBarReceiver.h @@ -33,6 +33,7 @@ public: virtual void runMenu(int x, int y); virtual void primaryAction(); virtual const Icon getIcon() const; + void cleanup(); protected: void copyLog() const; diff --git a/lib/arch/CArchAppUtilWindows.cpp b/lib/arch/CArchAppUtilWindows.cpp index 06089a07..f2bbf49b 100644 --- a/lib/arch/CArchAppUtilWindows.cpp +++ b/lib/arch/CArchAppUtilWindows.cpp @@ -21,6 +21,7 @@ #include "LogOutputters.h" #include "CMSWindowsScreen.h" #include "XSynergy.h" +#include "IArchTaskBarReceiver.h" #include #include @@ -29,12 +30,27 @@ CArchAppUtilWindows::CArchAppUtilWindows() : m_exitMode(kExitModeNormal) { + if (SetConsoleCtrlHandler((PHANDLER_ROUTINE)consoleHandler, TRUE) == FALSE) + { + throw XArchEvalWindows(); + } } CArchAppUtilWindows::~CArchAppUtilWindows() { } +BOOL WINAPI CArchAppUtilWindows::consoleHandler(DWORD CEvent) +{ + // HACK: it would be nice to delete the s_taskBarReceiver object, but + // this is best done by the CApp destructor; however i don't feel like + // opening up that can of worms today... i need sleep. + instance().app().s_taskBarReceiver->cleanup(); + + ExitProcess(kExitTerminated); + return TRUE; +} + bool CArchAppUtilWindows::parseArg(const int& argc, const char* const* argv, int& i) { diff --git a/lib/arch/CArchAppUtilWindows.h b/lib/arch/CArchAppUtilWindows.h index b4dc3d52..d6618ab8 100644 --- a/lib/arch/CArchAppUtilWindows.h +++ b/lib/arch/CArchAppUtilWindows.h @@ -17,6 +17,7 @@ #include "CArchAppUtil.h" #include "CString.h" +#define WIN32_LEAN_AND_MEAN #include "Windows.h" #define ARCH_APPUTIL CArchAppUtilWindows @@ -65,4 +66,5 @@ public: private: AppExitMode m_exitMode; + static BOOL WINAPI consoleHandler(DWORD CEvent); }; diff --git a/lib/arch/IArchTaskBarReceiver.h b/lib/arch/IArchTaskBarReceiver.h index e0dd9bff..9f6730d6 100644 --- a/lib/arch/IArchTaskBarReceiver.h +++ b/lib/arch/IArchTaskBarReceiver.h @@ -89,6 +89,8 @@ public: virtual void updateStatus(INode*, const CString& errorMsg) = 0; + virtual void cleanup() {} + //@} }; diff --git a/lib/synergy/CClientTaskBarReceiver.h b/lib/synergy/CClientTaskBarReceiver.h index 92f4b352..5d2d6a87 100644 --- a/lib/synergy/CClientTaskBarReceiver.h +++ b/lib/synergy/CClientTaskBarReceiver.h @@ -47,6 +47,7 @@ public: virtual void unlock() const; virtual const Icon getIcon() const = 0; virtual std::string getToolTip() const; + virtual void cleanup() {} protected: enum EState {