Create Translucent Forms
Animate How Forms Open and Close
Tile an Image Across a Form's Background

Starting with Windows 98 you can animate the way your forms are displayed and closed. The AnimateWindow API function allows you to have your form Slide in or out of view. You can make it slide in from the top, bottom, left, right or even along a diagonal. You can also make is collapse inward and expand outward from the center. In this sample I provide a few options that are used to animate the form when you close it.

Windows 2000 allows you to create forms that are translucent. In other words, whatever is underneath your form will show through. You can control the translucency of your form making more of what is under it show or making it completely opaque. For transparent forms, see my Clear Form page.

Using an image control and a simple loop, you can tile the image to cover the entire background of your form.

Tile Image Across a Form, Animate the way the form opens and closes, Make the window translucent.
Download Source Code

Applies To

The Animation effects are only available when running Windows 98, Windows 2000 or newer.

The Translucent effects are only available when running Windows 2000 or newer.

Translucent Forms

Win2K makes layered windows available for use. This program demonstrates the Alpha Blend type of layered window. Alpha blend is a method of combining images using pixel colors and their alpha values to combine every pixel of a layered window with the ones under it yielding a translucent effect.

You create a layered window by setting its WS_EX_LAYERED extended style bit. First you obtain the window's current style with a call to GetWindowLong using the GWL_EXSTYLE flag. The results of this are OR'd with WS_EX_LAYERED and then set with SetWindowLong.

Now you have a layered window and you need to set its translucency. The SetLayeredWindowAttributes API achieves this. You pass it the handle of your window, the LWA_ALPHA flag and the alpha value. The alpha value can range from 0 (completely invisible) to 255 (opaque). Your window must be a top level window. The program checks for this condition.

Animate a Form

In this example I added a single line in the Unload event to provide some cool closing effects.

Call AnimateWindow(Me.hwnd, 500, AW_SLIDE Or AW_VER_POSITIVE Or AW_HIDE)

Tile An Image

Create a form and add an Image control to it. Set the Image control's Visible property to False. Set its Picture property to the picture you want to tile. Pictures can be bitmaps, jpeg, gif files,.... anything supported by control. The Form's Auto-Redraw property must also be False.

   Private Sub Form_Paint()
     Dim X As Integer
     Dim Y As Integer
     '
     ' Note, the visible property of the image should be set false,
     ' and the Form's Auto-Redraw property must be False.
     '
     ' The Form_Paint event is used since it occurs whenever the Form
     ' is repainted (when the form is restored from minimized form, form
     ' has been resized, maximized etc.)
     '
     For X = 0 To Me.Width Step Image1.Width
        For Y = 0 To Me.Height Step Image1.Height
           PaintPicture Image1, X, Y
        Next
     Next
End Sub

Instructions

Run the program and resize the form to see your image tiled to fill the form. Select one of the animation effects and then close the form.

Click the Make Translucent and Make Opaque labels to see the effects. Change the setting in the lblMake_Click event to vary how translucent or opaque the form is.




About TheScarms
About TheScarms


Sample code
version info

If you use this code, please mention "www.TheScarms.com"

Email this page


© Copyright 2024 TheScarms
Goto top of page