Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: two forms, Form2 is always on top of Form1


This question is answered.


Permlink Replies: 2 - Last Post: Oct 2, 2014 4:22 PM Last Post By: chen zero Threads: [ Previous | Next ]
chen zero

Posts: 30
Registered: 5/26/00
two forms, Form2 is always on top of Form1  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 1, 2014 11:24 PM
Hello,
C++Builder XE, WinXP,
a default VCL app with two forms. when showing, Form2 is always on top of Form1 even Form2 is deactivated.

this can be reproduced by this:
1. new a default VCL app
2. add another form --- Form2
3. in Form1, drop a button, its click code is:
Form2->Show();
4. run the app, click the button, in WIN XP, the Form2 is always on top of Form1 even Form2 is deactivated.

both forms, the FormStyle is default, fsNormal

I found that this is maybe related to Application->MainFormOnTaskBar
in default, this value is set to true in project source code.
however, if I change this value to false, two forms become ok.

could you help on this?
Thanks!
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: two forms, Form2 is always on top of Form1
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 2, 2014 10:24 AM   in response to: chen zero in response to: chen zero
chen wrote:

a default VCL app with two forms. when showing, Form2 is always on top
of Form1 even Form2 is deactivated.

That happens if Form1 is set as Form2's parent window. By default, the TForm::PopupMode
property is set to pmNone. When the Application->MainFormOnTaskBar property
is true (which it is by default), PopupMode=pmNone uses the Application->MainForm's
window as the parent window (from the Win32 API's perspective, not the VCL's
perspective). A child window is always on top of its parent window.

This is by design, to deal with z-order issues and Vista+ taskbar issues.
If you don't want this behavior, you can set the Application->MainFormOnTaskBar
property to false (not recommended on Vista+, though) to force the Application->Handle
to be used as the parent window instead. All of the TForm::PopupMode values
(pnNone, pmAuto, and pmExplicit) ultimately use either Application->ActiveFormHandle
or Application->MainForm->Handle as the parent window when Application->MainFormOnTaskBar
is true, unless you use the Application->OnGetMainFormHandle event to specify
a different HWND (which may have subtle side effects), or use PopupMode=pmExplicit
and assign a specific Form (even a hidden one) to the TForm::PopupParent
property.

--
Remy Lebeau (TeamB)
chen zero

Posts: 30
Registered: 5/26/00
Re: two forms, Form2 is always on top of Form1  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 2, 2014 4:22 PM   in response to: chen zero in response to: chen zero
Remy, Thanks for the detailed info !
Regards,
chenzero
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02