[C++] How to get a correct Window Handle
Since windows has some unorthodox methods for getting certain requirements.
#include <windows.h>
DWORD WINAPI Thread( LPVOID )
{
HWND hWnd;
for( ;; )
{
DWORD a;
GetWindowThreadProcessId( ( hWnd = GetActiveWindow() ), &a );
if ( ( a != GetCurrentProcessId() ) )
{
hWnd = NULL;
continue;
}
}
return NULL;
}
BOOL WINAPI DllMain( HMODULE hModule, DWORD Reason, LPVOID lpvReserved )
{
if( Reason == DLL_PROCESS_ATTACH )
CreateThread( NULL, 0, Thread, NULL, NULL, 0 );
return TRUE;
}
This is good for injecting into dynamic processes without the worry of Class Names, Window names, or Preset ID's.
This also avoids the problem with using GetActiveWindow Alone since it gets the window currently being used whether it is another program or the desktop.
Author: SEGnosis