TForms and z-order

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Post Reply
pedand
Active Poster
Active Poster
Posts: 16
Joined: Wed Jul 15, 2009 1:41 am

TForms and z-order

Post 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
User avatar
minas
BCBJ Guru
BCBJ Guru
Posts: 199
Joined: Sat Jul 10, 2004 6:09 am
Location: Greece

Re: TForms and z-order

Post 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.
pedand
Active Poster
Active Poster
Posts: 16
Joined: Wed Jul 15, 2009 1:41 am

Re: TForms and z-order

Post by pedand »

That works fine. I have learned somthing today!
Thanks minas
rlebeau
BCBJ Author
BCBJ Author
Posts: 1709
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA
Contact:

Re: TForms and z-order

Post 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+.
Last edited by rlebeau on Thu Nov 21, 2019 8:21 pm, edited 1 time in total.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
minas
BCBJ Guru
BCBJ Guru
Posts: 199
Joined: Sat Jul 10, 2004 6:09 am
Location: Greece

Re: TForms and z-order

Post 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."
rlebeau
BCBJ Author
BCBJ Author
Posts: 1709
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA
Contact:

Re: TForms and z-order

Post 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.
Remy Lebeau (TeamB)
Lebeau Software
pedand
Active Poster
Active Poster
Posts: 16
Joined: Wed Jul 15, 2009 1:41 am

Re: TForms and z-order

Post 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?
rlebeau
BCBJ Author
BCBJ Author
Posts: 1709
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA
Contact:

Re: TForms and z-order

Post 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.
Remy Lebeau (TeamB)
Lebeau Software
pedand
Active Poster
Active Poster
Posts: 16
Joined: Wed Jul 15, 2009 1:41 am

Re: TForms and z-order

Post 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.
Post Reply