Ver Mensaje Individual
  #6  
Antiguo 25-05-2016
gaunmanuel gaunmanuel is offline
Miembro
 
Registrado: may 2015
Posts: 48
Reputación: 0
gaunmanuel Va por buen camino
Gracias a todos.
Ya habia revisado todos los links y opciones que me dan.
Pero ya descubri el porque, siempre habia hecho el ejemplo con la calculadora de windows, y por alguna razon esta aplicacion no se puede embeber en la forma.
Sin embargo con otra aplicacion hecha en Delphi funciona correctamente, aqui les dejo el codigo como lo use:

Código Delphi [-]
unit ufrmMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus, shellApi;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    mnuNotepad: TMenuItem;
    procedure mnuNotepadClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
      H: THandle;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

type
  TWindowRec = record
    Handle: THandle;
    ProcessId: Cardinal;
    WindowName: PChar;
  end;
  PWindowRec = ^TWindowRec;

function EnumWindowsProc(Handle: Thandle; lParam: LPARAM): BOOL; stdcall;
var
  ProcessId: Cardinal;
  Buffer: PChar;
  Size: Integer;
begin
  Result:= TRUE;
  ProcessId:= 0;
  GetWindowThreadProcessId(Handle, ProcessId);
  if ProcessId = PWindowRec(lParam).ProcessId then
  begin
    if PWindowRec(lParam).WindowName <> nil then
    begin
      Size:= GetWindowTextLength(Handle) + 1;
      GetMem(Buffer,Size);
      try
        GetWindowText(Handle,Buffer,Size);
        if StrIcomp(PWindowRec(lParam).WindowName, Buffer) = 0 then
        begin
          PWindowRec(lParam).Handle:= Handle;
          Result:= FALSE;
        end;
      finally
        Freemem(Buffer);
      end;
    end else
    begin
      PWindowRec(lParam).Handle:= Handle;
      Result:= FALSE;
    end;
  end;
end;

function GetWindowFromProcessId(ProcessId: Cardinal; WindowName: PChar): THandle;
var
  WindowRec: TWindowRec;
begin
  FillChar(WindowRec,Sizeof(WindowRec),0);
  WindowRec.ProcessId:= ProcessId;
  WindowRec.WindowName:= WindowName;
  EnumWindows(@EnumWindowsProc, LPARAM(@WindowRec));
  Result:= WindowRec.Handle;
end;

function Ejecutar(Cmd: string; WindowName: PChar; Timeout: Cardinal): THandle;
var
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
  Ticks: Cardinal;
begin
  Result:= 0;
  FillChar(StartupInfo,Sizeof(StartupInfo),0);
  StartupInfo.wShowWindow:= SW_SHOW;
  Ticks:= GetTickCount;
  if CreateProcess(nil,PChar(Cmd),nil,nil, FALSE, CREATE_NEW_CONSOLE or
    NORMAL_PRIORITY_CLASS,nil,nil,StartupInfo, ProcessInfo) then
    while (Result = 0) and (GetTickCount - Ticks < TimeOut) do
    begin
      Result:= GetWindowFromProcessId(ProcessInfo.dwProcessId, WindowName);
      if Result = 0 then Sleep(200);
    end;
end;

procedure TForm1.mnuNotepadClick(Sender: TObject);

begin
  H:= Ejecutar('C:\Program Files (x86)\Borland\Delphi7\Projects\LetrasNumerosConsecutivos\Project1.exe',nil,5000);
  Windows.SetParent(H,Handle);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
PostMessage(h, WM_CLOSE, 0, 0);

end;

end.

saludos.
Responder Con Cita