Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Form always on top

Posted on 1999-08-16
Medium Priority
Last Modified: 2008-02-20
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

Question by:cas1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 14

Expert Comment

ID: 1531558
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


Accepted Solution

Dalin earned 200 total points
ID: 1531559
Just do this:
frmChild Show, frmMother

Author Comment

ID: 1531560
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


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

670 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