TForms and z-order

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

TForms and z-order

Postby pedand » Mon Nov 18, 2019 9:09 am

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

Re: TForms and z-order

Postby minas » Tue Nov 19, 2019 6:37 am

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

Re: TForms and z-order

Postby pedand » Tue Nov 19, 2019 9:54 am

That works fine. I have learned somthing today!
Thanks minas
pedand
Active Poster
Active Poster
 
Posts: 16
Joined: Wed Jul 15, 2009 1:41 am

Re: TForms and z-order

Postby rlebeau » Thu Nov 21, 2019 8:19 pm

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

Re: TForms and z-order

Postby minas » Fri Nov 22, 2019 9:27 am

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

Re: TForms and z-order

Postby rlebeau » Fri Nov 22, 2019 5:28 pm

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
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1616
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: TForms and z-order

Postby pedand » Mon Nov 25, 2019 3:36 am

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

Re: TForms and z-order

Postby rlebeau » Mon Nov 25, 2019 8:39 pm

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
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1616
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: TForms and z-order

Postby pedand » Tue Nov 26, 2019 9:51 am

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


Return to Technical

Who is online

Users browsing this forum: No registered users and 11 guests

cron