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
TForms and z-order
Moderator: 2ffat
Re: TForms and z-order
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
That works fine. I have learned somthing today!
Thanks minas
Thanks minas
Re: TForms and z-order
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.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?
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+.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.
Last edited by rlebeau on Thu Nov 21, 2019 8:21 pm, edited 1 time in total.
Remy Lebeau (TeamB)
Lebeau Software
Lebeau Software
Re: TForms and z-order
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."
"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
No. ShowMainFormOnTaskbar is also being used in the VCL's insides in places that are not documented.minas wrote:Do you mean as other side effects those mentioned in the documentation ?
Remy Lebeau (TeamB)
Lebeau Software
Lebeau Software
Re: TForms and z-order
Both forms have no PopParent set and PopupMode = pmNone.rlebeau wrote:
Check if the MainForm has been set as the second Form's PopupParent.
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
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:Both forms have no PopParent set and PopupMode = pmNone.
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.pedand wrote:It seems that I can not get the desired effect (change z-order) without setting MainFormOnTaskBar=false.
Remy Lebeau (TeamB)
Lebeau Software
Lebeau Software
Re: TForms and z-order
CreateParams() seems to give the effect I was looking for. Thanks.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.