diff options
author | RadAd <adamgates84+github@gmail.com> | 2019-07-16 13:49:10 +1000 |
---|---|---|
committer | RadAd <adamgates84+github@gmail.com> | 2019-07-16 13:49:10 +1000 |
commit | 0b1db49d64bd4f50bc5bbd8e456566c77d492e11 (patch) | |
tree | 02295853ce10833d72ca3b5cbd3aef193531e50c | |
parent | b40b190dfdb50acd2cbb2108e92c3d4b0d7f3bfe (diff) | |
download | RadTerminal-0b1db49d64bd4f50bc5bbd8e456566c77d492e11.tar.gz RadTerminal-0b1db49d64bd4f50bc5bbd8e456566c77d492e11.zip |
Close frame on last child window close
-rw-r--r-- | RadTerminal.cpp | 62 | ||||
-rw-r--r-- | RadTerminal.rc | bin | 7322 -> 8744 bytes | |||
-rw-r--r-- | RadTerminalFrame.cpp | 5 | ||||
-rw-r--r-- | WinUtils.h | 14 | ||||
-rw-r--r-- | resource.h | bin | 3458 -> 3458 bytes |
5 files changed, 52 insertions, 29 deletions
diff --git a/RadTerminal.cpp b/RadTerminal.cpp index 7121dfc..1beaad1 100644 --- a/RadTerminal.cpp +++ b/RadTerminal.cpp @@ -32,6 +32,7 @@ #define PROJ_NAME TEXT("RadTerminal") #define PROJ_CODE TEXT("RadTerminal") +#define REG_BASE TEXT("Software\\RadSoft\\") PROJ_CODE template <class T> bool MemEqual(const T& a, const T& b) @@ -103,7 +104,7 @@ struct RadTerminalCreate void LoadRegistry(RadTerminalCreate& rtc, LPCWSTR strSubKey) { HKEY hMainKey = NULL; - if (RegOpenKey(HKEY_CURRENT_USER, _T("Software\\RadSoft\\" PROJ_CODE "\\Profiles"), &hMainKey) == ERROR_SUCCESS) + if (RegOpenKey(HKEY_CURRENT_USER, REG_BASE TEXT("\\Profiles"), &hMainKey) == ERROR_SUCCESS) { HKEY hKey = NULL; if (RegOpenKey(hMainKey, strSubKey, &hKey) == ERROR_SUCCESS) @@ -157,7 +158,7 @@ void ParseCommandLine(RadTerminalCreate& rtc) RadTerminalCreate GetTerminalCreate(bool bParseCmdLine, std::tstring profile) { if (profile.empty()) - profile = RegGetString(HKEY_CURRENT_USER, _T("Software\\RadSoft\\" PROJ_CODE), _T("Profile"), _T("Cmd")); + profile = RegGetString(HKEY_CURRENT_USER, REG_BASE, TEXT("Profile"), TEXT("Cmd")); RadTerminalCreate rtc = {}; rtc.iFontHeight = 16; @@ -183,7 +184,7 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE, PTSTR pCmdLine, int nCmdSho HWND hWnd = NULL; HWND hWndMDIClient = NULL; HACCEL hAccel = NULL; - bool bMDI = RegGetDWORD(HKEY_CURRENT_USER, _T("Software\\RadSoft\\" PROJ_CODE), _T("MDI"), TRUE) > 0; + bool bMDI = RegGetDWORD(HKEY_CURRENT_USER, REG_BASE, TEXT("MDI"), TRUE) > 0; CHECK(GetRadTerminalAtom(hInstance), EXIT_FAILURE); @@ -811,10 +812,11 @@ void RadTerminalWindowOnDestroy(HWND hWnd) tsm_vte_unref(data->vte); tsm_screen_unref(data->screen); + if (!IsMDIChild(hWnd) || CountChildWindows(GetParent(hWnd)) == 1) + PostQuitMessage(0); + delete data; SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) nullptr); - if (!IsMDIChild(hWnd)) - PostQuitMessage(0); } void RadTerminalWindowOnPaint(HWND hWnd) @@ -1240,6 +1242,32 @@ void RadTerminalWindowOnCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify } } +LRESULT RadTerminalWindowOnWatch(HWND hWnd, WPARAM wParam, LPARAM lParam) +{ + const RadTerminalData* const data = (RadTerminalData*) GetWindowLongPtr(hWnd, GWLP_USERDATA); + HANDLE h = (HANDLE) wParam; + if (h == data->spd.pi.hProcess) + { + PostMessage(hWnd, WM_CLOSE, 0, 0); + } + return 0; +} + +LRESULT RadTerminalWindowOnRead(HWND hWnd, WPARAM wParam, LPARAM lParam) +{ + const RadTerminalData* const data = (RadTerminalData*) GetWindowLongPtr(hWnd, GWLP_USERDATA); + const char* buf = (const char*) wParam; + DWORD len = (DWORD) lParam; + tsm_vte_input(data->vte, buf, len); + FixScrollbar(hWnd); + InvalidateRect(hWnd, nullptr, TRUE); + return 0; +} + +/* LRESULT Cls_StdMessage(HWND hWnd, WPARAM wParam, LPARAM lParam) */ +#define HANDLE_STD_MSG(hwnd, message, fn) \ + case (message): return fn((hwnd), (wParam), (lParam)) + LRESULT CALLBACK RadTerminalWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { //return MyDefWindowProc(hWnd, uMsg, wParam, lParam); @@ -1260,28 +1288,8 @@ LRESULT CALLBACK RadTerminalWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR HANDLE_MSG(hWnd, WM_VSCROLL, RadTerminalWindowOnVScroll); HANDLE_MSG(hWnd, WM_DROPFILES, RadTerminalWindowOnDropFiles); HANDLE_MSG(hWnd, WM_COMMAND, RadTerminalWindowOnCommand); - case WM_WATCH: - { - const RadTerminalData* const data = (RadTerminalData*) GetWindowLongPtr(hWnd, GWLP_USERDATA); - HANDLE h = (HANDLE) wParam; - if (h == data->spd.pi.hProcess) - { - PostMessage(hWnd, WM_CLOSE, 0, 0); - } - return 0; - } - break; - case WM_READ: - { - const RadTerminalData* const data = (RadTerminalData*) GetWindowLongPtr(hWnd, GWLP_USERDATA); - const char* buf = (const char*) wParam; - DWORD len = (DWORD) lParam; - tsm_vte_input(data->vte, buf, len); - FixScrollbar(hWnd); - InvalidateRect(hWnd, nullptr, TRUE); - return 0; - } - break; + HANDLE_STD_MSG(hWnd, WM_WATCH, RadTerminalWindowOnWatch); + HANDLE_STD_MSG(hWnd, WM_READ, RadTerminalWindowOnRead); default: return MyDefWindowProc(hWnd, uMsg, wParam, lParam); } } diff --git a/RadTerminal.rc b/RadTerminal.rc Binary files differindex 4b6b09a..83cc31d 100644 --- a/RadTerminal.rc +++ b/RadTerminal.rc diff --git a/RadTerminalFrame.cpp b/RadTerminalFrame.cpp index 84a0789..f58c2d7 100644 --- a/RadTerminalFrame.cpp +++ b/RadTerminalFrame.cpp @@ -6,6 +6,7 @@ #define PROJ_NAME TEXT("RadTerminal") #define PROJ_CODE TEXT("RadTerminal") +#define REG_BASE TEXT("Software\\RadSoft\\") PROJ_CODE HWND ActionNewWindow(HWND hWnd, bool bParseCmdLine, const std::tstring& profile); LRESULT CALLBACK RadTerminalMDIFrameProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -66,9 +67,9 @@ BOOL RadTerminalFrameOnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct) { HKEY hMainKey = NULL; - if (RegOpenKey(HKEY_CURRENT_USER, TEXT("Software\\RadSoft\\" PROJ_CODE "\\Profiles"), &hMainKey) == ERROR_SUCCESS) + if (RegOpenKey(HKEY_CURRENT_USER, REG_BASE TEXT("\\Profiles"), &hMainKey) == ERROR_SUCCESS) { - const std::tstring strDefault = RegGetString(HKEY_CURRENT_USER, TEXT("Software\\RadSoft\\" PROJ_CODE), TEXT("Profile"), TEXT("Cmd")); + const std::tstring strDefault = RegGetString(HKEY_CURRENT_USER, REG_BASE, TEXT("Profile"), TEXT("Cmd")); DWORD i = 0; std::tstring strName; for (int i = 0; RegEnumKeyEx(hMainKey, i, strName); ++i) @@ -202,3 +202,17 @@ inline bool FindMenuPos(HMENU hBaseMenu, UINT myID, HMENU* pMenu, int* mpos) return false; } + +inline BOOL CALLBACK CountChildWindowsProc(HWND, LPARAM lParam) +{ + int* pCount = (int*) lParam; + ++(*pCount); + return TRUE; +} + +inline int CountChildWindows(HWND hWnd) +{ + int count = 0; + EnumChildWindows(hWnd, CountChildWindowsProc, (LPARAM) &count); + return count; +} Binary files differ |