Porting eConsole to Lazarus : Full emulation
Hi I am trying to bring the spawning capability of eConsole :
http://www.corion.net/econsole/ for cmd.exe emulation.
I extracted the needed section from eConsole however, I am having hard time to get it working.
Here is the code (you can find the whole project in the attachment)
Procedure TForm1.ReadInfo;
Var Info : TConsoleScreenBufferInfo;
Buffer : Pointer;
BufSize : LongInt;
LeftUpper : TCOORD;
Region : TSmallRect;
Target : TSmallRect;
TargetSize : TCOORD;
S : String;
BytesRead:longword;
Begin
RefreshTimer.Enabled := False;
If not GetConsoleScreenBufferInfo( console, Info )
then RaiseLastWin32Error();
Region := Info.srWindow;
FillChar( Target, SizeOf( Target ), 0 );
TargetSize.X := Region.Right - Region.Left +1;
TargetSize.Y := Region.Bottom - Region.Top +1;
Target.Right := Region.Right - Region.Left +1;
Target.Bottom := Region.Bottom - Region.Top +1;
FillChar( LeftUpper, SizeOf( LeftUpper ), 0 );
LeftUpper.X:=TargetSize.X;
LeftUpper.y:=TargetSize.y;
BufSize := (Target.Right)* (Target.Bottom)* SizeOf( TCharInfo );
Buffer := AllocMem(BufSize) ;
try
if ReadConsoleOutput(shellwnd,Buffer,TargetSize,LeftUpper,Region) then
begin
OemToAnsi(Buffer,Buffer) ;
AMemo.Text := AMemo.text + String(Buffer) ;
end
else begin
if amemo.Lines.Strings[amemo.Lines.Count-1]<>'no' then
amemo.Lines.add('no');
end;
finally
FreeMem( Buffer, BufSize );
end;
RefreshTimer.Enabled := True;
End;
The problem is to identify the location of cmd window and use ReadConsoleOutput to get buffer.
I know it is possible to get and interact with the cmd using Tprocess but, it does not give you the full emulation.
Any ideas how to fix this?
thanks