What is TApplication.Handle ?
- Where is he from?
- Why does he exist?
- And most importantly: why do all forms have it as a handle to the parent window?
Help Delphi says:
TApplication.Handle
Provides access to the window handle of the main form (window) of the application.
property Handle: HWND;
Description
Use Handle when calling the Windows API functions requiring a parent handle window. For example, a DLL that displays its own top-level popup for windows requires a parent window to display its windows in an expression. Using the Handle property makes such windows part of the application so that they are minimized, restored, enabled, and disabled by the application.
If I focus on the words "window handle to the main form of the application," and I think it means the window handle to the main form of the application, then I can compare:
- "window handle of the main form of the application",
- window handle
MainForm Application
but they do not match:
Application.MainForm.Handle: 11473728 Application.Handle: 11079574
So what is Application.Handle ?
- Where is he from?
- What is Windows & reg; window handle?
- If Windows & reg; window handle
Application MainForm , then why they do not match? - If this is not a handle to the
Application MainForm window, then what is it? - More importantly: why is he the primary parent of each form?
- And most importantly: why does everything happen with haywire if I try to have a form that has no analogues (so that it can appear on the TaskBar) or try to use something like IProgressDialog?
Indeed, I ask: what is the design rationale that makes Application.Handle existing? If I can understand why, then how it should become obvious.
Refresh Understanding the game from twenty questions:
Saying that the decision to create a window appears on the taskbar, making its owner null , Peter Below said in 2000 :
This can cause some problems with modal forms shown on secondary forms.
If the user disconnects from the application, and the modal form is up and then back to the form that showed it, the modal form can hide under the form. This can be dealt with by making sure the modal form was born on the form that showed it (using `params.WndParent``, as mentioned above)
But this is not possible in the standard dialogs from the Dialogs block and exceptions that require more effort to make them work correctly (basically processing Application.OnActivate , looks for modal forms born for the Application through GetLastActivePopup and bringing them to the top of the Z-order through SetWindowPos ).
- Why does a modal form end with other forms?
- What mechanism usually brings the modal form to the fore and why doesn’t it work here?
- Window & reg; responsible for displaying window stacks. What went wrong with Windows & reg; doesn't show the correct windows?
He also talked about using the new advanced Windows style, which makes the window appear on the taskbar (when the usual rules of its irrelevance are insufficient, impractical or undesirable), adding the advanced style WS_EX_APPWINDOW
procedure TForm2.CreateParams(var Params: TCreateParams); begin inherited CreateParams( params ); Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW; end;
But then he warns:
If you click on the button of the taskbar of the secondary form, while another active application, it will still lead to the appearance of all forms of applications. if you do not want to have an option
Who brings all forms to the front when the form owner is still Application.Handle . Is this an app ? Why is he doing this? Instead, should this not be done? What the disadvantage is not ; I see a drawback to do (the system menu does not work properly, the thumbnails of the buttons on the taskbar are inaccurate, the Windows® shell cannot minimize windows.
In another Application post, Mike Edenfield says the parent window sends a message summary, maximization, and message recovery to another window :
This will add a taskbar button for your form, but there are still a few small details for the pen. Most obviously, your form still receives the reduction / maximization information that is sent to the parents of the form (main application form). To avoid this, you can set the message handler for WM_SYSCOMMAND by adding a line, for example:
procedure WMSysCommand(var Msg: TMessage); WM_SYSCOMMAND; procedure TParentForm.WMSysCommand(var Msg: TMessage); begin if Msg.wParam = SC_MINIMIZE then begin
Note that this handler is in the PARENT form of the one you want to keep independent of> the rest of the application in order to avoid sending a minimization message. You can add similar code for SC_MAXIMIZE, SC_RESTORE, etc.
How to minimize / maximize / restore messages for my Windows & reg; windows do not go to my window? This is because messages destined for the window are sent by Windows & reg; window owner? And in this case, all forms in the Delphi application "belong" to the Application ? Does this mean that the owner is null:
procedure TForm2.CreateParams(var Params: TCreateParams); begin inherited; Params.WndParent := 0; //NULL end;
will delete Application , and this Handle window due to interference in my form, and should Windows send me my messages mimimize / maximize / restore again?
Perhaps if we were comparing and comparing the “normal” Windows application now, this did the way Borland originally designed Delphi applications to do something — with respect to this Application object and its main loop.
- What solution was
Application ? - What changes were made in later versions of Delphi so that these same problems do not exist?
- Has the change in later versions of Delphi not changed other problems that were so much solved in the design of the application?
- How can these new applications work without an application blocking them?
Obviously, Borland realized the flaw in its original design. What was their initial design, what was the problem in solving it, what was the drawback, which was redesigned and how does it solve the problem?