From 449469111740c20b31be05a1ef08c282a558597f Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Fri, 18 Sep 2020 22:54:38 -0600 Subject: [PATCH] add visual extension --- .gitignore | 5 +- ExampleExtension.sln | 14 +- ExampleExtension/CMakeLists.txt | 1 + ExampleExtension/ExampleExtension.vcxproj | 4 +- .../ExampleVisualExtension.vcxproj | 161 ++++++++++++++++++ .../ExampleVisualExtension.vcxproj.filters | 26 +++ ExampleExtension/VisualExtension.cpp | 83 +++++++++ 7 files changed, 290 insertions(+), 4 deletions(-) create mode 100644 ExampleExtension/ExampleVisualExtension.vcxproj create mode 100644 ExampleExtension/ExampleVisualExtension.vcxproj.filters create mode 100644 ExampleExtension/VisualExtension.cpp diff --git a/.gitignore b/.gitignore index 3c4efe2..aeedfb7 100644 --- a/.gitignore +++ b/.gitignore @@ -258,4 +258,7 @@ paket-files/ # Python Tools for Visual Studio (PTVS) __pycache__/ -*.pyc \ No newline at end of file +*.pyc + +# CMake output +**/out/** \ No newline at end of file diff --git a/ExampleExtension.sln b/ExampleExtension.sln index 9ccb724..ee0215b 100644 --- a/ExampleExtension.sln +++ b/ExampleExtension.sln @@ -1,10 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27703.2018 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30406.217 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ExampleExtension", "ExampleExtension\ExampleExtension.vcxproj", "{577FDFFF-CBC8-4889-BC1C-27267DF3367A}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ExampleVisualExtension", "ExampleExtension\ExampleVisualExtension.vcxproj", "{55D08EC5-DC85-4C01-8768-33B1DE95C5FC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -21,6 +23,14 @@ Global {577FDFFF-CBC8-4889-BC1C-27267DF3367A}.Release|x64.Build.0 = Release|x64 {577FDFFF-CBC8-4889-BC1C-27267DF3367A}.Release|x86.ActiveCfg = Release|Win32 {577FDFFF-CBC8-4889-BC1C-27267DF3367A}.Release|x86.Build.0 = Release|Win32 + {55D08EC5-DC85-4C01-8768-33B1DE95C5FC}.Debug|x64.ActiveCfg = Debug|x64 + {55D08EC5-DC85-4C01-8768-33B1DE95C5FC}.Debug|x64.Build.0 = Debug|x64 + {55D08EC5-DC85-4C01-8768-33B1DE95C5FC}.Debug|x86.ActiveCfg = Debug|Win32 + {55D08EC5-DC85-4C01-8768-33B1DE95C5FC}.Debug|x86.Build.0 = Debug|Win32 + {55D08EC5-DC85-4C01-8768-33B1DE95C5FC}.Release|x64.ActiveCfg = Release|x64 + {55D08EC5-DC85-4C01-8768-33B1DE95C5FC}.Release|x64.Build.0 = Release|x64 + {55D08EC5-DC85-4C01-8768-33B1DE95C5FC}.Release|x86.ActiveCfg = Release|Win32 + {55D08EC5-DC85-4C01-8768-33B1DE95C5FC}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ExampleExtension/CMakeLists.txt b/ExampleExtension/CMakeLists.txt index 1044957..4c55923 100644 --- a/ExampleExtension/CMakeLists.txt +++ b/ExampleExtension/CMakeLists.txt @@ -3,3 +3,4 @@ cmake_minimum_required(VERSION 3.5) cmake_policy(SET CMP0037 OLD) add_library(Example\ Extension SHARED Extension.cpp ExtensionImpl.cpp) +add_library(Example\ Visual\ Extension SHARED VisualExtension.cpp ExtensionImpl.cpp) diff --git a/ExampleExtension/ExampleExtension.vcxproj b/ExampleExtension/ExampleExtension.vcxproj index 009f0c8..56a1cba 100644 --- a/ExampleExtension/ExampleExtension.vcxproj +++ b/ExampleExtension/ExampleExtension.vcxproj @@ -23,7 +23,7 @@ {577FDFFF-CBC8-4889-BC1C-27267DF3367A} Win32Proj ExampleExtension - 10.0.17134.0 + 10.0 @@ -75,12 +75,14 @@ true + $(ProjectName)\$(Platform)\$(Configuration)\ false false + $(ProjectName)\$(Platform)\$(Configuration)\ diff --git a/ExampleExtension/ExampleVisualExtension.vcxproj b/ExampleExtension/ExampleVisualExtension.vcxproj new file mode 100644 index 0000000..7960aa6 --- /dev/null +++ b/ExampleExtension/ExampleVisualExtension.vcxproj @@ -0,0 +1,161 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {55D08EC5-DC85-4C01-8768-33B1DE95C5FC} + Win32Proj + ExampleExtension + 10.0 + + + + DynamicLibrary + true + v141 + Unicode + + + DynamicLibrary + false + v141 + true + Unicode + + + DynamicLibrary + true + v141 + Unicode + + + DynamicLibrary + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + $(ProjectName)\$(Platform)\$(Configuration)\ + + + false + + + false + $(ProjectName)\$(Platform)\$(Configuration)\ + + + + NotUsing + Level3 + Disabled + true + WIN32;_DEBUG;EXAMPLEEXTENSION_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + NotUsing + Level3 + Disabled + true + _DEBUG;EXAMPLEEXTENSION_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + NotUsing + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;EXAMPLEEXTENSION_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + NotUsing + Level3 + MaxSpeed + true + true + true + NDEBUG;EXAMPLEEXTENSION_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/ExampleExtension/ExampleVisualExtension.vcxproj.filters b/ExampleExtension/ExampleVisualExtension.vcxproj.filters new file mode 100644 index 0000000..37c2724 --- /dev/null +++ b/ExampleExtension/ExampleVisualExtension.vcxproj.filters @@ -0,0 +1,26 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + + + Source Files + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/ExampleExtension/VisualExtension.cpp b/ExampleExtension/VisualExtension.cpp new file mode 100644 index 0000000..476d1d9 --- /dev/null +++ b/ExampleExtension/VisualExtension.cpp @@ -0,0 +1,83 @@ +#include "extension.h" +#include + +HWND hWnd; +std::mutex m; +std::wstring currentSentence = L"Waiting..."; + +BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + { + WNDCLASSEXW wcex = {}; + wcex.cbSize = sizeof(WNDCLASSEX); + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hInstance = hModule; + wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + wcex.lpszClassName = L"Extra Window"; + wcex.lpfnWndProc = [](HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -> LRESULT + { + switch (message) + { + case WM_PAINT: + { + PAINTSTRUCT ps; + HDC hdc = BeginPaint(hWnd, &ps); + RECT wndRect; + GetWindowRect(hWnd, &wndRect); + RECT rect = { 0, 0, wndRect.right - wndRect.left, wndRect.bottom - wndRect.top }; + FillRect(hdc, &rect, (HBRUSH)(COLOR_WINDOW + 1)); + std::lock_guard lock(m); + DrawTextW(hdc, currentSentence.c_str(), -1, &rect, DT_WORDBREAK); + EndPaint(hWnd, &ps); + return 0; + } + default: + { + return DefWindowProcW(hWnd, message, wParam, lParam); + } + } + }; + RegisterClassExW(&wcex); + + hWnd = CreateWindowExW( + WS_EX_TOPMOST, + L"Extra Window", + L"Example Visual Extension", + WS_THICKFRAME, + CW_USEDEFAULT, + 0, + CW_USEDEFAULT, + 0, + FindWindowW(NULL, L"Textractor") /*NULL*/, + NULL, + hModule, + nullptr + ); + if (!hWnd) throw; + ShowWindow(hWnd, SW_SHOWNORMAL); + UpdateWindow(hWnd); + } + break; + case DLL_PROCESS_DETACH: + { + DestroyWindow(hWnd); + } + break; + } + return TRUE; +} + +bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) +{ + if (sentenceInfo["current select"]) + { + std::lock_guard lock(m); + currentSentence = sentence; + InvalidateRect(hWnd, nullptr, FALSE); // Force window repaint + } + return false; +}