I am wondering how i can get the correct HWND from the process my DLL is injected into. I made the code bellow myself and are wondering how and if i can improve it so it does the same think as if i used the FindWindow function like this FindWindow(0, L"calculator"). I am doing this because i didn't want to compare with name using FindWindow function, and becouse i want to learn.
HWND CorrectHWND = NULL;
BOOL CALLBACK HWND_Callback(HWND hwnd, LPARAM lParam)
{
if (CorrectHWND == NULL)
{
DWORD HWND_Process_ID;
GetWindowThreadProcessId(hwnd, &HWND_Process_ID);
if (GetCurrentProcessId() == HWND_Process_ID)
{
CorrectHWND = hwnd;
return false;
}
}
else
{
return false;
}
return true;
}
HWND Get_HWND()
{
EnumWindows(HWND_Callback, 0);
return CorrectHWND;
}