View Single Post
  #1 (permalink)  
Old 08-21-2006, 06:48 AM
TcM's Avatar   
TcM TcM is offline
Code Warrior
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 8,323
Credits: 0
Rep Power: 69
TcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of light
Exclamation VB 6.0: Tutorial, How to Make Glass2K!!

Well I don't know if you people use Glass2k, Well I used it some time ago, but then I decided to make my own! Well in this tutorial I will show you how to make the basics of Glass2k not the whole app.

Requirements:-
  • Visual Basic (prefiribly 6.0)
  • Windows 2000/XP ( because Transparency will not work in other Win 95,98,ME and so! )
So open VB and the following will be shown:-



Select Standard EXE and Press Open.
You will be presented an empty Form.
Ok so now add a module. How? see the pic below:-



The following will be displayed:-



Now Press Open.
and paste the following code into the module:-

Code:
Option Explicit

Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const ULW_ALPHA = &H2
Private Const WS_EX_LAYERED = &H80000

Public Function MakeTransparent(ByVal hwnd As Long, Perc As Integer) As Long
Dim Msg As Long
On Error Resume Next
If Perc < 0 Or Perc > 255 Then
  MakeTransparent = 1
Else
  Msg = GetWindowLong(hwnd, GWL_EXSTYLE)
  Msg = Msg Or WS_EX_LAYERED
  SetWindowLong hwnd, GWL_EXSTYLE, Msg
  SetLayeredWindowAttributes hwnd, 0, Perc, LWA_ALPHA
  MakeTransparent = 0
End If
If Err Then
  MakeTransparent = 2
End If
End Function
This code is a Function to make a window Transparent
Ok so now what?
Now Add a Textbox ( Text1 ) and a Command Button ( Command1 )
and arrange the form the way you like I made it as follows:-



Now all we need to do is adding the following code to our project:-

Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub Command1_Click()
    Dim Handle As Long, Ret As Long
    Handle = FindWindow(vbNullString, Text1.Text)
    MakeTransparent Handle, 100
End Sub
Explaining the code:-
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Here we are declaring an API function to Find a Windows from the title bar

Code:
    Dim Handle As Long
Here we are just declaring a Variable

Code:
    Handle = FindWindow(vbNullString, Text1.Text)
Here we are assigning the variable with the API to find the window with the title bar same as the textbox ( text1 ) text that we added on out form.

Code:
    MakeTransparent Handle, 100
Here we are calling the Function of the module to make transparent the Var Handle, that we assigned to it the window, and 100 is the transparency level you want ex.
250 is solid ( normal window colour )
1 is invisible ( makes the wnidow invisible )
and the larger the no ( max 250 ) the more visible will the window be but still transparent until it is 250 ) so from 100 to 200 is the ideal value for a transparent window

Now how does this work?

Well run your app and open for example My Documents and in the Textbox write My Documents and then press the command button and the My Documents window will be transparent. Now to restore the window to its original color just close My Documents and Re-open it!

I want to make Transparent another window instead of My Documents, how?

Simple just type in the title of the window in the Textbox and press the command button!

Complete Source Code:-
Well I included the FULL source code its an attachment, its the complete project just compile and have fun

Ending:-

If you have any questions/problems/feedback pls post here and I will sureley Help you! Well this will make you only the selected window transparent not exactly like Glass2k but if you modify it you surely can make it
So I'm waiting for your feedback
Ow and if you want me to make you some tutorials request what you want and I will see what I can do! I will be happy making some tuts here!

Tcm9669
Attached Files To view attachments in this forum your post count must be 1 or greater. You currently have 0 posts.

Last edited by Jordan; 10-02-2006 at 12:45 PM. Reason: Picture Location Change
Reply With Quote

Sponsored Links