AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Konsolenfenster im GUI-Mode unterdrücken

Ein Thema von naujo · begonnen am 23. Aug 2005 · letzter Beitrag vom 19. Apr 2014
 
Benutzerbild von himitsu
himitsu
Online

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.372 Beiträge
 
Delphi 12 Athens
 
#19

Re: Konsolenfenster im GUI-Mode unterdrücken

  Alt 23. Nov 2007, 11:06
Warum bin ich eigentlich nicht gleich draufgekommen AttachConsole als erstes aufzurufen?
(wozu FreeConsole ... AttachConsole sagt ja auch ob's erfolgreich war)

Das einzige Problem ist jetzt nur noch, daß AttachConsole erst ab XP verfügbar ist.
Und nachprogrammieren ist für mich etwas zu hoch ... hab mal reingeschaut und da werden Dinge aufgerufen, wo ich mit meinem Unwissen nicht rankomm.

Bei allem vor XP wird AttachConsoleDummy verwendet, welches einfach nur sagt daß es nicht ging
und ab XP funktioniert es so eigentlich perfekt. > es wird kine neue Konsole geöffnet und beim Programmstart blinkt auch Keine kurz auf.

Delphi-Quellcode:
{$APPTYPE GUI}

Uses Windows;

Function AttachConsoleDummy(dwProcessId: LongWord): LongBool;
  Begin
    Result := False;
  End;

Var AttachConsole: Function(dwProcessId: LongWord): LongBool; StdCall;
  ConsoleOutput: Boolean = False;




AttachConsole := GetProcAddress(GetModuleHandle('kernel32.dll'), 'AttachConsole');
If @AttachConsole = nil Then AttachConsole := @AttachConsoleDummy;

ConsoleOutput := AttachConsole(ATTACH_PARENT_PROCESS);




// und jetzt immer wenn zur Console verbunden wurde etwas reinschreiben
// > WriteLn erzeugt eine Exception, wenn keine Console vorhanden ist (darum ConsoleOutput)
If ConsoleOutput Then WriteLn('irgendwas');


Oder diese kleine Unit
Delphi-Quellcode:
Unit FSSystem;

Interface
  Var ConsoleOutput: Boolean = False;

  Procedure WriteConsole(S: String);

Implementation
  Uses Windows;

  Var AttachConsole: Function(dwProcessId: LongWord): LongBool; StdCall;

  Function AttachConsoleDummy(dwProcessId: LongWord): LongBool;
    Begin
      Result := False;
    End;

  Procedure WriteConsole(S: String);
    Begin
      If (S = '') or not ConsoleOutput Then Exit;
      UniqueString(S);
      CharToOemA(PAnsiChar(S), PAnsiChar(S));
      WriteLn(S);
    End;

Initialization
  AttachConsole := GetProcAddress(GetModuleHandle('kernel32.dll'), 'AttachConsole');
  If @AttachConsole = nil Then AttachConsole := @AttachConsoleDummy;

  ConsoleOutput := AttachConsole(ATTACH_PARENT_PROCESS);

End.
und im Programm dann jeweils einfach nur noch WriteConsole aufrufen
Delphi-Quellcode:
{$APPTYPE GUI}


WriteConsole('irgendwas');
Angehängte Dateien
Dateityp: pas fssysten_181.pas (775 Bytes, 28x aufgerufen)
Ein Therapeut entspricht 1024 Gigapeut.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:49 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz