From 1f1b1d50f5ea1de76339740711aefe7d116099ba Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Thu, 30 Sep 2021 08:40:04 -0400 Subject: Initial work to allow building a DLL for embedding --- RadTerminal.cpp | 56 +++++++++++++++++++++- RadTerminal.sln | 25 +++++++--- RadTerminal.vcxproj | 1 + RadTerminalDll.vcxproj | 126 +++++++++++++++++++++++++++++++++++++++++++++++++ tsm.vcxproj | 2 +- 5 files changed, 201 insertions(+), 9 deletions(-) create mode 100644 RadTerminalDll.vcxproj diff --git a/RadTerminal.cpp b/RadTerminal.cpp index 0ab4de4..a53b238 100644 --- a/RadTerminal.cpp +++ b/RadTerminal.cpp @@ -8,6 +8,9 @@ #include "libtsm\src\tsm\libtsm.h" #include "libtsm\external\xkbcommon\xkbcommon-keysyms.h" #include "resource.h" +#include "RadTerminal.h" + +#define RADTERM_DEAD WM_USER+1 // TODO // https://stackoverflow.com/questions/5966903/how-to-get-mousemove-and-mouseclick-in-bash @@ -179,6 +182,43 @@ RadTerminalCreate GetTerminalCreate(bool bParseCmdLine, std::tstring profile) return rtc; } +#ifdef BUILD_AS_DLL +extern "C" { + + __declspec(dllexport) HWND WINAPI CreateTerminalWindow(HINSTANCE hInstance, HWND hParent, BOOL darkMode) + { + HWND hRet; + + RadTerminalCreate rtc = GetTerminalCreate(true, TEXT("")); + + if (darkMode) + InitDarkMode(); + + hRet = CreateWindowEx( + WS_EX_ACCEPTFILES, + MAKEINTATOM(GetRadTerminalAtom(hInstance)), + PROJ_NAME, + WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | WS_CLIPCHILDREN | WS_VSCROLL, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + hParent, // Parent window + NULL, // Menu + hInstance, + &rtc + ); + + if (darkMode) + { + SetWindowTheme(hRet, L"DarkMode_Explorer", NULL); // Needed for scrollbar + AllowDarkModeForWindow(hRet, true); + } + + return hRet; + } + +} /* extern "C" */ + +#else + int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE, PTSTR pCmdLine, int nCmdShow) { InitDarkMode(); @@ -257,6 +297,8 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE, PTSTR pCmdLine, int nCmdSho return EXIT_SUCCESS; } +#endif + template struct ThreadData2 { @@ -836,8 +878,10 @@ void RadTerminalWindowOnDestroy(HWND hWnd) tsm_vte_unref(data->vte); tsm_screen_unref(data->screen); +#ifndef BUILD_AS_DLL if (!IsMDIChild(hWnd) || CountChildWindows(GetParent(hWnd)) == 1) PostQuitMessage(0); +#endif delete data; SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) nullptr); @@ -1102,7 +1146,10 @@ int RadTerminalWindowOnMouseActivate(HWND hWnd, HWND hwndTopLevel, UINT codeHitT static HWND s_hWnd = NULL; // MDI Windows get a WM_MOUSE_ACTIVATE on every mouse click, not just the first to make it active if (s_hWnd != hWnd && result == MA_ACTIVATE && codeHitTest == HTCLIENT) { +#ifndef BUILD_AS_DLL s_hWnd = hWnd; +#endif + SetFocus(hWnd); return MA_ACTIVATEANDEAT; } return result; @@ -1152,12 +1199,13 @@ void RadTerminalWindowOnRButtonDown(HWND hWnd, BOOL fDoubleClick, int x, int y, void RadTerminalWindowOnTimer(HWND hWnd, UINT id) { const RadTerminalData* const data = (RadTerminalData*) GetWindowLongPtr(hWnd, GWLP_USERDATA); + switch (id) { case 2: { - HWND hActive = MyGetActiveWnd(hWnd); - if (hActive == hWnd) + //HWND hActive = MyGetActiveWnd(hWnd); + if (GetFocus() == hWnd) { HDC hdc = GetDC(hWnd); DrawCursor(hdc, data); @@ -1303,7 +1351,11 @@ LRESULT RadTerminalWindowOnWatch(HWND hWnd, WPARAM wParam, LPARAM lParam) HANDLE h = (HANDLE) wParam; if (h == data->spd.pi.hProcess) { +#ifdef BUILD_AS_DLL + SendMessage(GetParent(hWnd), RADTERM_DEAD, (WPARAM)0, (LPARAM)hWnd); +#else PostMessage(hWnd, WM_CLOSE, 0, 0); +#endif } return 0; } diff --git a/RadTerminal.sln b/RadTerminal.sln index 045b096..73c27fb 100644 --- a/RadTerminal.sln +++ b/RadTerminal.sln @@ -1,11 +1,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31702.278 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RadTerminal", "RadTerminal.vcxproj", "{5660720B-5A4B-4F82-85C3-AE789F685218}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tsm", "tsm.vcxproj", "{F7508F50-F42C-4091-A87E-227FFE89C038}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RadTerminalDll", "RadTerminalDll.vcxproj", "{72CD6B5C-8F7C-449E-87AC-399A0674FE5B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -14,24 +16,35 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5660720B-5A4B-4F82-85C3-AE789F685218}.Debug|x64.ActiveCfg = Debug|x64 - {5660720B-5A4B-4F82-85C3-AE789F685218}.Debug|x64.Build.0 = Debug|x64 + {5660720B-5A4B-4F82-85C3-AE789F685218}.Debug|x64.ActiveCfg = Debug|Win32 + {5660720B-5A4B-4F82-85C3-AE789F685218}.Debug|x64.Build.0 = Debug|Win32 {5660720B-5A4B-4F82-85C3-AE789F685218}.Debug|x86.ActiveCfg = Debug|Win32 {5660720B-5A4B-4F82-85C3-AE789F685218}.Debug|x86.Build.0 = Debug|Win32 {5660720B-5A4B-4F82-85C3-AE789F685218}.Release|x64.ActiveCfg = Release|x64 {5660720B-5A4B-4F82-85C3-AE789F685218}.Release|x64.Build.0 = Release|x64 {5660720B-5A4B-4F82-85C3-AE789F685218}.Release|x86.ActiveCfg = Release|Win32 {5660720B-5A4B-4F82-85C3-AE789F685218}.Release|x86.Build.0 = Release|Win32 - {F7508F50-F42C-4091-A87E-227FFE89C038}.Debug|x64.ActiveCfg = Debug|x64 - {F7508F50-F42C-4091-A87E-227FFE89C038}.Debug|x64.Build.0 = Debug|x64 + {F7508F50-F42C-4091-A87E-227FFE89C038}.Debug|x64.ActiveCfg = Debug|Win32 + {F7508F50-F42C-4091-A87E-227FFE89C038}.Debug|x64.Build.0 = Debug|Win32 {F7508F50-F42C-4091-A87E-227FFE89C038}.Debug|x86.ActiveCfg = Debug|Win32 {F7508F50-F42C-4091-A87E-227FFE89C038}.Debug|x86.Build.0 = Debug|Win32 {F7508F50-F42C-4091-A87E-227FFE89C038}.Release|x64.ActiveCfg = Release|x64 {F7508F50-F42C-4091-A87E-227FFE89C038}.Release|x64.Build.0 = Release|x64 {F7508F50-F42C-4091-A87E-227FFE89C038}.Release|x86.ActiveCfg = Release|Win32 {F7508F50-F42C-4091-A87E-227FFE89C038}.Release|x86.Build.0 = Release|Win32 + {72CD6B5C-8F7C-449E-87AC-399A0674FE5B}.Debug|x64.ActiveCfg = Debug|x64 + {72CD6B5C-8F7C-449E-87AC-399A0674FE5B}.Debug|x64.Build.0 = Debug|x64 + {72CD6B5C-8F7C-449E-87AC-399A0674FE5B}.Debug|x86.ActiveCfg = Debug|Win32 + {72CD6B5C-8F7C-449E-87AC-399A0674FE5B}.Debug|x86.Build.0 = Debug|Win32 + {72CD6B5C-8F7C-449E-87AC-399A0674FE5B}.Release|x64.ActiveCfg = Release|x64 + {72CD6B5C-8F7C-449E-87AC-399A0674FE5B}.Release|x64.Build.0 = Release|x64 + {72CD6B5C-8F7C-449E-87AC-399A0674FE5B}.Release|x86.ActiveCfg = Release|Win32 + {72CD6B5C-8F7C-449E-87AC-399A0674FE5B}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E4EC1B55-6BA7-4358-99FE-A52E530A44E1} + EndGlobalSection EndGlobal diff --git a/RadTerminal.vcxproj b/RadTerminal.vcxproj index 1d1df6f..6d0eb95 100644 --- a/RadTerminal.vcxproj +++ b/RadTerminal.vcxproj @@ -111,6 +111,7 @@ + diff --git a/RadTerminalDll.vcxproj b/RadTerminalDll.vcxproj new file mode 100644 index 0000000..cfb481d --- /dev/null +++ b/RadTerminalDll.vcxproj @@ -0,0 +1,126 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {72CD6B5C-8F7C-449E-87AC-399A0674FE5B} + Win32Proj + RadTerminal + 10.0 + + + + DynamicLibrary + v142 + Unicode + + + true + + + false + true + + + + + + + + + + + + $(SolutionDir)Bin\$(Platform)$(Configuration)\ + Int\$(Platform)$(Configuration)\$(ProjectName)\ + + + true + + + false + + + + Level3 + _WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + + + + + WIN32;%(PreprocessorDefinitions) + + + + + Disabled + _DEBUG;%(PreprocessorDefinitions);BUILD_AS_DLL + + + true + kernel32.lib;user32.lib;gdi32.lib;uxtheme.lib;dwmapi.lib;%(AdditionalDependencies) + kernel32.lib;user32.lib;gdi32.lib;uxtheme.lib;dwmapi.lib;%(AdditionalDependencies) + + + + + MaxSpeed + true + true + NDEBUG;%(PreprocessorDefinitions) + + + true + true + true + kernel32.lib;user32.lib;gdi32.lib;uxtheme.lib;dwmapi.lib;%(AdditionalDependencies) + kernel32.lib;user32.lib;gdi32.lib;uxtheme.lib;dwmapi.lib;%(AdditionalDependencies) + + + + + + + + + + {f7508f50-f42c-4091-a87e-227ffe89c038} + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tsm.vcxproj b/tsm.vcxproj index 62fb229..4fee17f 100644 --- a/tsm.vcxproj +++ b/tsm.vcxproj @@ -58,7 +58,7 @@ Unicode - StaticLibrary + DynamicLibrary true v142 Unicode -- cgit v1.2.3