Solved

Hiding Delphi Console Window

Posted on 2003-10-28
5
3,601 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now