Keep window topmost in MDI application

I am creating an application that will display one or more MDI Child forms. I want to be able to display a Search form that will:
1. Be a child of the MDI parent form
2. Stay on top of the child forms
3. Not stay on  top of other applications that may be      running.  

I have tried the SetParent API call to achieve item 1, but when the Search form is unloaded, it also hides the toolbar on the MDI Main form.

I have also used SetWindowPos to achieve item 2, but the Search form remains on top of other applications.

I have also tried using Zorder in the activate and deactivate events on all forms, but the blinking that occurs is unacceptable.
LVL 1
kponderAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
JohnnConnect With a Mentor Commented:
I'm not really sure what seems to be wrong with what your doing.  As long as you reset the parent in the search form's unload event to 0, it shouldn't unload your toolbar.  Also, this window will always stay on top of the child windows without doing anything else.  My tests were in VB5.  I guess your try too hard?

Dim frmChild() As Child
Private Sub MDIForm_Load()
    Dim a%
    ReDim frmChild(1 To 5)
    For a = 1 To 5
        Set frmChild(a) = New Child
        Load frmChild(a)
        frmChild(a).Visible = True
    Next
    Load frmSearch
    SetParent frmSearch.hWnd, Me.hWnd
    frmSearch.Visible = True'set to false at design time to elminated any "flashing"
End Sub
'search form
Private Sub Form_Unload(Cancel As Integer)
    SetParent Me.hWnd, 0
End Sub

Hope that works for you
John
0
 
TimBusiness Systems AnalystCommented:
Try setting the search form to VBModal.  That should keep it on top of the other forms in your app and still allow other apps to run on top of it.
0
 
kponderAuthor Commented:
I have tried this but it is not a child of the MDI form. The Search form can't be allowed to go outside of the MDI form's borders.




0
 
kponderAuthor Commented:
Another point:  When the search form is displayed the user will also need to be able to access the MDI child forms.
0
 
JohnnCommented:
The reason my code works above is that we are setting the "find" windows parent to the actual MDI form, not the MDI form's client which is a totally different window.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.