Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Fade in & Fade out in VB6

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
SlangeN
Advanced Cheater
Reputation: 0

Joined: 22 Mar 2009
Posts: 55

PostPosted: Sat Mar 28, 2009 9:07 pm    Post subject: Fade in & Fade out in VB6 Reply with quote

Hi. Just wanted to ask if someone knowes how to do this?
I've searched on CEF a bit and didn't found any tutorial that either worked or was for VB6.

I found a script that worked to a certain point.
I managed to get 2 forms fade in when i wanted to (On Load), when i press on the Show Form2 button that one fades in also, as i've copied the code there too.
But here's the strange part. When i close Form 2 or switch focus, it fades in again. Same with Form2 when i switch to that one.

Here's the code i've used (Only modified (Timer - Delay) < 0.05 from < 0.01)

Code:
Const LWA_COLORKEY = &H1
Const LWA_ALPHA = &H2
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000
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 Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Private Sub Form_Activate()
Dim Alpha As Byte
Dim Delay As Single
Do
    Delay = Timer
    Do While (Timer - Delay) < 0.01
        DoEvents
    Loop
    Alpha = Alpha + 5
    SetLayeredWindowAttributes Me.hWnd, 0, Alpha, LWA_ALPHA
Loop Until Alpha = 255
End Sub

Private Sub Form_Load()
    Dim Ret As Long
    Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
    Ret = Ret Or WS_EX_LAYERED
    SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret
End Sub

I don't know if this is the easiest way of doing a fade in and fade out when Unload or when i exits the program.
Delphi had a way easier method, VB8 too, but not VB6 it seems.

I've heard that it's "easy" to recode a script from VB8 to VB6 as it's almost the same language?

Anyways, i'll attach a test file for you to play with if you want to see it in action.

Thanks in advance! Very Happy



The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.

Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sun Mar 29, 2009 6:21 am    Post subject: Reply with quote

how about AnimateWindow() ?
Back to top
View user's profile Send private message
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Sun Mar 29, 2009 6:24 am    Post subject: Reply with quote

Well, I don't know if this is VB6 (I don't code in VB), but I hope it solves your problem.
Put this at the top of your form class:
Code:

  Public Enum VisibilityTransition
        None = 0
        Fade
        FadeIn
    End Enum

    Dim visibility As VisibilityTransition = VisibilityTransition.None
    Dim fadeRate As Double = 0.01

    Private Sub StartTransition(ByVal rate As Double)
        fadeRate = rate
        If Me.Opacity = 0R Then
            visibility = VisibilityTransition.FadeIn
        ElseIf Me.Opacity = 1R Then
            visibility = VisibilityTransition.Fade
        End If
    End Sub



And this in the timer event:
Code:

   If visibility = VisibilityTransition.Fade Then
        If Me.Opacity > 0 Then
            Me.Opacity -= fadeRate
        Else
            visibility = VisibilityTransition.None
        End If
    ElseIf visibility = VisibilityTransition.FadeIn Then
        If Me.Opacity < 100 Then
            Me.Opacity += fadeRate
        Else
            visibility = VisibilityTransition.None
        End If
    End If


Call StartTransition with the desired rate whenever you want the form to fade/fade in.
Thanks to Developerfusion for the code converter.
Edit: Thoughtlessly used int instead of double.

_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren
Back to top
View user's profile Send private message MSN Messenger
SlangeN
Advanced Cheater
Reputation: 0

Joined: 22 Mar 2009
Posts: 55

PostPosted: Sun Mar 29, 2009 7:06 am    Post subject: Reply with quote

That code gives me plenty of errors. A bunch of statements that are missing or isn't implented. I don't really know how to use the timer event when the other code doens't have any timers =/.

Can't that code i have be "reconstructed" so that it doesn't fade in again after i set focus on that window?

Thanks for helping me Smile
Back to top
View user's profile Send private message
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Sun Mar 29, 2009 8:10 am    Post subject: Reply with quote

Could you post the errors? It might help solve your problem.
I attached a working example in C# that you could take a look at.



The Extension 'zip' was deactivated by an board admin, therefore this Attachment is not displayed.


_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren
Back to top
View user's profile Send private message MSN Messenger
SlangeN
Advanced Cheater
Reputation: 0

Joined: 22 Mar 2009
Posts: 55

PostPosted: Sun Mar 29, 2009 3:41 pm    Post subject: Reply with quote

Thanks Odecey for the example Smile... I don't use C# though but Visual Basic 6 Rolling Eyes.

