Ver Mensaje Individual
  #1  
Antiguo 07-09-2008
ninguno ninguno is offline
Miembro
 
Registrado: sep 2008
Posts: 45
Reputación: 0
ninguno Va por buen camino
Problemas con ShellExecute

Hola

Tengo un problema con ShellExecute que no se cómo pillarlo. La cuestión es que tengo que lanzar 2 app externas y posicionarlas en pantalla de forma que se vean las 2. Para hacerlo, lanzo la siguiente función 2 veces, una para cada app:

Código:
 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;
}
aFile contiene el fichero a ejecutar y Wait me indica si tengo que devolver el handle de la ventana principal (en cuyo caso lo busco mediante la función LocatedWindows) o no.

Bien, la cuestión es que si le digo que no necesito handle, ShellExecute funciona siempre, pero si le digo que me lo devuelva (para poder posicionar una ventana lo necesito para la función SetWindowPos) ShellExecute deja de funciuonar hasta reiniciar el programa. Está claro que el error está en esta función, pero no llego a alcanzar a ver el por qué. Os pongo la función:

Código:
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;
}

Alguna idea?

Gracias
Responder Con Cita