unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Menus;
type
TForm1 =
class(TForm)
Panel1: TPanel;
MainMenu1: TMainMenu;
Window1: TMenuItem;
Show1: TMenuItem;
Hide1: TMenuItem;
N1: TMenuItem;
ArrangeAll1: TMenuItem;
Cascade1: TMenuItem;
ile1: TMenuItem;
NewWindow1: TMenuItem;
OpenDialog1: TOpenDialog;
Button1: TButton;
procedure NewWindow1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function RunProcess(FileName:
string; ShowCmd: DWORD; wait: Boolean; ProcID: PCardinal): Longword;
var
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
FillChar(StartupInfo, SizeOf(StartupInfo), #0);
StartupInfo.cb := SizeOf(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW
or STARTF_FORCEONFEEDBACK;
StartupInfo.wShowWindow := ShowCmd;
if not CreateProcess(
nil,
@Filename[1],
nil,
nil,
False,
CREATE_NEW_CONSOLE
or
NORMAL_PRIORITY_CLASS,
nil,
nil,
StartupInfo,
ProcessInfo)
then
Result := WAIT_FAILED
else
begin
try
if not wait
then
begin
if ProcID <>
nil then ProcID^ := ProcessInfo.dwProcessId;
Result := S_OK;
exit;
end;
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Result);
finally
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ProcID: PCardinal;
begin
if OpenDialog1.Execute
then
RunProcess(OpenDialog1.FileName, SW_MINIMIZE, TRUE, ProcID);
Messagebox(0, '
fertig', @OpenDialog1.Filename[1], 0);
end;
procedure TForm1.NewWindow1Click(Sender: TObject);
var
hNotepad: hWnd;
//Handle auf das Window welches man einsperren möchte
begin
hNotepad := FindWindow('
Notepad','
Unbenannt - Editor');
//In diesem Fall sperren wir das gute alte Notepad ein
Windows.SetParent(hNotepad, form1.panel1.Handle);
//Wir setzen das Parent mit Windows.SetParent, da ein Aufruf
//von SetParent zur Folge hätte, dass wir die Methode von
//TWinControl aufrufen würden, was wir nicht wollen
ShowWindow(hNotepad, SW_MAXIMIZE);
//Einmal ShowWindow mit SW_MAXIMIZE als Parameter damit das Fenster
//sich über die ganze Form erstreckt
end;
end.