diff --git a/EXE.h b/EXE.h index 6f45f0e..1a0b80c 100644 --- a/EXE.h +++ b/EXE.h @@ -16,6 +16,9 @@ #include "GseContext.h" #include "/EgtDev/Include/EgtILogger.h" +//----------------------------------------------------------------------------- +HWND ExeGetMainWindowHandle( void) ; + //---------------------------------------------------------------------------- const std::string& ExeGetIniFile( void) ; diff --git a/EXE_General.cpp b/EXE_General.cpp index 7a167af..d82c979 100644 --- a/EXE_General.cpp +++ b/EXE_General.cpp @@ -44,6 +44,7 @@ static int s_nKeyType = KEY_LOCK_TYPE_ANY ; static string s_sIniFile ; static pfProcEvents s_pFunProcEvents = nullptr ; static pfOutText s_pFunOutText = nullptr ; +static HWND s_hMainWnd = nullptr ; //----------------------------------------------------------------------------- bool @@ -427,6 +428,22 @@ ExeOutText( const string& sText) return false ; } +//----------------------------------------------------------------------------- +bool +ExeSetMainWindowHandle( HWND hMainWnd) +{ + s_hMainWnd = hMainWnd ; + return true ; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +HWND +ExeGetMainWindowHandle( void) +{ + return s_hMainWnd ; +} + //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- const string& diff --git a/EgtExecutor.rc b/EgtExecutor.rc index 4599336..87fcb21 100644 Binary files a/EgtExecutor.rc and b/EgtExecutor.rc differ diff --git a/GenTools.cpp b/GenTools.cpp index 9046844..91fbf7f 100644 --- a/GenTools.cpp +++ b/GenTools.cpp @@ -27,14 +27,15 @@ FindTopWindow( void) 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) && + if ( GetWindowThreadProcessId( hWnd, &processId) != NULL && processId == pParams->second && - GetWindow( hWnd, GW_OWNER) == (HWND) nullptr && + GetWindow( hWnd, GW_OWNER) == NULL && IsWindowVisible( hWnd)) { // Stop enumerating SetLastError( -1) ; diff --git a/LUA_General.cpp b/LUA_General.cpp index c19395a..b1923a0 100644 --- a/LUA_General.cpp +++ b/LUA_General.cpp @@ -242,7 +242,8 @@ LuaOutBox( lua_State* L) LuaGetParam( L, 4, bModal) ; LuaClearStack( L) ; // emetto la finestra di dialogo - int nRes = MessageBox( FindTopWindow(), stringtoW( sOut), stringtoW( sTitle), + HWND hTopWnd = ExeGetMainWindowHandle() ; // FindTopWindow() ; + int nRes = MessageBox( hTopWnd, stringtoW( sOut), stringtoW( sTitle), MB_OKCANCEL | nIcon | ( bModal ? MB_TASKMODAL : MB_SYSTEMMODAL)) ; // risultato (Ok->true, Cancel->false) LuaSetParam( L, ( nRes == IDOK)) ; @@ -304,7 +305,7 @@ LuaFileDialog( lua_State* L) OPENFILENAME ofn ; ZeroMemory( &ofn, sizeof( ofn)) ; ofn.lStructSize = sizeof( ofn) ; - ofn.hwndOwner = FindTopWindow() ; + ofn.hwndOwner = ExeGetMainWindowHandle() ; // FindTopWindow() ; ofn.lpstrFilter = LPWSTR( wsFilter) ; ofn.lpstrFile = LPWSTR( wsFileName) ; ofn.nMaxFile = MAX_PATH ; @@ -622,7 +623,8 @@ LuaDialogBox( lua_State* L) } LuaClearStack( L) ; // lancio dialogo - bool bOk = ( DialogBox( GetModuleIstance(), MAKEINTRESOURCE( IDD_LUADLG), FindTopWindow(), (DLGPROC)DialogBoxProc) == IDOK) ; + HWND hTopWnd = ExeGetMainWindowHandle() ; // FindTopWindow() ; + bool bOk = ( DialogBox( GetModuleIstance(), MAKEINTRESOURCE( IDD_LUADLG), hTopWnd, (DLGPROC)DialogBoxProc) == IDOK) ; // restituzione parametri if ( bOk) { STRVECTOR vRes ;