Solved

Hiding Delphi Console Window

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

707 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