interested
Main Topics
Browse All TopicsThis is a strange one. I want to be able to run a DOS application so it displays INSIDE my form. Like when you start command prompt it appears in its own window. I want this window to be in my form.
1. The application will be initiated from Delphi.
2. DOS Application should be terminated from itself or from my Delphi application
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Try this component.
http://master-brain.boom.r
sorry above link isn't working
Try
http://master-brain.boom.r
then press Download
and find
DosCommand.zip
well you can launch the dos app with CreateProcess then use dwProcessID from the returned PROCESSINFO structure
to get the window from the processid use the folowing code
function EnumWindowsProc(Wnd: hWnd; ProcWndInfo: PProcessWindow): BOOL;
stdcall;
var
WndProcessID: Cardinal;
begin
GetWindowThreadProc(Wnd, WndProcessID);
if WndProcessID = ProcWndInfo^.TargetProcess
ProcWndInfo^.FoundWindow := Wnd;
Result := False; // This tells EnumWindows to stop enumerating since
we've already found a window.
end else Result := True; // Keep searching
end;
function GetProcessWindow(TargetPro
var
ProcWndInfo: TProcessWindow;
begin
ProcWndInfo.TargetProcessI
ProcWndInfo.FoundWindow := 0;
EnumWindows(@EnumWindowsPr
Result := ProcWndInfo.FoundWindow;
end;
then simply set the windows parent to your form or panel or whatever control you wish
the usage would be smth like :
ok:=CreateProcess(nil, 'DosApp.exe, nil, nil, true,
NORMAL_PRIORITY_CLASS, nil, nil, si, pi);
if ok then
Windows.SetParent(GetProce
I haven't tested it but that's the basic idea :)
ehh :) just made a test app ,, the code bellow works just fine :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
PProcessWindow = ^TProcessWindow;
TProcessWindow = record
TargetProcessID: Cardinal;
FoundWindow: hWnd;
end;
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
OpenD: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
hDosWin: HWND = 0;
implementation
{$R *.dfm}
function EnumWindowsProc(Wnd: hWnd; ProcWndInfo: PProcessWindow): BOOL;stdcall;
var
WndProcessID: Cardinal;
begin
GetWindowThreadProcessId(W
if WndProcessID = ProcWndInfo^.TargetProcess
ProcWndInfo^.FoundWindow := Wnd;
Result := False; // This tells EnumWindows to stop enumerating since we've already found a window.
end else Result := True; // Keep searching
end;
function GetProcessWindow(TargetPro
var
ProcWndInfo: TProcessWindow;
begin
ProcWndInfo.TargetProcessI
ProcWndInfo.FoundWindow := 0;
EnumWindows(@EnumWindowsPr
Result := ProcWndInfo.FoundWindow;
end;
procedure TForm1.Button1Click(Sender
var si: STARTUPINFO;
pi: TProcessInformation;
ok: Boolean;
begin
if not OpenD.Execute then exit;
FillChar(si, SizeOf(si), 0);
si.cb:=SizeOf(si);
si.wShowWindow:=SW_SHOW;
ok:=CreateProcess(nil, PChar(OpenD.FileName), nil,
nil, true, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, si, pi);
if not ok then exit;
hDosWin:=GetProcessWindow(
if hDosWin > 0 then
begin
Windows.SetParent(hDosWin,
SetWindowPos(hDosWin, 0, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOZORDER);
end;
// we don't need the handles so we close them
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if hDosWin > 0 then
PostMessage(hDosWin, WM_CLOSE, 0, 0);
end;
end.
Hi,
I also like it. Nice code Lee_Nover ;-)
1. My uses clause (D5):
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;
2.
GetWindowThreadProcessId(W
3.Add
Sleep(100);
or more after CreateProcess to let the new process to create its main window.
Regards, Geo
Hi all, I know this is an old thread, but, I was wondering...
The above code compiles/runs without any errors, but doesn't move/assign the dos window to the Panel as a parent (maybe it does, but the dos window is still not running in the panel), BUT as soon as I debug and step through it.... the dos window is assigned to the panel. I'm using D6... Any Ideas!?
Business Accounts
Answer for Membership
by: TomasHelgiPosted on 2002-05-10 at 01:53:13ID: 7000749
Hi!
.htm
Take a look at the TDosMemo v.1.00 on Torry's Delphi Pages
http://www.torry.net/memos
This is a great way to display a running DOS application "inside" a Delphi form.
Regards,
Tomas Helgi