//---------------------------------------------------------------------------- // EgalTech 2017-2017 //---------------------------------------------------------------------------- // File : GenTools.cpp Data : 08.01.17 Versione : 1.6x5 // Contenuto : Funzioni generalie. // // // // Modifiche : 08.01.17 DS Creazione modulo. // // //---------------------------------------------------------------------------- #include "stdafx.h" #include "GenTools.h" #include using namespace std ; //---------------------------------------------------------------------------- HWND FindTopWindow( void) { // Recupero l'Id del processo corrente DWORD pid = GetCurrentProcessId() ; pair params = { 0, pid} ; // Enumerate the windows using a lambda to process each window SetLastError( 0) ; BOOL bResult = EnumWindows( []( HWND hWnd, LPARAM lParam) -> BOOL { auto pParams = ( pair*)(lParam) ; DWORD processId ; if ( GetWindowThreadProcessId( hWnd, &processId) != NULL && processId == pParams->second && GetWindow( hWnd, GW_OWNER) == NULL && IsWindowVisible( hWnd)) { // Stop enumerating SetLastError( -1) ; pParams->first = hWnd ; return FALSE ; } // Continue enumerating return TRUE ; }, (LPARAM) ¶ms) ; if ( ! bResult && GetLastError() == -1 && params.first != nullptr) { return params.first ; } return nullptr ; }