I am trying to get the window handles to a Delphi application from an external application. I can see that there are a few windows created (TApplication, TFrmMain and a few others), and I know that TApplication is the “controller”, but never visible. However, can I read what the value for the real window is? I know that it is TFrmMain (for this specific application), but is it possible to actually figure this out somehow? Is the information stored in the window properties,or somewhere else? Thanks!
Share
No, there is no documented way to discover which of the windows represents
Application.MainFormfrom outside the application. In newer versions of Delphi, the main form’s window handle isn’t necessarilyApplication.MainForm.Handleanyway; applications can handle theOnGetMainFormHandleevent to return whatever they want — that’s used for choosing the parent window for modal dialogs.You can guess by looking for windows with “main” in their class names, but even if you find one, there’s no guarantee that there’s only one instance of it. Applications can have multiple top-level windows, in which case it doesn’t make much sense to designate any one of them as the “main” one.