tags:

views:

528

answers:

2

I am a Delphi novice, but I'm trying to understand the relationship between TApplication and TfrmMain windows using Spy++. It seems that the TfrmMain window is the real window that has proper screen coordinates, but the TApplication window is the one that appears in the Windows taskbar. Also, they don't seem to be related to each other at all. One isn't the parent window of the other, so how are the windows linked together? And why is the non-UI window the one that gets the Windows taskbar button? Can any Delphi experts help me understand this?

+8  A: 

TApplication is the class that encapsulates your application and handles things like the Windows Messaging. TfrmMain will be a subclass of TForm which will be your Applications "Main Form".

So basically, TApplication is the controller so to speak and it owns and creates TfrmMain, and forwards messages to it, or any of it's children.

Look in your projectname.pas file and you'll see something like:

program Project1;
uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1};
{$R *.RES}
begin
  Application.Initialize;
  Application.CreateForm(TfrmMain, frmMain) ;
  Application.Run;
end.

where Application is of type TApplication.

KiwiBastard
Do you know how to get the TfrmMain's controller window handle using Win32 code (not from inside the Delphi application)? Strangely, the TfrmMain window doesn't appear to be owned by the TApplication window.
Jon Tackabury
I think you would have to use GetWIndowHandle(formcaption) or something like that
KiwiBastard
+1  A: 

With applications made with versions of Delphi BEFORE Delphi 2007, the "secret window" would be the visible window in Vista's Flip 3D or preview. Here's a great article explaining how to compile Delphi applications on Delphi 2006 (and earlier) so that the "secret window" is not shown: here

Mick