Ver Mensaje Individual
  #6  
Antiguo 27-03-2007
erika.martinez erika.martinez is offline
Miembro
 
Registrado: may 2003
Ubicación: Buenos Aires - Argentina
Posts: 18
Reputación: 0
erika.martinez Va por buen camino
Tal vez si conocen el código que estoy usando sea más fácil para ustedes entender mi problema. el código es el siguiente:


Código Delphi [-]
procedure TForm1.PostKeyEx32(key: Word; const shift: TShiftState; specialkey: Boolean);
{Este código lo obtuve en el Club Delphi}
{************************************************************
* Procedure PostKeyEx32
*
* Parameters:
*  key    : virtual keycode of the key to send. For printable
*           keys this is simply the ANSI code (Ord(character)).
*  shift  : state of the modifier keys. This is a set, so you
*           can set several of these keys (shift, control, alt,
*           mouse buttons) in tandem. The TShiftState type is
*           declared in the Classes Unit.
*  specialkey: normally this should be False. Set it to True to
*           specify a key on the numeric keypad, for example.
* Description:
*  Uses keybd_event to manufacture a series of key events matching
*  the passed parameters. The events go to the control with focus.
*  Note that for characters key is always the upper-case version of
*  the character. Sending without any modifier keys will result in
*  a lower-case character, sending it with [ssShift] will result
*  in an upper-case character!
*Created: 17.7.98 by P. Below
************************************************************}
Type
   TShiftKeyInfo = Record
   shift: Byte;
   vkey : Byte;
   End;
   byteset = Set of 0..7;
Const
   shiftkeys: Array [1..3] of TShiftKeyInfo =
       ((shift: Ord(ssCtrl); vkey: VK_CONTROL ),
       (shift: Ord(ssShift); vkey: VK_SHIFT ),
       (shift: Ord(ssAlt); vkey: VK_MENU ));
Var
   flag: DWORD;
   bShift: ByteSet absolute shift;
   i: Integer;
Begin
   For i := 1 To 3 Do Begin
       If shiftkeys[i].shift In bShift Then
           keybd_event( shiftkeys[i].vkey, MapVirtualKey(shiftkeys[i].vkey, 0), 0, 0);
   End; { For }

   If specialkey Then
     flag := KEYEVENTF_EXTENDEDKEY
   Else
     flag := 0;

   keybd_event( key, MapvirtualKey( key, 0 ), flag, 0 );
   flag := flag or KEYEVENTF_KEYUP;
   keybd_event( key, MapvirtualKey( key, 0 ), flag, 0 );

   For i := 3 DownTo 1 Do Begin
     If shiftkeys[i].shift In bShift Then
       keybd_event( shiftkeys[i].vkey, MapVirtualKey(shiftkeys[i].vkey, 0), KEYEVENTF_KEYUP, 0);
   End; { For }
End; { PostKeyEx32 }

function TForm1.WinExecAndWait32(FileName: String; Visibility: Integer): Integer;
{Esta función la utilicé hace tiempo para otra aplicación y creo que el código lo saqué
 del Club Delphi}
var
  zAppName: Array[0..512] of Char;
  zCurDir: Array[0..255] of Char;
  WorkDir: String;
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
  Resultado, ExitCode: DWord;
begin
  StrPCopy(zAppName, FileName);
  GetDir(0, WorkDir);
  StrPCopy(zCurDir, WorkDir);
  FillChar(StartupInfo, Sizeof(StartupInfo), #0);
  StartupInfo.cb := SizeOf(StartupInfo);
  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := Visibility;
  CreateProcess(nil, zAppName, nil, nil, False, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,
    nil, nil, StartupInfo, ProcessInfo);

  repeat
    exitCode := WaitForSingleObject(ProcessInfo.hProcess,1000);
    Application.ProcessMessages;
  until (exitCode <> WAIT_OBJECT_0);

  GetExitCodeProcess(ProcessInfo.hProcess,Resultado);
  MessageBeep(0);
  CloseHandle(ProcessInfo.hProcess);
  Result := Resultado;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  F: TextFile;
  H: HWND;
  I, J: Integer;
  C: Char;
  Genoma: Array of Char;
begin
  WinExecAndWait32(PChar('C:\VIENNA\RNAfold.exe'),SW_SHOWNORMAL);
  for J := 1 to 1443 do
  begin
    AssignFile(F, 'C:\GenomasGenerados\SinGenes\' + IntToStr(J) + '\GenomaInicial.txt');
    {Acá tengo la información que tengo que pasarle al programita RNAfold.exe, y que la paso
    mediante simmulación de teclado. Esta información la tengo guardada en archivos de texto,
    después la cargo a un array of char: Genoma, y mientras recorro este array simulo presión de
    teclas}
    try
      Reset(F);
    except
      CloseFile(F);
      Exit;
    end;
    SetLength(Genoma, 0);
    while not Eof(F) do
    begin
      Read(F, C);
      SetLength(Genoma, Length(Genoma) + 1);
      Genoma[High(Genoma)] := C;
    end;
    CLoseFile(F);
    H := FindWindow(Nil,'C:\VIENNA\RNAfold.exe');
    if H = 0 then ShowMessage('No se encontro la Aplicacion')
    else
    begin
      SetForegroundWindow(H);
      for I := Low(Genoma) to High(Genoma) do
        PostKeyEx32(Ord(Genoma[i]), [], False);
      repeat
        Application.ProcessMessages;
      until FileExists('C:\Erika\ICBME\Delphi y Vienna\rna.ps');
      {Esto es porque el programita me genera una gráfica en un erchivo de tipo ps. De todas
      formas no es esta la información que me interesa, lo que a mi me interesa es lo que el
      programa devuelve en PANTALLA}
    end;;
    LeerPantallaRNAFold {ESTO ES LO QUE ME FALTA Y NO SÉ COMO HACER!!!}
  end;
  H := FindWindow(Nil,'C:\VIENNA\RNAfold.exe');
    if H = 0 then ShowMessage('No se encontro la Aplicacion');
  SendMessage(H, WM_CLOSE, 0, 0);
end;

y lo que no puedo hacer es capturar los datos de salida que me da la aplicación rnafold.exe. Esta salida es de tipo stdout, es decir no me genera ningún archivo de salida.

Gracias por su ayuda!!!

Última edición por erika.martinez fecha: 27-03-2007 a las 18:36:00.
Responder Con Cita