Solved

Hiding Delphi Console Window

Posted on 2003-10-28
5
3,632 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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