3

I have a Delphi 6 application with multiple forms. One important characteristic of the form selected in the Compiler Options to be the main form is that when it is minimized, all other forms (windows) in the application are minimized, and conversely, when it is restored all other forms that were visible are restored.

I would like to switch that trait of the main form to another form of the application at runtime so it acts like the main form in that sense (minimize/restore leadership). Is there a Delphi technique, or a Windows API call, that will allow me to do this? If not, is there a way to have a secondary form emulate this behavior that won't cause more problems than it's worth?

Robert Oschler
  • 14,153
  • 18
  • 94
  • 227

1 Answers1

2

In fact what determines the behaviour you describe is the window owner. Note that I am using the Windows terminology rather than the VCL terminology. In Windows terms, the meaning of owner differs from the VCL meaning.

MSDN has this to say about window ownership:

An overlapped or pop-up window can be owned by another overlapped or pop-up window. Being owned places several constraints on a window.

  • An owned window is always above its owner in the z-order.
  • The system automatically destroys an owned window when its owner is destroyed.
  • An owned window is hidden when its owner is minimized.

So what you want to be able to control is the forms owners rather than what is the main form. The VCL does allow you to specify which form is the owner of any other form.

In order to control the owner of a VCL form you need to use the PopupMode and PopupParent properties.

MySecondaryForm.PopupMode := pmExplicit;
MySecondaryForm.PopupParent := MyOtherSecondaryForm;

At the moment, your code is probably using the default PopupMode of pmAuto. In this mode the active form is used as the form owner and that usually means that the main form is the ultimate owner of all secondary forms.

Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490