aboutsummaryrefslogtreecommitdiff
path: root/RadTerminalFrame.cpp
diff options
context:
space:
mode:
authorRadAd <adamgates84+github@gmail.com>2019-07-16 12:05:52 +1000
committerRadAd <adamgates84+github@gmail.com>2019-07-16 12:05:52 +1000
commitb40b190dfdb50acd2cbb2108e92c3d4b0d7f3bfe (patch)
tree863869d3a959b5fed0e430da9dc75a184f9e491f /RadTerminalFrame.cpp
parenta1dd103887ff7e6b6881716da495b4e57ed754c0 (diff)
downloadRadTerminal-b40b190dfdb50acd2cbb2108e92c3d4b0d7f3bfe.tar.gz
RadTerminal-b40b190dfdb50acd2cbb2108e92c3d4b0d7f3bfe.zip
Support multiple profiles
Diffstat (limited to 'RadTerminalFrame.cpp')
-rw-r--r--RadTerminalFrame.cpp54
1 files changed, 50 insertions, 4 deletions
diff --git a/RadTerminalFrame.cpp b/RadTerminalFrame.cpp
index 1d2aeff..84a0789 100644
--- a/RadTerminalFrame.cpp
+++ b/RadTerminalFrame.cpp
@@ -1,11 +1,13 @@
#include <windows.h>
#include <windowsx.h>
+#include <vector>
#include "WinUtils.h"
#include "resource.h"
#define PROJ_NAME TEXT("RadTerminal")
+#define PROJ_CODE TEXT("RadTerminal")
-HWND ActionNewWindow(HWND hWnd, bool bParseCmdLine);
+HWND ActionNewWindow(HWND hWnd, bool bParseCmdLine, const std::tstring& profile);
LRESULT CALLBACK RadTerminalMDIFrameProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
HWND CreateRadTerminalFrame(HINSTANCE hInstance)
@@ -44,16 +46,52 @@ inline LRESULT MyDefFrameWindowProc(_In_ HWND hWnd, _In_ UINT Msg, _In_ WPARAM w
return DefFrameProc(hWnd, GetMDIClient(hWnd), Msg, wParam, lParam);
}
+struct RadTerminalFrameData
+{
+ std::vector<std::tstring> profiles;
+};
+
BOOL RadTerminalFrameOnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct)
{
FORWARD_WM_CREATE(hWnd, lpCreateStruct, MyDefFrameWindowProc);
- HINSTANCE hInst = GetWindowInstance(hWnd);
+ const HINSTANCE hInst = GetWindowInstance(hWnd);
+
+ RadTerminalFrameData* const data = new RadTerminalFrameData;
+ SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) data);
CLIENTCREATESTRUCT ccs = {};
HMENU hMenu = GetMenu(hWnd);
ccs.hWindowMenu = GetSubMenu(hMenu, GetMenuItemCount(hMenu) - 1);
ccs.idFirstChild = IDM_WINDOWCHILD;
+ {
+ HKEY hMainKey = NULL;
+ if (RegOpenKey(HKEY_CURRENT_USER, TEXT("Software\\RadSoft\\" PROJ_CODE "\\Profiles"), &hMainKey) == ERROR_SUCCESS)
+ {
+ const std::tstring strDefault = RegGetString(HKEY_CURRENT_USER, TEXT("Software\\RadSoft\\" PROJ_CODE), TEXT("Profile"), TEXT("Cmd"));
+ DWORD i = 0;
+ std::tstring strName;
+ for (int i = 0; RegEnumKeyEx(hMainKey, i, strName); ++i)
+ {
+ data->profiles.push_back(strName);
+ if (strName != TEXT("Default"))
+ {
+ MENUITEMINFO mii = {};
+ mii.cbSize = sizeof(mii);
+ mii.fMask = MIIM_ID | MIIM_STRING | MIIM_STATE;
+ mii.fType = MFT_STRING;
+ if (strName == strDefault)
+ mii.fState |= MFS_DEFAULT;
+ mii.wID = ID_NEW_PROFILE_1 + i;
+ mii.dwTypeData = (LPTSTR) strName.c_str();
+ InsertMenuItem(hMenu, ID_NEW_PLACEHOLDER, FALSE, &mii);
+ }
+ }
+ DeleteMenu(hMenu, ID_NEW_PLACEHOLDER, MF_BYCOMMAND);
+ RegCloseKey(hMainKey);
+ }
+ }
+
HWND hWndMDIClient = CreateWindow(TEXT("MDICLIENT"), (LPCTSTR) NULL,
WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
0, 0, 0, 0, hWnd, (HMENU) 0, hInst, (LPSTR) &ccs);
@@ -68,7 +106,10 @@ BOOL RadTerminalFrameOnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct)
void RadTerminalFrameOnDestroy(HWND hWnd)
{
FORWARD_WM_DESTROY(hWnd, MyDefFrameWindowProc);
+ const RadTerminalFrameData* const data = (RadTerminalFrameData*) GetWindowLongPtr(hWnd, GWLP_USERDATA);
PostQuitMessage(0);
+ delete data;
+ SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) nullptr);
}
void RadTerminalFrameOnSizing(HWND hWnd, UINT edge, LPRECT prRect)
@@ -87,11 +128,16 @@ void RadTerminalFrameOnSizing(HWND hWnd, UINT edge, LPRECT prRect)
void RadTerminalFrameOnCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify)
{
- HWND hWndMDIClient = GetMDIClient(hWnd);
+ const HWND hWndMDIClient = GetMDIClient(hWnd);
+ const RadTerminalFrameData* const data = (RadTerminalFrameData*) GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (id)
{
- case ID_FILE_NEW: ActionNewWindow(hWnd, false); break;
+ case ID_FILE_NEW: ActionNewWindow(hWnd, false, TEXT("")); break;
+ case ID_NEW_PROFILE_1: case ID_NEW_PROFILE_2: case ID_NEW_PROFILE_3:
+ case ID_NEW_PROFILE_4: case ID_NEW_PROFILE_5: case ID_NEW_PROFILE_6:
+ case ID_NEW_PROFILE_7: case ID_NEW_PROFILE_8: case ID_NEW_PROFILE_9:
+ ActionNewWindow(hWnd, false, data->profiles[id - ID_NEW_PROFILE_1]); break;
case ID_FILE_EXIT: PostMessage(hWnd, WM_CLOSE, 0, 0); break;
case ID_WINDOW_CASCADE: CascadeWindows(hWndMDIClient, 0, nullptr, 0, nullptr); break;
case ID_WINDOW_TILEHORIZONTALLY: TileWindows(hWndMDIClient, MDITILE_HORIZONTAL, nullptr, 0, nullptr); break;