[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Keeping Child of MDI on top of all forms

Posted on 2000-01-17
6
Medium Priority
?
160 Views
Last Modified: 2010-05-02
Is there a way to keep a child of an MDI on top of all other forms while it is open?  I don't think you can make them modal.  

Thanks a bunch.
0
Comment
Question by:jogmen
  • 2
  • 2
  • 2
6 Comments
 
LVL 1

Accepted Solution

by:
sunil27 earned 100 total points
ID: 2360933
You may the following procedure to do this. Note that this procedure 2 arguments: Form Name and a boolean value to specify whether you want the form on top or not.

Declare Function SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal dwX As Long, ByVal dwY As Long, ByVal dwCX As Long, ByVal dwCY As Long, ByVal wFlags As Long) As Long


Public Sub FormOnTop(argForm As Form, ByVal bTopmost As Boolean)

    Const SWP_NOSIZE = &H1
    Const SWP_NOMOVE = &H2
    Const HWND_TOPMOST = -1
    Const HWND_NOTOPMOST = -2

    Dim dwRet As Long, dwPos As Long

    If bTopmost Then
        dwPos = HWND_TOPMOST
    Else
        dwPos = HWND_NOTOPMOST
    End If

    dwRet = SetWindowPos(argForm.hWnd, dwPos, 0&, 0&, 0&, 0&, SWP_NOSIZE Or SWP_NOMOVE)

End Sub

' Now you can call this procedure to bring the form frmChild on top as follows:

Private Sub Commmand1_Click()

    FormOnTop frmChild, True

End Sub

0
 
LVL 6

Expert Comment

by:VBGuru
ID: 2362480
If you don't have any control or all the controls are disable on the form, then just put this piece of code

Private Sub Form_LostFocus()
SetFocus
End Sub

If you have controls on the forms then the lostfocus event of the form won't triggerd insted the lostfocus event of the control is triggered. So place the setfocus on the lostfocus event of all the control, it should work just fine.

If you want a global handler, then you have to do subclassing for the form.
0
 

Author Comment

by:jogmen
ID: 2363760
Neither of these solutions seem to work.

1.  The above code does not seem to work when choosing another child form.

2.  The setfocus event does not kick off when choosing another child form.

Any ideas?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 1

Expert Comment

by:sunil27
ID: 2365070
Jogmen,

In my answer I forgot to mention that using FormOnTop function (that I previously gave you) will keep the child form on top even when you click on the other form. The trick is to use that function as follows:

Private Sub Form_Load()
    ' Put the form topmost
    FormOnTop Me, True

    ' Now specify No Top argument in the next line which will allow you to bring the other child forms on top
    FormOnTop Me, False
End sub

Hope this would help.
0
 
LVL 6

Expert Comment

by:VBGuru
ID: 2365678
download the example from
http://www.geocities.com/vb4developer/lostfocus.zip

In the example it is always the form1 which remains on top always.
0
 

Author Comment

by:jogmen
ID: 2367838
sunil27,

The function provided does not keep a child form on top if i call it in my child form upon load then click on another open child form that form goes on top.

It doesn't really appear to do anything.  
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question