Solved

Hiding Delphi Console Window

Posted on 2003-10-28
5
3,616 Views
Last Modified: 2010-10-05
Hi, I've notcied that when you make a console application in delphi it significantly reduces the filesize, assuming you only use the SysUtils in your uses. I was wondering if maybe there was a way to hide the console window? So bascially a program that runs invisibly or just when opened is designed to do one task, and it's done.

So does anyone know how to hide the console window in a console app?
0
Comment
Question by:ionet
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:alsantos
ID: 9638967
Hi ionet, try this:

program Project1;

{$APPTYPE CONSOLE}

uses SysUtils, Windows;

function EnumProc(hwnd:HWND;lParam:DWORD):BOOL; stdcall;
var
  PID:DWORD;
begin
  Result := False;
  GetWindowThreadProcessID(hwnd,@PID);
  if PID=lparam then
    ShowWindow(hwnd,SW_HIDE)
  else
    Result := True;
end;

begin
  writeln('Press Enter to HIDE application window...');
  readln;
  EnumWindows(@EnumProc,GetCurrentProcessID()); // will hide your console application after the enter key.
  readln;
end.

alsantos
0
 

Author Comment

by:ionet
ID: 9639015
Hmm, alsantos, This is great code, although I meant that the console window wouldn't even show up from when you start the program. With this code it would show up for about less than a second, and then hide.
0
 
LVL 2

Accepted Solution

by:
alsantos earned 50 total points
ID: 9639091
It's more easy. Just delete the line  {$APPTYPE CONSOLE}, for example:

program Project1;

uses Windows;

begin
  CopyFile('c:\test.txt', 'c:\test2.txt', True); // an example code
end.

alsantos
0
 

Author Comment

by:ionet
ID: 9639123
Thanks a lot alsantos. Points to you.

Only thing I have left to ask is

"Is there a way to create a program that runs like a regular application without forms and with the file size significantly decreased. Basically like a console application except it doesn't close when its done."
0
 
LVL 2

Expert Comment

by:alsantos
ID: 9639150
I didn't understand... Do You want a program that run without form and it isn't a console application ?

Look, you can create an normal application, with form, but you put the form invisible. So, It will work normally, and to decrease the size, you can use upx(http://upx.sourceforge.net)
And you can create an console application using a while for example... While (True = True) do ... will join in a infinite loop. so, it will only exit when you want.

alsantos
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question