From 4f62c52b49479fb5b9e9e6607fe5d49088c87ae0 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Fri, 26 May 2023 10:08:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BA=94=E7=94=A8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=97=B6=E6=9C=AA=E9=87=8A=E6=94=BE=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sane/scanner.cpp | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/sane/scanner.cpp b/sane/scanner.cpp index 179f285..4a4e7c8 100644 --- a/sane/scanner.cpp +++ b/sane/scanner.cpp @@ -345,11 +345,12 @@ namespace callback // SANE_EVENT_IMAGE_OK - void* unused, be NULL, flag - unused, be 0 static HMODULE hui = NULL; int (*choose_scanner)(const std::vector& devs) = NULL; // blocked. return selected DEVQUE::id or -1 if user cancelled - int (*apply_current_config)(const char* dev_name, SANE_Handle device, LPSANEAPI api) = NULL; // 应用设备的当前配�? + char* (*apply_current_config)(const char* dev_name, SANE_Handle device, LPSANEAPI api) = NULL; // 应用设备的当前配�? int (*show_setting_ui)(SANE_Handle device, HWND parent, LPSANEAPI api, const char* devname, bool with_scan, std::function callback) = NULL; int (*show_progress_ui)(HWND parent, std::function callback, std::function* notify) = NULL; int (*show_messagebox_ui)(HWND parent, int event, void* msg, int flag) = NULL; int (*close_ui)(int) = NULL; + void (*twain_ui_free)(void* buf) = NULL; static void init_ui(void) @@ -380,6 +381,7 @@ namespace callback GET_API(show_progress_ui); GET_API(show_messagebox_ui); GET_API(close_ui); + GET_API(twain_ui_free); } } static void unint_ui(void) @@ -392,12 +394,39 @@ namespace callback show_progress_ui = NULL; show_messagebox_ui = NULL; close_ui = NULL; + twain_ui_free = NULL; if (hui) { FreeLibrary(hui); hui = NULL; } } + + + // check thread whether has window + static BOOL WINAPI check_window(HWND hwnd, LPARAM lp) + { + LPDWORD id = (LPDWORD)lp; + + if (GetWindowThreadProcessId(hwnd, NULL) == id[0]) + { + id[1] = 1; + + return FALSE; + } + + return TRUE; + } + static bool is_thread_has_window(DWORD thread_id = -1) + { + if (thread_id == -1) + thread_id = GetCurrentThreadId(); + + DWORD param[] = { thread_id, 0 }; + EnumWindows(check_window, (LPARAM)param); + + return param[1]; + } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -717,7 +746,11 @@ void scanner::save_config(const wchar_t* file) void scanner::apply_config(void) { if (callback::apply_current_config) - callback::apply_current_config(local_trans::u2a(scanner_name_.c_str(), CP_UTF8).c_str(), handle_, &sane_api_); + { + char* cfg = callback::apply_current_config(local_trans::u2a(scanner_name_.c_str(), CP_UTF8).c_str(), handle_, &sane_api_); + if (cfg && callback::twain_ui_free) + callback::twain_ui_free(cfg); + } else if (cfg_) { gb::sane_config_schm* schm = cfg_->get_scheme();