Einzelnen Beitrag anzeigen

Benutzerbild von Shaman
Shaman

Registriert seit: 2. Nov 2003
Ort: Schweiz
407 Beiträge
 
Turbo Delphi für Win32
 
#12

Re: Console in Delphiprogramm?

  Alt 17. Dez 2004, 10:26
Hallo zusammen

Ich hab mir mit Code aus dem Forum mal folgendes zusammengebastelt, um eine Konsolenanwendung innerhalb meiner Form anzuzeigen:

Delphi-Quellcode:
function RunConsoleApp(const FileName: string; const Parent: THandle): THandle;

  function EnumWindowsProc(hWnd: HWND; lParam: LPARAM): BOOL; stdcall;
  begin
    TList(lParam).Add(Pointer(hWnd));
    Result := True;
  end;

var
  SI: TStartupInfo;
  PI: TProcessInformation;
  List: TList;
  ProcessId: DWORD;
  Console: THandle;
  I: Integer;
begin
  Result:= 0;
  FillChar(SI, SizeOf(TStartupInfo), 0);
  SI.cb := SizeOf(TStartupInfo);
  SI.dwFlags := STARTF_USESHOWWINDOW;
  SI.wShowWindow := SW_HIDE;
  if CreateProcess(nil, PChar(FileName), nil, nil, False, 0, nil, nil, SI, PI) then
  try
    Console:= 0;
    List:= TList.Create;
    try
      repeat
        List.Clear;
        if EnumWindows(@EnumWindowsProc, Longint(List)) then
        begin
          for I := 0 to List.Count - 1 do
          begin
            GetWindowThreadProcessId(Longint(List.Items[I]), ProcessId);
            if PI.dwProcessId = ProcessId then
            begin
              Console:= Longint(List.Items[I]);
              Break;
            end;
          end;
        end;
      until Console <> 0;
    finally
      List.Free;
    end;
  finally
    CloseHandle(PI.hProcess);
    CloseHandle(PI.hThread);
  end;
  if Console <> 0 then
  begin
    SetParent(Console, Parent);
    SetWindowPos(Console, 0, 0, 0, 0, 0, SWP_NOSIZE or SWP_SHOWWINDOW);
    Result:= Console;
  end;
end;
Meine Frage: Wie lässt sich nun noch die Titelleiste ausblenden, damit man die Konsole nicht mehr verschieben kann?
assert(SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) and not WS_CAPTION) <> 0); geht irgendwie nicht bei Konsolen...

Gruss
Shaman
Daniel Pauli
Looking for answers from the great beyond
  Mit Zitat antworten Zitat