yoy.be "Why-o-Why"

Application without forms.

2005-06-08 19:36  i87  delphi  [permalink]

One type of 'application without forms', is using the {$APPTYPE CONSOLE} setting to replace the default {$APPTYPE GUI}. When using Write and WriteLn the output is sent to a command prompt box, either the one the application was started in, or a new one if the application is started from the graphical environment (GUI).

If no commant prompt window is needed, and all you need is your exe running, you really end up with an application without forms. If you open the project source (the .dpr file) from the menu: Project > View Source, or with Ctrl+F12, you will see these lines:


Application.Initialize calls initialization some units require to be done right before the application starts, e.g. when using COM objects. Application.Run loops until the application is terminated, and processes incoming windows messages. If you add forms or datamodules, Application.CreateForm calls are added inbetween these two.

Sometimes, when using an application without forms, you get a button on the taskbar anyway. This is done every time Application.Handle is used, e.g. when using Application.MessageBox. If you don't want this, you might consider not using Application (if you don't include the Forms unit in the project the final exe-file could be much smaller!) but that might create a number of other problems. Another solution is this code, executed in the start-up code.


By using the Handle property, the task-bar button is created, and by using the Windows function ShowWindow you can hide this button without changing the internal states of the Application object.

This task-bar button actually has a seperate right-click menu only with options Restore, Minimize and Close, that tie in to the Application object, which is different to the default right-click menu (SystemMenu) that has Move and Resize also. To have a taskbar-button for each window, see the CreateParams trick.

twitter reddit linkedin facebook