Non Modal form over a modal form

Is there a way to show a non modal form on a modal form. I've been trying this for long and I am not able to get to a solution. This is really required for me.

Thanks in advance.
SaradhiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mcriderCommented:
The whole purpose of a modal form is to prevent input into other forms before the modal form is released...

Unfortunately, the only way to show a non-modal form while a modal form is showing is to launch another instanciation of your program.

You can communicate between the instanciations via GetSetting/SaveSetting...


Cheers!

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
caraf_gCommented:
Saradhi,

Displaying a non modal form on top of a modal form is impossible. It can not be done. mcrider explains quite well why.

If it is really required for you, there is only ONE solution. Change the requirement.

First of all, you're trying to solve a problem, I guess, to do with user interaction. Now, you've thought of a way to solve it which requires you to show a non-modal form on top of a modal one. But I bet you anything, that is not the only way it can be achieved. Think functionality, not problem. Think laterally...

If the "non-modal form on top of modal form" is the only possible solution to your problem, try to work around the restrictions...

One solution is to make your modal form non modal. This can be achieved quite easily, without losing too much of the "modal" look and feel. Even though the form is non-modal, the user thinks they're looking at a modal form... You can then quite happily display a non-modal form on top of the non-modal form formerly known as the modal form. <pun intended>

mcrider's idea is another possibility, but a more elegant way of doing this is to encapsulate your non-modal form in an ActiveX .exe, rather than having the same (full) application start up twice.

If any of the ideas sound workable to you, let me know.
0
Bob LearnedCommented:
You might want to try to temporarily make the non-modal form Always On Top.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

SaradhiAuthor Commented:
Well Mr. Caraf Q.,

 I didn't post this answer just for fun. I din't think you have to talk about thinking laterally blablabla...

I know that I can act on the restrictions. But, what I want is whether I can solve the problem or not, not looking for alternatives.

I have seen many applications doing this and also I have heard about doing this in some site but I couldn't just remember.

My problem goes like. I have a Settings form show on the main form modally. My problem is, I have a list box and I have to show different descriptions in a seperate window when the listbox selection is changed. Now I don't want to show this window modally. Whenever I chage the selection the contents of the window have to change.

Well if you have any there good alternatives please tell me.
0
caraf_gCommented:
"But, what I want is whether I can solve the problem or not"

In that case, the answer is very straight forward. No. You can't show a non-modal form on top of a modal form.

"I have seen many applications doing this". No you have not. You might think that that is what they are doing, but they are not. Repeat: you can NOT show a non-modal form on top of a modal one.

"Well if you have any there good alternatives please tell me"
Yes. When you show the settings form, show it modelessly. But disable the main form. That way your users will be none the wiser.

Here's how to do it. Create a VB project with two standard forms, Form1 and Form2.

Form1 contains one command button, Command1

Paste the following code into Form1
Option Explicit
Private WithEvents objForm2 As Form2
Private Sub Command1_Click()

Enabled = False
Set objForm2 = New Form2
objForm2.Show vbModeless, Me

End Sub

Private Sub objForm2_Unloading()

Enabled = True

End Sub


Paste the following code into Form2
Option Explicit
Public Event Unloading()
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

RaiseEvent Unloading

End Sub



Run the project. When you click the command button, form2 will be displayed.

Form2 is displayed modally, but you won't know that. AFAYK, the form is displayed modally. You can't click on Form1

But because Form2 is now displayed modelessly, you can display another modeless form on top of Form2

Enjoy.
0
caraf_gCommented:
PS - the font used in Experts-Exchange is to blame for this, but my profile is actually caraf_g
0
caraf_gCommented:
Oops, erratum.

"Form2 is displayed modelessly, but you won't know that. AFAYK, the form is displayed modally. You can't click on Form1 "
0
caraf_gCommented:
In your case, the Main form is equivalent to Form1, and the Settings form is equivalent to Form2

Hope this helps
0
Bob LearnedCommented:
I beg to differ about AlwaysOnTop and modal forms.

I you want to show a form always on top:

Private Const HWND_TOPMOST = &HFFFFFFFF
Private Const HWND_NOTOPMOST = &HFFFFFFFE
Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1

Private Declare Function SetWindowPos Lib "user32" _
   (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Sub SetTopmostWindow(ByVal hwnd As Long, Optional bTopmost As Boolean = True)
   
   If bTopmost Then
      SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
   Else
      SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
   End If
   
End Sub

The form will be above even modal forms.  It is true, though, that you will not be able to activate this form, or do anything with it (since it is non-modal), but the form will still be above any other form in the Z-Order.

But this strategy will work if you want to show a non-modal form above a modal form.  You will have to show the non-modal form first.
0
caraf_gCommented:
Interesting suggestion, but not very nice. The user won't even be able to move the window...
0
mcriderCommented:
Something else truely annoying about "Always on top"...

If you get an error, you can't see the error msgbox and your app "appears" to freeze...


Cheers!
0
caraf_gCommented:
Yes.. that too. :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.