Skip to content

Instantly share code, notes, and snippets.

@Kiterai
Created August 9, 2018 13:23
Show Gist options
  • Save Kiterai/6f4315269bc7cb331bafa720c23b4c85 to your computer and use it in GitHub Desktop.
Save Kiterai/6f4315269bc7cb331bafa720c23b4c85 to your computer and use it in GitHub Desktop.
DWORD GetMainThread(DWORD Pid)
{
struct
{
const DWORD Pid;
DWORD Tid;
} tmpDat = {Pid, 0};
EnumWindows(
[](HWND hWnd, LPARAM lp) -> BOOL
{
DWORD WndPid;
DWORD tmpTid = GetWindowThreadProcessId(hWnd, &WndPid);
auto pTmpDat = reinterpret_cast<decltype(tmpDat)*>(lp);
if (
WndPid == pTmpDat->Pid &&
GetWindow(hWnd, GW_OWNER) == NULL &&
IsWindowVisible(hWnd))
{
pTmpDat->Tid = tmpTid;
return FALSE;
}
else
{
return TRUE;
}
},
reinterpret_cast<LPARAM>(&tmpDat));
return tmpDat.Tid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment