Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it OK to hide Delphi's "Application" Window?

Tags:

delphi

We just moved our application from a MDI container to a single document interface. Our users are used to using a "Windows" menu in the MDI parent to show windows side by side. We want to train them to right click on the Windows taskbar and use the window management functions there.

With Delphi applications we noticed that the windows shell leaves room for the hidden "Application" window. So if I only have two windows open it will arrange room for three. The Application window is not really shown but there is space left for it.

This is made worse by the fact that we have two different applications. If they only have one window open in each application and want to show them side by side windows will actually try to account for 4 windows.

So instead of seeing two windows each taking 1/2 of the screen I see two windows that take up 1/4 of the desktop and the rest of the screen is open.

I found that adding a line to hide the application window as my application starts up will fix this problem.

ShowWindow(Application.Handle, SW_HIDE);

Edit in case someone does not read down to the answer. Based on Craig's answer below I am setting the windows style to WS_EX_TOOLWINDOW instead of hiding the window. SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);

My (original) questions is: Is this safe (hiding the application window)? I'm wondering if I may be breaking something else by hiding the Application window. Are there any side effect I need to be aware of? Is there a better way to solve this issue?

I'm using Delphi 2007. The issues seem to be consistent across Windows XP, Vista, and 7.

Update: Some of the answers seem to think the problem is with the Application forms icon being visible. That is not the case. I already have MainFormOnTaskbar set to true.

Also if you are testing this be aware that the Delphi IDE (only tested with 2007) makes things worse. Try this. Open the Delphi IDE and two instances of notepad. Minimize the IDE but have both notepads un-minimized. Right click on choose Show Windows Side by Side. You will see each notepad take up 1/3 of the screen. Close the IDE and choose Show Windows Side by Side again and each will take up 1/2 half of the screen.

like image 802
Mark Elder Avatar asked Jun 15 '11 15:06

Mark Elder


2 Answers

In Delphi 2007 (and above) the Application Window does not show on TaskBar at all if

Application.MainFormOnTaskbar := True;

line is in a project file (*.dpr). For example

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;   // <--
  Application.CreateForm(TForm7, Form7);
  Application.CreateForm(TForm8, Form8);
  Application.Run;
end.

That is default setting for new applications, but this line is absent if you ported an application from previous Delphi version - you should add this line manually.

like image 150
kludg Avatar answered Nov 18 '22 13:11

kludg


As long as MainFormOnTaskBar is true, you can fix the problem by adding this to your DPR:

SetWindowLong(Application.Handle, GWL_EXSTYLE,
  GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);

Later versions of Delphi automatically include the WS_EX_TOOLWINDOW flag when they create the TApplication handle.

like image 3
Zoë Peterson Avatar answered Nov 18 '22 11:11

Zoë Peterson