April 14, 2001

Create transparent form

Following steps shows how to create a transparent form:

1. Create a new project in Visual Basic. Form1 is created by default. Set the form's Picture property to the ARCHES.BMP bitmap file (usually found in the \WINDOWS directory).

2. Add a Command Button control to Form1. Command1 is created by default. Set its Caption property to "Show Form".

3. Add the following code to the Click event for Command1:

Private Sub Command1_Click()
End Sub

4. From the Visual Basic Insert menu, select Form to create a new form. Form2 is created by default. Change the size of Form2 so that it is the same size as Form1. Position Form2 so that it is on top of Form1.

5. Add the following Constant and Declare statements to the General Declarations section of Form2 (note that the Declare statement must be typed as one single line of code):

Private Declare Function SetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal
nIndex As Integer, ByVal dwNewLong As Long) As Long
Const GWL_EXSTYLE = (-20)

6. Add the following code to the Form_Load event for Form2:

Private Sub Form_Load()
Dim Ret As Long
Ret = SetWindowLong(Form2.hWnd, GWL_EXSTYLE, WS_EX_TRANSPARENT)
End Sub