mirror of
https://gitlab.com/Mr_Goldberg/goldberg_emulator.git
synced 2024-11-30 15:27:21 +01:00
Changed window detection code.
GetModuleHandle(NULL) get the exe handle. Sometimes the window couldn't be found because the window wasn't created in the .exe but in a dll. Thats why I list all dll HANDLES and try to find the main window handle.
This commit is contained in:
parent
0fa2d82c67
commit
4db2b6528c
1 changed files with 19 additions and 8 deletions
|
@ -7,19 +7,30 @@ extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam
|
||||||
|
|
||||||
#include "../dll/dll.h"
|
#include "../dll/dll.h"
|
||||||
|
|
||||||
|
#include <psapi.h>
|
||||||
|
|
||||||
HWND GetGameWindow()
|
HWND GetGameWindow()
|
||||||
{
|
{
|
||||||
HWND hWnd = FindWindow(NULL, NULL);
|
HWND hWnd = FindWindow(nullptr, nullptr);
|
||||||
|
HMODULE hModules[512];
|
||||||
|
DWORD needed;
|
||||||
|
if (EnumProcessModules(GetCurrentProcess(), hModules, 512, &needed) != 0)
|
||||||
|
{
|
||||||
|
int numMods = needed/sizeof(HMODULE);
|
||||||
while (hWnd)
|
while (hWnd)
|
||||||
{
|
{
|
||||||
if (!GetParent(hWnd))
|
HMODULE wndInst = (HMODULE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE);
|
||||||
|
if (wndInst != nullptr)
|
||||||
{
|
{
|
||||||
if (GetModuleHandle(NULL) == (HMODULE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE))
|
for (int i = 0; i < numMods; ++i)
|
||||||
break;
|
{
|
||||||
|
if (!GetParent(hWnd) && hModules[i] == wndInst)
|
||||||
|
return hWnd;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
hWnd = GetWindow(hWnd, GW_HWNDNEXT);
|
hWnd = GetWindow(hWnd, GW_HWNDNEXT);
|
||||||
}
|
}
|
||||||
if (!hWnd)
|
}
|
||||||
PRINT_DEBUG("Failed to get game window HWND\n");
|
PRINT_DEBUG("Failed to get game window HWND\n");
|
||||||
return hWnd;
|
return hWnd;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue