Form always on top

Hi, freaks

I have two forms, one main form and one child form. Both are normal forms (no mdi) and I set the one form as a child of the other with the Function:

Declare Function SetParent& Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long)

i = SetParent(CHildForm.hWnd, MainForm.hWnd)

So far, so good!

But now I want to force the child form always be on top of the main form. If I use the API-function

Declare Function SetWindowPos Lib "user32" (ByVal h&, ByVal hb&, ByVal x&, ByVal y&, ByVal cx&, ByVal cy&, ByVal f&) As Long

Public Function SetTopWindow(hWnd As Long, bState As Boolean) As Boolean
  If bState = True Then
    SetTopWindow = SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
  ElseIf bState = False Then
    SetTopWindow = SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
    Debug.Print "bState unbekannt."
    SetTopWindow = False
  End If
End Function

,my child window is tiny small.

Does anyone know what to do?

Plaese post only comments as long as I tell s.o. to post as an answer

Thanx in advance

Who is Participating?
DalinConnect With a Mentor Commented:
Just do this:
frmChild Show, frmMother
Option Explicit

'Constants for topmost.
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOACTIVATE = &H10
Public Const SWP_SHOWWINDOW = &H40

Public Declare Function SetWindowPos _
    Lib "user32" Alias "SetWindowPos" _
   (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

Option Explicit

Private Sub Form_Load()
  'typically called in the form load
   Call SetWindowPos(Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)

End Sub

cas1Author Commented:
Hi, Dalin, my good old adviser

If you would know how long I explaned my parent-child problem with forms in general (was another question) just to simply get this damned line of code, you would laugh out loud. This answers me that and my previous question entirely. I'm sorry for you that I can only credit you that points! I would be glad that if you could read my wish to first just post as an comment in future times... I have some unlocked questions that noone could answer me completely. This points are lost because after a question is answered I cannot delete it anymore to get the points back.

Best regards

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.