Changed window detection.
parent
dd530e80b1
commit
8e07dd0c6b
|
@ -9,30 +9,44 @@ extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam
|
||||||
|
|
||||||
#include <psapi.h>
|
#include <psapi.h>
|
||||||
|
|
||||||
|
struct enum_wnd_param
|
||||||
|
{
|
||||||
|
//HMODULE hModules[512];
|
||||||
|
//DWORD num_mods;
|
||||||
|
DWORD pid;
|
||||||
|
HWND window;
|
||||||
|
};
|
||||||
|
|
||||||
|
static BOOL __stdcall EnumWindowsProc(HWND hWnd, enum_wnd_param* param)
|
||||||
|
{
|
||||||
|
DWORD pid;
|
||||||
|
GetWindowThreadProcessId(hWnd, &pid);
|
||||||
|
if (pid == param->pid && GetWindow(hWnd, GW_OWNER) == nullptr && IsWindowVisible(hWnd))
|
||||||
|
{
|
||||||
|
param->window = hWnd;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
HWND GetGameWindow()
|
HWND GetGameWindow()
|
||||||
{
|
{
|
||||||
HWND hWnd = FindWindow(nullptr, nullptr);
|
enum_wnd_param param;
|
||||||
HMODULE hModules[512];
|
param.window = nullptr;
|
||||||
DWORD needed;
|
|
||||||
if (EnumProcessModules(GetCurrentProcess(), hModules, 512, &needed) != 0)
|
param.pid = GetCurrentProcessId();
|
||||||
{
|
EnumWindows(reinterpret_cast<WNDENUMPROC>(EnumWindowsProc), reinterpret_cast<LPARAM>(¶m));
|
||||||
int numMods = needed/sizeof(HMODULE);
|
|
||||||
while (hWnd)
|
if (param.window != nullptr) {
|
||||||
{
|
PRINT_DEBUG("Failed to get game window HWND\n");
|
||||||
HMODULE wndInst = (HMODULE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE);
|
|
||||||
if (wndInst != nullptr)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < numMods; ++i)
|
|
||||||
{
|
|
||||||
if (!GetParent(hWnd) && hModules[i] == wndInst)
|
|
||||||
return hWnd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hWnd = GetWindow(hWnd, GW_HWNDNEXT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
PRINT_DEBUG("Failed to get game window HWND\n");
|
else {
|
||||||
return hWnd;
|
char wnd_name[1024];
|
||||||
|
GetWindowText(param.window, wnd_name, 1023);
|
||||||
|
PRINT_DEBUG("Found window %s\n", wnd_name);
|
||||||
|
}
|
||||||
|
return param.window;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Windows_Hook::start_hook()
|
bool Windows_Hook::start_hook()
|
||||||
|
|
Loading…
Reference in New Issue