home *** CD-ROM | disk | FTP | other *** search
- On Top
-
- This is a Visual Basic 2.0 project (should work in VB 1.0 but I didn't try it).
- The project demonstrates a way of keeping one form out of a group of forms on top
- while minimizing "flashing" and without changing the focus.
-
- The project keeps Form3 on top of Form1. This is accomplished by using the
- ShowWindow API call and "shadow" or "backing" forms. The backing forms
- are dummy forms that have the following property values:
-
- No Caption
- No border
- No Control Box (system menu)
- No Minimize button
- No Maximize button
-
- When a backing form is displayed by itself on the screen it looks like a white
- hole in the display (I assumed the default background color is white in this case).
- The backing forms track the position of another form and are always positioned
- under another form (or in back of another form). The purpose of the backing form
- is to trap the move messages of the top form. It does this because anytime the top
- form is moved, part of the bottom form is exposed and then we get a PAINT MESSAGE.
- This has the effect of converting the move message of the top form to a paint
- event in the bottom form. Of course the backing form immediatley sizes and moves
- it self to stay perfectly under the top form so that it can't be seen!
-
- This project has 4 forms and one module (*.BAS) file. The forms are called
-
- Form1.FRM
- Form2.FRM
- Form3.FRM
- Form4.FRM
- Module1.BAS
-
- To re-create the project, make four forms. Set the property valus of Form2.FRM
- and Form4.FRM as shown above for the "backing" forms. Copy the text to the
- appropriate events in the forms and *.bas file and go for it! Anytime you place
- Form1 on top of Form3, Form3 will come to the top .. but Form1 will still have
- the focus. Have fun!
-
- One note, the extra backing form (I think it is Form2) is a remnant of another
- experiment. This experiment made the position of two forms track. If you are
- interested let me know. It only takes a few lines of code.
-
- Jon Sigler
- 71631,776
-
- *********************** Form1 ****************************
-
- Option Explicit
-
- Sub Form_GotFocus ()
- Dim an_error As Integer
- Form4.Top = form1.Top
- Form4.Left = form1.Left
- Form4.Width = form1.Width
- Form4.Height = form1.Height
- If Intersection(form3, form1) Then
- an_error = ShowWindow(form3.hWnd, SW_SHOWNA)
- End If
- End Sub
-
- Sub Form_Load ()
- Form4.Show
- Form2.Show
- form3.Show
- End Sub
-
- Sub Form_Paint ()
- Cls
- Print "This form"
- Print "will not"
- Print "stay on"
- Print "of Form3."
- End Sub
-
- Sub Form_Resize ()
- Dim an_error As Integer
- Form4.Top = form1.Top
- Form4.Left = form1.Left
- Form4.Width = form1.Width
- Form4.Height = form1.Height
- If Intersection(form3, form1) Then
- an_error = ShowWindow(form3.hWnd, SW_SHOWNA)
- End If
- End Sub
-
- *********************** Form2 ****************************
-
- Option Explicit
-
- Sub Form_Paint ()
- Dim an_error As Integer
- Form2.Top = form3.Top
- Form2.Left = form3.Left
- Form2.Width = form3.Width
- Form2.Height = form3.Height
- If Intersection(form3, form1) Then
- an_error = ShowWindow(form3.hWnd, SW_SHOWNA)
- End If
- End Sub
-
- *********************** Form3 ****************************
- Option Explicit
-
- Sub Form_Paint ()
- Cls
- Print "This form"
- Print "will always"
- Print "stay on top"
- Print "of Form1."
- End Sub
-
- *********************** Form4 ****************************
- Option Explicit
-
- Sub Form_Paint ()
- Dim an_error As Integer
- Form4.Top = form1.Top
- Form4.Left = form1.Left
- Form4.Width = form1.Width
- Form4.Height = form1.Height
- If Intersection(form3, form1) Then
- an_error = ShowWindow(form3.hWnd, SW_SHOWNA)
- End If
- End Sub
-
- ********************** Module1 ***************************
- Option Explicit
-
- 'SW_SHOWNA
- Global Const SW_SHOWNA = 8
-
- 'ShowWindow
- Declare Function ShowWindow Lib "User" (ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer
-
- Function Intersection (FormA As Form, FormB As Form) As Integer
- 'this simply determines if an intersection exits between FormA and FormB
- If ((FormA.Left + FormA.Width) < FormB.Left) Then
- Intersection = False
- ElseIf ((FormB.Left + FormB.Width) < FormA.Left) Then
- Intersection = False
- ElseIf ((FormA.Top + FormA.Height) < FormB.Top) Then
- Intersection = False
- ElseIf ((FormB.Top + FormB.Height) < FormA.Top) Then
- Intersection = False
- Else
- Intersection = True
- End If
- End Function
-
-