Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi - Hide console window [duplicate]

Tags:

delphi

Possible Duplicate:
Profiler and Memory Analysis Tools for Delphi
How do I hide the console window?

I'm reposting this to make it more clear. So, here is my console application:

enter image description here

That opens a socket to 127.0.0.1:81, when the console application is visible it works fine, now how do I keep it working fine as a console but make the console invisible?

I am using Delphi 2007 (7).

Thanks.

like image 301
user1770015 Avatar asked Oct 24 '12 19:10

user1770015


1 Answers

You can use ShowWindow and the GetConsoleWindow WinAPi functions.

Try this sample

{$APPTYPE CONSOLE}

uses
  Windows,
  SysUtils;

function GetConsoleWindow: HWND; stdcall; external kernel32;


begin
  try
    Writeln('Press enter to hide console the window');
    Readln;
    //hide the console window
    ShowWindow(GetConsoleWindow, SW_HIDE);

    //do something
    Sleep(5000);

    Writeln('Press enter to exit');
    //show the console window
    ShowWindow(GetConsoleWindow, SW_SHOW);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
like image 81
RRUZ Avatar answered Nov 18 '22 23:11

RRUZ