ShellExecute ne fonctionne pas
Bonjour
J'ai un problème avec ShellExecute et c'est le suivant. Je dois contrôler 2 app externes pour les positionner convenablement dans l'écran. Pour le faire, j'appelle 2 fois a cette fonction (1 pour chaque application que je dois lancer).
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
HWND __fastcall TStep3::EjecApp(AnsiString aFile, bool Wait)
{
bool Exit = false;
int MSec = 0;
HWND aHandle = 0;
AnsiString aTitle = "";
ShellExecute(this->Handle, "open", (TmpDir + aFile).c_str(), NULL, NULL, SW_NORMAL);
if ( !Wait ) return aHandle;
do {
Sleep(200);
MSec = MSec + 200;
if (MSec >= 2000) Exit = true;
aHandle = LocatedWindows(aTitle, aPartialTitle);
} while ( (aHandle != 0) | Exit );
return aHandle;
} |
Bon, si Wait et false tout va bien, mais si est true ShellExecute ne fonctionne pas la deuxième fois. Le problème est dans la fonction LocatedWindows (cherche dans toutes les fenêtres du Desktop un titre pour localiser le handle nécessaire de la fenêtre pour SetWindowPos) mais je n'arrive a voir pourquoi
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
HWND __fastcall TStep3::LocatedWindows(AnsiString aTitle)
{
HWND nHwnd = 0;
HWND nInitHwnd = 0;
HWND nCurrWnd = 0;
int nLength = 0;
char * aTitulo = "";
nHwnd = GetDesktopWindow();
nInitHwnd = GetWindow( nHwnd, GW_CHILD );
nCurrWnd = GetWindow( nInitHwnd, GW_HWNDFIRST );
while ( nCurrWnd != 0 )
{
nLength = GetWindowTextLength(nCurrWnd);
if (nLength > 0)
{
GetWindowText(nCurrWnd, aTitulo, 255);
if ( UpperCase(aTitulo) == UpperCase(aTitle) )
return nCurrWnd;
}
nCurrWnd = GetWindow( nCurrWnd, GW_HWNDNEXT );
}
return 0;
} |
Quelqu'un peut m'aider?
Merci en avance