From d9547823e2e49f43dea3ebe80616cc46bd563db7 Mon Sep 17 00:00:00 2001 From: jerry Date: Mon, 19 Dec 2011 12:01:41 +0400 Subject: [PATCH 1/3] core hide-on-close implementation --- Console/MainFrame.cpp | 87 +++++++++++++++++++++---------------- Console/SettingsHandler.cpp | 4 ++ Console/SettingsHandler.h | 1 + 3 files changed, 54 insertions(+), 38 deletions(-) diff --git a/Console/MainFrame.cpp b/Console/MainFrame.cpp index 306740ff..7a285922 100644 --- a/Console/MainFrame.cpp +++ b/Console/MainFrame.cpp @@ -415,48 +415,17 @@ LRESULT MainFrame::OnEraseBkgnd(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lPara LRESULT MainFrame::OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) { - // save settings on exit - bool bSaveSettings = false; - ConsoleSettings& consoleSettings = g_settingsHandler->GetConsoleSettings(); - PositionSettings& positionSettings = g_settingsHandler->GetAppearanceSettings().positionSettings; - - if (consoleSettings.bSaveSize) - { - consoleSettings.dwRows = m_dwRows; - consoleSettings.dwColumns = m_dwColumns; - - bSaveSettings = true; - } - - if (positionSettings.bSavePosition) - { - CRect rectWindow; - - GetWindowRect(rectWindow); - - positionSettings.nX = rectWindow.left; - positionSettings.nY = rectWindow.top; - - bSaveSettings = true; - } - - if (bSaveSettings) g_settingsHandler->SaveSettings(); + StylesSettings& stylesSettings = g_settingsHandler->GetAppearanceSettings().stylesSettings; - // destroy all views - MutexLock viewMapLock(m_viewsMutex); - for (ConsoleViewMap::iterator it = m_views.begin(); it != m_views.end(); ++it) + if (stylesSettings.bHideOnClose) { - RemoveTab(it->second->m_hWnd); - if (m_activeView.get() == it->second.get()) m_activeView.reset(); - it->second->DestroyWindow(); + ShowWindow(SW_HIDE); + return 0; } - if (g_settingsHandler->GetAppearanceSettings().stylesSettings.bTrayIcon) SetTrayIcon(NIM_DELETE); - - UnregisterGlobalHotkeys(); + BOOL handled; - DestroyWindow(); - PostQuitMessage(0); + OnFileExit(0, 0, m_hWnd, handled); return 0; } @@ -1369,7 +1338,49 @@ LRESULT MainFrame::OnPrevTab(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl* LRESULT MainFrame::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { - PostMessage(WM_CLOSE); + // save settings on exit + bool bSaveSettings = false; + ConsoleSettings& consoleSettings = g_settingsHandler->GetConsoleSettings(); + PositionSettings& positionSettings = g_settingsHandler->GetAppearanceSettings().positionSettings; + StylesSettings& stylesSettings = g_settingsHandler->GetAppearanceSettings().stylesSettings; + + if (consoleSettings.bSaveSize) + { + consoleSettings.dwRows = m_dwRows; + consoleSettings.dwColumns = m_dwColumns; + + bSaveSettings = true; + } + + if (positionSettings.bSavePosition) + { + CRect rectWindow; + + GetWindowRect(rectWindow); + + positionSettings.nX = rectWindow.left; + positionSettings.nY = rectWindow.top; + + bSaveSettings = true; + } + + if (bSaveSettings) g_settingsHandler->SaveSettings(); + + // destroy all views + MutexLock viewMapLock(m_viewsMutex); + for (ConsoleViewMap::iterator it = m_views.begin(); it != m_views.end(); ++it) + { + RemoveTab(it->second->m_hWnd); + if (m_activeView.get() == it->second.get()) m_activeView.reset(); + it->second->DestroyWindow(); + } + + if (g_settingsHandler->GetAppearanceSettings().stylesSettings.bTrayIcon) SetTrayIcon(NIM_DELETE); + + UnregisterGlobalHotkeys(); + + DestroyWindow(); + PostQuitMessage(0); return 0; } diff --git a/Console/SettingsHandler.cpp b/Console/SettingsHandler.cpp index ed95c10a..c31aa1ba 100644 --- a/Console/SettingsHandler.cpp +++ b/Console/SettingsHandler.cpp @@ -458,6 +458,7 @@ StylesSettings::StylesSettings() , bBorder(true) , dwInsideBorder(2) , bTrayIcon(false) +, bHideOnClose(false) , crSelectionColor(RGB(255, 255, 255)) { } @@ -479,6 +480,7 @@ bool StylesSettings::Load(const CComPtr& pSettingsRoot) XmlHelper::GetAttribute(pStylesElement, CComBSTR(L"border"), bBorder, true); XmlHelper::GetAttribute(pStylesElement, CComBSTR(L"inside_border"), dwInsideBorder, 2); XmlHelper::GetAttribute(pStylesElement, CComBSTR(L"tray_icon"), bTrayIcon, false); + XmlHelper::GetAttribute(pStylesElement, CComBSTR(L"hide_on_close"), bHideOnClose, false); CComPtr pSelColorElement; @@ -506,6 +508,7 @@ bool StylesSettings::Save(const CComPtr& pSettingsRoot) XmlHelper::SetAttribute(pStylesElement, CComBSTR(L"border"), bBorder); XmlHelper::SetAttribute(pStylesElement, CComBSTR(L"inside_border"), dwInsideBorder); XmlHelper::SetAttribute(pStylesElement, CComBSTR(L"tray_icon"), bTrayIcon); + XmlHelper::SetAttribute(pStylesElement, CComBSTR(L"hide_on_close"), bHideOnClose); CComPtr pSelColorElement; @@ -529,6 +532,7 @@ StylesSettings& StylesSettings::operator=(const StylesSettings& other) bBorder = other.bBorder; dwInsideBorder = other.dwInsideBorder; bTrayIcon = other.bTrayIcon; + bHideOnClose = other.bHideOnClose; crSelectionColor= other.crSelectionColor; return *this; diff --git a/Console/SettingsHandler.h b/Console/SettingsHandler.h index 312ab9b5..6a47bec0 100644 --- a/Console/SettingsHandler.h +++ b/Console/SettingsHandler.h @@ -162,6 +162,7 @@ struct StylesSettings : public SettingsBase bool bBorder; DWORD dwInsideBorder; bool bTrayIcon; + bool bHideOnClose; COLORREF crSelectionColor; }; From 773c2e5d073f132347572acbb0cd3a04b8405205 Mon Sep 17 00:00:00 2001 From: jerry Date: Mon, 19 Dec 2011 12:05:15 +0400 Subject: [PATCH 2/3] hide-on-close GUI part --- Console/Console.rc | 1 + Console/DlgSettingsStyles.h | 1 + Console/resource.h | 1 + 3 files changed, 3 insertions(+) diff --git a/Console/Console.rc b/Console/Console.rc index f1a99011..f9dd8259 100644 --- a/Console/Console.rc +++ b/Console/Console.rc @@ -264,6 +264,7 @@ BEGIN LTEXT "Key col&or:",IDC_STATIC_KEY_COLOR,19,245,33,8 CONTROL "",IDC_KEY_COLOR,"Static",SS_BLACKFRAME | SS_NOTIFY,54,242,16,14,WS_EX_DLGMODALFRAME GROUPBOX "Window transparency",IDC_STATIC,0,111,226,154 + CONTROL "Hide on Close",IDC_CHECK_STYLE_HIDE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,154,35,59,10 END IDD_SETTINGS_TEMP DIALOGEX 0, 0, 611, 555 diff --git a/Console/DlgSettingsStyles.h b/Console/DlgSettingsStyles.h index 244faaf3..88cb1f95 100644 --- a/Console/DlgSettingsStyles.h +++ b/Console/DlgSettingsStyles.h @@ -34,6 +34,7 @@ class DlgSettingsStyles DDX_CHECK(IDC_CHECK_STYLE_BORDER, m_stylesSettings.bBorder) DDX_CHECK(IDC_CHECK_STYLE_TASKBAR, m_stylesSettings.bTaskbarButton) DDX_CHECK(IDC_CHECK_STYLE_TRAY, m_stylesSettings.bTrayIcon) + DDX_CHECK(IDC_CHECK_STYLE_HIDE, m_stylesSettings.bHideOnClose) DDX_UINT(IDC_INSIDE_BORDER, m_stylesSettings.dwInsideBorder) DDX_RADIO(IDC_TRANSPARENCY_TYPE, reinterpret_cast(m_transparencySettings.transType)) END_DDX_MAP() diff --git a/Console/resource.h b/Console/resource.h index e397a5c8..b7287795 100644 --- a/Console/resource.h +++ b/Console/resource.h @@ -322,6 +322,7 @@ #define ID_NEXT_TAB 2200 #define ID_PREV_TAB 2201 #define IDC_DUMP_BUFFER 3000 +#define IDC_CHECK_STYLE_HIDE 4321 #define IDS_ERR_CANT_START_SHELL 5000 #define IDS_ERR_CANT_START_AS_USER 5001 #define IDS_ERR_CANT_START_SHELL_AS_USER 5001 From d4eaae3ac0bac1dfd25ad18952295775045a9206 Mon Sep 17 00:00:00 2001 From: jerry Date: Mon, 19 Dec 2011 12:08:31 +0400 Subject: [PATCH 3/3] Global Activate/Deactivate behaviour --- Console/MainFrame.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Console/MainFrame.cpp b/Console/MainFrame.cpp index 7a285922..8f67c195 100644 --- a/Console/MainFrame.cpp +++ b/Console/MainFrame.cpp @@ -535,8 +535,16 @@ LRESULT MainFrame::OnHotKey(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOO { case IDC_GLOBAL_ACTIVATE : { - ShowWindow(SW_RESTORE); - PostMessage(WM_ACTIVATEAPP, TRUE, 0); + if (IsWindowVisible()) + { + ShowWindow(SW_HIDE); + PostMessage(WM_ACTIVATEAPP, FALSE, 0); + } + else + { + ShowWindow(SW_RESTORE); + PostMessage(WM_ACTIVATEAPP, TRUE, 0); + } POINT cursorPos; CRect windowRect;