fix bug-740: 为消息框查找父窗口时,通过配置([twain-app]check-main-wnd-thread-id=0/1)决定是否需要同一线程,默认不检查。A+程序强制检查。
This commit is contained in:
parent
c838a6dc47
commit
ef545cca20
|
@ -241,13 +241,16 @@ namespace callback
|
|||
return "";
|
||||
}
|
||||
|
||||
static bool check_wnd_thread_id = false;
|
||||
static BOOL CALLBACK main_wnd(HWND hwnd, LPARAM param)
|
||||
{
|
||||
DWORD pid = 0;
|
||||
DWORD pid = 0,
|
||||
tid = GetWindowThreadProcessId(hwnd, &pid);
|
||||
|
||||
GetWindowThreadProcessId(hwnd, &pid);
|
||||
if (pid != GetCurrentProcessId())
|
||||
return TRUE;
|
||||
if (check_wnd_thread_id && tid != GetCurrentThreadId())
|
||||
return TRUE;
|
||||
|
||||
if (((void**)param)[1] == NULL)
|
||||
{
|
||||
|
@ -293,6 +296,11 @@ namespace callback
|
|||
HWND wnd[2] = { NULL };
|
||||
|
||||
EnumWindows(main_wnd, (LPARAM)wnd);
|
||||
{
|
||||
wchar_t mw[128] = { 0 };
|
||||
swprintf_s(mw, _countof(mw) - 1, L"find_main_wnd of thread %u = 0x%x\r\n", GetCurrentThreadId(), wnd[0]);
|
||||
log_info(mw, 1);
|
||||
}
|
||||
|
||||
return wnd[0];
|
||||
}
|
||||
|
@ -3816,11 +3824,13 @@ std::string g_path_file_("");
|
|||
FILE* g_file_ = NULL;
|
||||
static int g_log_level = 1;
|
||||
|
||||
static int get_log_level(const char* log_file)
|
||||
static int get_log_level(const char* log_file, std::wstring* firstmsg = NULL)
|
||||
{
|
||||
std::string cfg(log_file);
|
||||
size_t pos = cfg.rfind('\\');
|
||||
|
||||
if (firstmsg)
|
||||
*firstmsg = L"";
|
||||
cfg.erase(pos);
|
||||
pos = cfg.rfind('\\');
|
||||
if (pos != std::string::npos)
|
||||
|
@ -3833,6 +3843,23 @@ static int get_log_level(const char* log_file)
|
|||
}
|
||||
cfg += "\\debug.cfg";
|
||||
|
||||
// A+ -> XYBscanner.exe
|
||||
callback::check_wnd_thread_id = GetPrivateProfileIntA("twain-app", "check-main-wnd-thread-id", 0, cfg.c_str()) == 1;
|
||||
if (!callback::check_wnd_thread_id)
|
||||
{
|
||||
wchar_t pe[MAX_PATH] = { 0 }, * name = NULL;
|
||||
GetModuleFileNameW(NULL, pe, _countof(pe) - 1);
|
||||
name = wcsrchr(pe, L'\\');
|
||||
if (name++ == NULL)
|
||||
name = pe;
|
||||
if (wcsicmp(name, L"XYBscanner.exe") == 0)
|
||||
{
|
||||
callback::check_wnd_thread_id = true;
|
||||
if (firstmsg)
|
||||
*firstmsg = std::wstring(L"check window thread while PE is: '") + pe + L"'\r\n";
|
||||
}
|
||||
}
|
||||
|
||||
return GetPrivateProfileIntA("log", "twain-level", 1, cfg.c_str());
|
||||
}
|
||||
void init_log(void)
|
||||
|
@ -3879,12 +3906,14 @@ void init_log(void)
|
|||
}
|
||||
|
||||
wchar_t ts[128] = { 0 }, now[40] = { 0 };
|
||||
std::wstring msg1(L"");
|
||||
|
||||
hg_get_current_time_w(now);
|
||||
g_log_level = get_log_level(g_path_file_.c_str());
|
||||
g_log_level = get_log_level(g_path_file_.c_str(), &msg1);
|
||||
swprintf_s(ts, _countof(ts) - 1, L"==================%s - %d, Proc %d==================\r\n", now, g_log_level, GetCurrentProcessId());
|
||||
fwrite(ts, 2, lstrlenW(ts), g_file_);
|
||||
|
||||
if (msg1.length())
|
||||
fwrite(msg1.c_str(), 2, msg1.length(), g_file_);
|
||||
}
|
||||
}
|
||||
void close_log(void)
|
||||
|
|
Loading…
Reference in New Issue