This commit is contained in:
恍兮惚兮 2024-11-15 03:53:55 +08:00
parent 09c0ffc54b
commit 15e5315e83
2 changed files with 20 additions and 5 deletions

View File

@ -1,3 +1,5 @@
#ifndef WINXP
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Storage.Pickers.h>
#include <winrt/Windows.Storage.Streams.h>
@ -25,8 +27,10 @@ using namespace Windows::Media::Devices;
using namespace Windows::Security::Cryptography;
using namespace Windows::Globalization;
using namespace Windows::Foundation::Collections;
#endif
DECLARE_API bool check_language_valid(wchar_t *language)
{
#ifndef WINXP
OcrEngine ocrEngine = OcrEngine::TryCreateFromUserProfileLanguages();
std::wstring l = language;
try
@ -38,20 +42,26 @@ DECLARE_API bool check_language_valid(wchar_t *language)
{
return false;
}
#else
return false;
#endif
}
DECLARE_API void getlanguagelist(void(*cb)(LPCWSTR))
DECLARE_API void getlanguagelist(void (*cb)(LPCWSTR))
{
#ifndef WINXP
OcrEngine ocrEngine = OcrEngine::TryCreateFromUserProfileLanguages();
auto languages = ocrEngine.AvailableRecognizerLanguages();
for (auto &&language : languages)
{
auto lang = language.LanguageTag();
cb(lang.c_str());
}
#endif
}
DECLARE_API void OCR(void *ptr, size_t size, wchar_t *lang, wchar_t *space, void (*cb)(int, int, int, int, LPCWSTR))
{
#ifndef WINXP
IBuffer buffer = CryptographicBuffer::CreateFromByteArray(
winrt::array_view<uint8_t>(static_cast<uint8_t *>(ptr), size));
InMemoryRandomAccessStream memoryStream;
@ -82,7 +92,7 @@ DECLARE_API void OCR(void *ptr, size_t size, wchar_t *lang, wchar_t *space, void
y1 = std::min((unsigned int)rect.Y, y1);
y2 = std::max(y2, (unsigned int)(rect.Y + rect.Height));
}
cb(x1,y1,x2,y2,xx.c_str());
cb(x1, y1, x2, y2, xx.c_str());
}
#endif
}

View File

@ -1,4 +1,6 @@
#include <dxgi.h>

#ifndef WINXP
#include <dxgi.h>
#include <inspectable.h>
#include <dxgi1_2.h>
#include <d3d11.h>
@ -203,8 +205,10 @@ void capture_window(HWND window_handle, void (*cb)(byte *, size_t))
memcpy(ptr, p_buf.get(), l_bmp_info.bmiHeader.biSizeImage);
cb(p_buf2.get(), bmfh.bfSize);
}
#endif
DECLARE_API void winrt_capture_window(HWND hwnd, void (*cb)(byte *, size_t))
{
#ifndef WINXP
// auto hwnd = GetForegroundWindow();// FindWindow(L"Window_Magpie_967EB565-6F73-4E94-AE53-00CC42592A22", 0);
auto style_ex = GetWindowLong(hwnd, GWL_EXSTYLE);
auto style_ex_save = style_ex;
@ -220,4 +224,5 @@ DECLARE_API void winrt_capture_window(HWND hwnd, void (*cb)(byte *, size_t))
capture_window(hwnd, cb);
if (needset)
SetWindowLong(hwnd, GWL_EXSTYLE, style_ex_save);
#endif
}