The lines that are red is that were i have errors on.

Quote:
Public Enum VisibilityTransition
None = 0
Fade
FadeIn
End Enum

Dim visibility As VisibilityTransition = VisibilityTransition.None
Dim fadeRate As Double = 0.01


Private Sub StartTransition(ByVal rate As Double)
fadeRate = rate
If Me.Opacity = 0R Then
visibility = VisibilityTransition.FadeIn
Else
If Me.Opacity = 1R Then
visibility = VisibilityTransition.Fade
End If
End Sub
Back to top
View user's profile Send private message
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Sun Mar 29, 2009 5:14 pm    Post subject: Reply with quote

To be frank that wasn't what I meant. When I said "post the errors", I was referring to the actual error message the compiler gives you when you try to build the application. Based on the info you gave though, I'd say VB 6 might be using some other syntax when defining variables, are you sure that's how they are supposed to be declared? Regarding the two last lines I have no idea what could be wrong. Try removing the 'R' after the numbers.
_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren
Back to top
View user's profile Send private message MSN Messenger
92Garfield
I'm a spammer
Reputation: 57

Joined: 20 Dec 2007
Posts: 5871
Location: Banana Republic Germany

PostPosted: Sun Mar 29, 2009 10:04 pm    Post subject: Reply with quote

Just wanted to mention that VB don't knows -= and +=

you gotta use

Me.Opacity = me.opacity - fadeRate

_________________
Back to top
View user's profile Send private message
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Mon Mar 30, 2009 2:07 am    Post subject: Reply with quote

Try using the Form_Load() event instead of Form_Activate():
Code:

Const LWA_COLORKEY = &H1
Const LWA_ALPHA = &H2
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000
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 Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Private Sub Form_Load()
    Dim Ret As Long
    Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
    Ret = Ret Or WS_EX_LAYERED
    SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret
    Dim Alpha As Byte
    Dim Delay As Single
    Do
        Delay = Timer
        Do While (Timer - Delay) < 0.01
            DoEvents
        Loop
        Alpha = Alpha + 5
        SetLayeredWindowAttributes Me.hWnd, 0, Alpha, LWA_ALPHA
    Loop Until Alpha = 255
End Sub

_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren
Back to top
View user's profile Send private message MSN Messenger
SlangeN
Advanced Cheater
Reputation: 0

Joined: 22 Mar 2009
Posts: 55

PostPosted: Mon Mar 30, 2009 8:33 am    Post subject: Reply with quote

Thanks for all the posts. It helped a lot Smile. I got it to work finally with some timers and a module. If someone's interested, here's how i did it.

MODULE
Code:
Option Explicit

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

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 Declare Function SetLayeredWindowAttributes Lib _
"user32" (ByVal hWnd As Long, ByVal crKey As Long, _
ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Public Function TransForm(Form As Form, TransLevel As Byte) As Boolean
SetWindowLong Form.hWnd, GWL_EXSTYLE, WS_EX_LAYERED
SetLayeredWindowAttributes Form.hWnd, 0, TransLevel, LWA_ALPHA
TransForm = Err.LastDllError = 0
End Function


FORM
Code:
Option Explicit
Dim TLevel As Integer

Private Sub Command1_Click()
Timer1.Enabled = False
Timer2.Enabled = True
End Sub

Private Sub Form_Load()
Timer2.Enabled = False
TLevel = 5
TransForm Me, Val(TLevel)
End Sub

Private Sub Timer1_Timer()
TLevel = TLevel + 5
TransForm Me, Val(TLevel)

    If TLevel = 255 Then
        Timer1.Enabled = False
    End If
End Sub

Private Sub Timer2_Timer()
TLevel = TLevel - 5
TransForm Me, Val(TLevel)
    If TLevel = 5 Then
        Unload Me
    End If
End Sub


You need 2 Timers with interval = 5 and a Command button.
This can be changed though to whatever you like sort of.
Code:
Private Sub Command1_Click()
Timer1.Enabled = False
Timer2.Enabled = True
End Sub


to "Private Sub Picture1_Click()" or Image.
I tried to change the speed with changing all 5's on all scripts. It worked but sometimes it gives me an overload error. It's no big deal though, it's still nice with 5 Smile.

Thanks for all the answers Very Happy.
Back to top
View user's profile Send private message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Wed Apr 01, 2009 12:19 pm    Post subject: Reply with quote

Cant you just use 1 timer and a if statement?
_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites