Page 1 of 1

TForms and z-order

PostPosted: Mon Nov 18, 2019 9:09 am
by pedand
Hello,
I have a very simple VCL-program that has a main form and a second form that is managed from the main form using Show and Hide. That works fine. It was suggested that the second form should be placed behind the main form, ie only partly hidden, to make it a bit more usable. Also switching form should only require a click on the form. I thought that changing the z-order would be a simple thing but I always end up with the second form on top of the first form. I’ve tried BringToFront, SetWindowPos etc. but no progress. I must be doing something wrong, but what?
I'm using CPB 10.3.1.
Thanks

Re: TForms and z-order

PostPosted: Tue Nov 19, 2019 6:37 am
by minas
Set Application->MainFormOnTaskBar to false in your project's source file . Use menu Project->View Source. The "side effect" in this case is that the taskbar button of your application will use the Application's title instead of the mainform's title.

Re: TForms and z-order

PostPosted: Tue Nov 19, 2019 9:54 am
by pedand
That works fine. I have learned somthing today!
Thanks minas

Re: TForms and z-order

PostPosted: Thu Nov 21, 2019 8:19 pm
by rlebeau
pedand wrote:I thought that changing the z-order would be a simple thing but I always end up with the second form on top of the first form. I’ve tried BringToFront, SetWindowPos etc. but no progress. I must be doing something wrong, but what?


Check if the MainForm has been set as the second Form's PopupParent. If it is, that will affect z-ordering, as the MainForm's window will be the "owner" of the second Form's window (at the Win32 layer, not the VCL layer), and a window cannot go behind its owner window. For what you are attempting, the MainForm should NOT be set as the PopupParent.

minas wrote:The "side effect" in this case is that the taskbar button of your application will use the Application's title instead of the mainform's title.


That is not the only side effect that will happen. The MainFormOnTaskBar property is tied into a whole bunch of other VCL Form functionalities that it really had no business being integrated into in the first place, but it was. So turning it off may encounter other consequences on Vista+.

Re: TForms and z-order

PostPosted: Fri Nov 22, 2019 9:27 am
by minas
Do you mean as other side effects those mentioned in the documentation ?

"MainFormOnTaskBar must be True to use Windows Vista or Windows 7 Aero effects, including live taskbar thumbnails, Dynamic Windows, Windows Flip, and Windows Flip 3D."

Re: TForms and z-order

PostPosted: Fri Nov 22, 2019 5:28 pm
by rlebeau
minas wrote:Do you mean as other side effects those mentioned in the documentation ?


No. ShowMainFormOnTaskbar is also being used in the VCL's insides in places that are not documented.

Re: TForms and z-order

PostPosted: Mon Nov 25, 2019 3:36 am
by pedand
rlebeau wrote:
Check if the MainForm has been set as the second Form's PopupParent.

Both forms have no PopParent set and PopupMode = pmNone.
It seems that I can not get the desired effect (change z-order) without setting MainFormOnTaskBar=false.
Am I still missing something?

Re: TForms and z-order

PostPosted: Mon Nov 25, 2019 8:39 pm
by rlebeau
pedand wrote:Both forms have no PopParent set and PopupMode = pmNone.


That doesn't mean the MainForm can't still be getting set as the second Form's PopupParent, it could just be getting assigned implicitly by the VCL's internal logic, without updating the public properties themselves.

pedand wrote:It seems that I can not get the desired effect (change z-order) without setting MainFormOnTaskBar=false.


Yes, you can. It would just involve overriding the Form's CreateParams() or CreateWindowHandle() method to specify whichever HWND you want, to be the Form's owner window, such as the TApplication window.

Re: TForms and z-order

PostPosted: Tue Nov 26, 2019 9:51 am
by pedand
rlebeau wrote:Yes, you can. It would just involve overriding the Form's CreateParams() or CreateWindowHandle() method to specify whichever HWND you want, to be the Form's owner window, such as the TApplication window.

CreateParams() seems to give the effect I was looking for. Thanks.