Solved

Hiding Delphi Console Window

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

896 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

14 Experts available now in Live!

Get 1:1 Help Now