More fixes for menus and combo boxes.
This commit is contained in:
1 parent
67ebc28d15
commit
872388a59b
11 files changed
+392
-35
No files matched your search
@@ -0,0 +1,70 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
#include "menu_bridge.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static DWORD foreground_thread32(void) {
|
||||
DWORD pid = 0;
|
||||
DWORD thread = GetWindowThreadProcessId(GetForegroundWindow(), &pid);
|
||||
HANDLE process = pid ? OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid) : NULL;
|
||||
BOOL wow64 = FALSE;
|
||||
BOOL known = process && IsWow64Process(process, &wow64);
|
||||
if (process) CloseHandle(process);
|
||||
return known && wow64 ? thread : 0;
|
||||
}
|
||||
|
||||
// Hook DLLs must match the application's architecture. This small PE host
|
||||
// supplies the 32-bit menu hook without requiring 32-bit Linux GLib/Winelib.
|
||||
int WINAPI WinMain(HINSTANCE instance, HINSTANCE previous, LPSTR args, int show) {
|
||||
(void)instance; (void)previous; (void)show;
|
||||
char *end;
|
||||
DWORD parentId = strtoul(args, &end, 10);
|
||||
HWND bridge = (HWND)(UINT_PTR)strtoul(end, &end, 10);
|
||||
DWORD bridgeProcess = 0;
|
||||
GetWindowThreadProcessId(bridge, &bridgeProcess);
|
||||
if (!parentId || bridgeProcess != parentId) return 1;
|
||||
HANDLE parent = OpenProcess(SYNCHRONIZE, FALSE, parentId);
|
||||
if (!parent) return 1;
|
||||
|
||||
WCHAR path[4096] = {0};
|
||||
DWORD length = GetModuleFileNameW(NULL, path, 4096);
|
||||
WCHAR *name = NULL;
|
||||
for (DWORD i = 0; i < length && i < 4096; ++i)
|
||||
if (path[i] == L'\\' || path[i] == L'/') name = path + i + 1;
|
||||
if (!length || length >= 4096 || !name ||
|
||||
name - path + lstrlenW(L"wine-access-menu32.dll") >= 4096) {
|
||||
CloseHandle(parent);
|
||||
return 1;
|
||||
}
|
||||
lstrcpyW(name, L"wine-access-menu32.dll");
|
||||
HMODULE module = LoadLibraryW(path);
|
||||
HOOKPROC callback = module ? (HOOKPROC)GetProcAddress(module, "WineAccessMenuHook") : NULL;
|
||||
HHOOK hook = NULL;
|
||||
DWORD hookedThread = 0;
|
||||
if (!callback)
|
||||
fprintf(stderr, "wine-access: 32-bit menu hook unavailable (error %lu)\n", GetLastError());
|
||||
if (callback) {
|
||||
while (IsWindow(bridge)) {
|
||||
// Wine's mixed-architecture global hook chain can suppress the 64-bit
|
||||
// hook. Attach only to the foreground 32-bit UI thread, and release it
|
||||
// when focus moves elsewhere. The 64-bit helper keeps its global hook.
|
||||
DWORD thread = foreground_thread32();
|
||||
if (thread != hookedThread) {
|
||||
if (hook) UnhookWindowsHookEx(hook);
|
||||
hook = thread ? SetWindowsHookExW(WH_CALLWNDPROC, callback, module, thread) : NULL;
|
||||
hookedThread = hook ? thread : 0;
|
||||
}
|
||||
DWORD result = MsgWaitForMultipleObjects(1, &parent, FALSE, 100, QS_ALLINPUT);
|
||||
if (result == WAIT_OBJECT_0 || result == WAIT_FAILED) break;
|
||||
MSG message;
|
||||
while (PeekMessageW(&message, NULL, 0, 0, PM_REMOVE)) {
|
||||
TranslateMessage(&message);
|
||||
DispatchMessageW(&message);
|
||||
}
|
||||
}
|
||||
if (hook) UnhookWindowsHookEx(hook);
|
||||
}
|
||||
if (module) FreeLibrary(module);
|
||||
CloseHandle(parent);
|
||||
return callback ? 0 : 1;
|
||||
}
|
||||
Reference in new issue
Block a user