diff options
author | RadAd <adamgates84+github@gmail.com> | 2019-05-27 15:24:32 +1000 |
---|---|---|
committer | RadAd <adamgates84+github@gmail.com> | 2019-05-27 15:24:32 +1000 |
commit | d78ed540055c4b5ea56b3a79f67d0d62c3c35286 (patch) | |
tree | fc8ea17cdb857bbeec89fb817fc6a2c1b9ef716d | |
parent | d8d149ab25fcc57f794c0c4cbc7fa6f43e26289c (diff) | |
download | RadTerminal-d78ed540055c4b5ea56b3a79f67d0d62c3c35286.tar.gz RadTerminal-d78ed540055c4b5ea56b3a79f67d0d62c3c35286.zip |
Get defaults form registry
-rw-r--r-- | RadTerminal.cpp | 81 | ||||
-rw-r--r-- | RadTerminal.reg | bin | 0 -> 486 bytes | |||
-rw-r--r-- | WinUtils.h | 38 |
3 files changed, 89 insertions, 30 deletions
diff --git a/RadTerminal.cpp b/RadTerminal.cpp index dec0b31..f4140c1 100644 --- a/RadTerminal.cpp +++ b/RadTerminal.cpp @@ -34,6 +34,7 @@ #endif #define PROJ_NAME TEXT("RadTerminal") +#define PROJ_CODE TEXT("RadTerminal") template <class T> bool MemEqual(const T& a, const T& b) @@ -72,38 +73,31 @@ LRESULT CALLBACK RadTerminalWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR struct RadTerminalCreate { int iFontHeight; - LPTSTR strFontFace; - LPTSTR strScheme; + std::tstring strFontFace; + std::tstring strScheme; COORD szCon; int sb; std::tstring strCmd; }; -int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE, PTSTR pCmdLine, int nCmdShow) +void LoadRegistry(RadTerminalCreate& rtc) { - HWND hWnd = NULL; - - WNDCLASS wc = {}; - - wc.lpfnWndProc = RadTerminalWindowProc; - wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - //wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW); - wc.hInstance = hInstance; - wc.lpszClassName = TEXT("RadTerminal"); - - ATOM atom = NULL; - CHECK(atom = RegisterClass(&wc), EXIT_FAILURE); - - RadTerminalCreate rtc = {}; - rtc.iFontHeight = 16; - rtc.strFontFace = _T("Consolas"); - //rtc.strScheme = _T("solarized"); - rtc.szCon = { 80, 25 }; - rtc.sb = 1000; - //rtc.strCmd = _T("%COMSPEC%"); - rtc.strCmd = _T("cmd"); + HKEY hKey = NULL; + if (RegOpenKey(HKEY_CURRENT_USER, _T("Software\\RadSoft\\" PROJ_CODE), &hKey) == ERROR_SUCCESS) + { + rtc.iFontHeight = RegGetDWORD(hKey, _T("FontSize"), rtc.iFontHeight); + rtc.strFontFace = RegGetString(hKey, _T("FontFace"), rtc.strFontFace); + rtc.strScheme = RegGetString(hKey, _T("Scheme"), rtc.strScheme); + rtc.szCon.X = (SHORT) RegGetDWORD(hKey, _T("Width"), rtc.szCon.X); + rtc.szCon.Y = (SHORT) RegGetDWORD(hKey, _T("Height"), rtc.szCon.Y); + rtc.sb = RegGetDWORD(hKey, _T("Scrollback"), rtc.sb); + + RegCloseKey(hKey); + } +} +void ParseCommandLine(RadTerminalCreate& rtc) +{ bool command = false; for (int i = 1; i < __argc; ++i) { @@ -131,6 +125,35 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE, PTSTR pCmdLine, int nCmdSho command = true; } } +} + +int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE, PTSTR pCmdLine, int nCmdShow) +{ + HWND hWnd = NULL; + + WNDCLASS wc = {}; + + wc.lpfnWndProc = RadTerminalWindowProc; + wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + //wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW); + wc.hInstance = hInstance; + wc.lpszClassName = PROJ_CODE; + + ATOM atom = NULL; + CHECK(atom = RegisterClass(&wc), EXIT_FAILURE); + + RadTerminalCreate rtc = {}; + rtc.iFontHeight = 16; + rtc.strFontFace = _T("Consolas"); + //rtc.strScheme = _T("solarized"); + rtc.szCon = { 80, 25 }; + rtc.sb = 1000; + //rtc.strCmd = _T("%COMSPEC%"); + rtc.strCmd = _T("cmd"); + + LoadRegistry(rtc); + ParseCommandLine(rtc); HWND hChildWnd = CreateWindowEx( 0, @@ -560,21 +583,21 @@ BOOL RadTerminalWindowOnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct) tsm_screen_set_max_sb(data->screen, rtc->sb); e = tsm_vte_new(&data->vte, data->screen, tsm_vte_write, data->spd.hInput, tsm_log, nullptr); tsm_vte_set_osc_cb(data->vte, tsm_vte_osc, hWnd); - if (rtc->strScheme != nullptr) + if (!rtc->strScheme.empty()) { #ifdef _UNICODE char scheme[1024]; - WideCharToMultiByte(CP_UTF8, 0, rtc->strScheme, -1, scheme, ARRAYSIZE(scheme), nullptr, nullptr); + WideCharToMultiByte(CP_UTF8, 0, rtc->strScheme.c_str(), -1, scheme, ARRAYSIZE(scheme), nullptr, nullptr); e = tsm_vte_set_palette(data->vte, scheme); #else - e = tsm_vte_set_palette(data->vte, rtc->strScheme); + e = tsm_vte_set_palette(data->vte, rtc->strScheme.c_str()); #endif } for (int b = 0; b < 2; ++b) for (int i = 0; i < 2; ++i) for (int u = 0; u < 2; ++u) - CHECK(data->draw_info.hFonts[b][i][u] = CreateFont(rtc->strFontFace, rtc->iFontHeight, b == 0 ? FW_NORMAL : FW_BOLD, i, u), FALSE); + CHECK(data->draw_info.hFonts[b][i][u] = CreateFont(rtc->strFontFace.c_str(), rtc->iFontHeight, b == 0 ? FW_NORMAL : FW_BOLD, i, u), FALSE); HDC hdc = GetDC(hWnd); SelectFont(hdc, data->draw_info.hFonts[0][0][0]); diff --git a/RadTerminal.reg b/RadTerminal.reg Binary files differnew file mode 100644 index 0000000..8b83f12 --- /dev/null +++ b/RadTerminal.reg @@ -46,9 +46,45 @@ inline RECT Rect(POINT p1, SIZE s2) return { p1.x, p1.y, p1.x + s2.cx, p1.y + s2.cy }; } -inline HFONT CreateFont(LPTSTR pFontFace, int iFontHeight, int cWeight, BOOL bItalic, BOOL bUnderline) +inline HFONT CreateFont(LPCTSTR pFontFace, int iFontHeight, int cWeight, BOOL bItalic, BOOL bUnderline) { return CreateFont(iFontHeight, 0, 0, 0, cWeight, bItalic, bUnderline, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, pFontFace); } + +std::string RegGetString(HKEY hKey, LPCSTR sValue, const std::string& strDef) +{ + CHAR buf[1024]; + DWORD len = (ARRAYSIZE(buf) - 1) * sizeof(CHAR); + if (RegGetValueA(hKey, nullptr, sValue, RRF_RT_REG_SZ, nullptr, buf, &len) == ERROR_SUCCESS) + { + buf[len / sizeof(CHAR)] = _T('\0'); + return buf; + } + else + return strDef; +} + +std::wstring RegGetString(HKEY hKey, LPCWSTR sValue, const std::wstring& strDef) +{ + WCHAR buf[1024]; + DWORD len = (ARRAYSIZE(buf) - 1) * sizeof(WCHAR); + if (RegGetValueW(hKey, nullptr, sValue, RRF_RT_REG_SZ, nullptr, buf, &len) == ERROR_SUCCESS) + { + buf[len / sizeof(WCHAR)] = _T('\0'); + return buf; + } + else + return strDef; +} + +DWORD RegGetDWORD(HKEY hKey, LPCTSTR sValue, DWORD dwDef) +{ + DWORD data = 0; + DWORD len = sizeof(data); + if (RegGetValue(hKey, nullptr, sValue, RRF_RT_REG_DWORD, nullptr, &data, &len) == ERROR_SUCCESS) + return data; + else + return dwDef; +} |