|
-
Dec 20th, 2005, 07:51 AM
#1
Thread Starter
PowerPoster
[STILL UNRESOLVED] destroy timer question
my splash screen fades in to display the splash screen and then after X seconds, it automatically closes and then displays the login form. i would like to destroy the timer (set = nothing). I have done this when the user clicks on the splash screen but where would I set it for when the form closes after X seconds? Would this be in Form_QueryUnload, Form_Terminate or Form_Unload??
Last edited by BrailleSchool; Dec 21st, 2005 at 03:26 AM.
-
Dec 20th, 2005, 08:01 AM
#2
Thread Starter
PowerPoster
Re: destroy timer question
seems i am doing it wrong because i am getting an error:
compile error:
invalid use of property
VB Code:
Private Sub imgSplash_Click()
'when the splash screen is clicked on, set the timer to nothing so that the
'login form doesnt haunt the end user
Set tmrSplash = Nothing ' <--------------------------errors here
frmLoginForm.Show
Unload Me
End Sub
complete code:
VB Code:
Option Explicit
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 As Long = (-20)
Private Const WS_EX_LAYERED As Long = &H80000
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 Const LWA_ALPHA As Long = &H2
Private lngForNum As Long
Private lngStyle As Long
Private bolActive As Boolean
Private Sub Form_Activate()
If Not bolActive Then
bolActive = True
For lngForNum = 10 To 255
MakeWindowTransparent Me.hwnd, lngForNum
DoEvents
Next
End If
End Sub
Private Sub Form_Load()
MakeWindowTransparent Me.hwnd, 10
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'when the splash screen is automatically closed, set the timer to nothing so that the
'login form doesnt haunt the end user
Set tmrSplash = Nothing
End Sub
Private Sub Form_Terminate()
'when the splash screen is clicked on, set the timer to nothing so that the
'login form doesnt haunt the end user
Set tmrSplash = Nothing
End Sub
Private Sub Form_Unload(Cancel As Integer)
'when the splash screen is clicked on, set the timer to nothing so that the
'login form doesnt haunt the end user
Set tmrSplash = Nothing
End Sub
Private Sub imgSplash_Click()
'when the splash screen is clicked on, set the timer to nothing so that the
'login form doesnt haunt the end user
Set tmrSplash = Nothing
frmLoginForm.Show
Unload Me
End Sub
Public Sub MakeWindowTransparent(ByVal lngHwnd As Long, _
ByVal bytRate As Byte)
lngStyle = GetWindowLong(lngHwnd, GWL_EXSTYLE)
lngStyle = lngStyle Or WS_EX_LAYERED
SetWindowLong lngHwnd, GWL_EXSTYLE, lngStyle
SetLayeredWindowAttributes lngHwnd, 0, bytRate, LWA_ALPHA
End Sub
Private Sub tmrSplash_Timer()
frmLoginForm.Show
tmrSplash.Enabled = False
Unload Me
End Sub
-
Dec 20th, 2005, 08:14 AM
#3
Re: destroy timer question
I wouldn't think you would need to set a control to nothing. That is done with objects (assuming tmrSplash is a VB timer control.)
I believe this is what is causing the "Invalid use of Property"
-
Dec 20th, 2005, 08:17 AM
#4
Thread Starter
PowerPoster
Re: destroy timer question
yes, its a vb timer control. the problem i am having is when i am in my app after login, the damned login screen will just popup. i thought it might have been the timer that was doing it. everywhere else in my app where frmLoginForm is called from is within a click event so it couldnt be those, and also form_unload events so couldnt be that either. need to figure out why the damned login form is haunting me, lol.
-
Dec 20th, 2005, 08:25 AM
#5
Re: destroy timer question
In the QueryUnload event of your splash form, I would check to see if frmLogin has already been loaded.
If so, do nothing. If not, then load it.
-
Dec 20th, 2005, 08:27 AM
#6
Thread Starter
PowerPoster
Re: destroy timer question
the login form isnt loaded until the splash form is either clicked on or automatically closed by the timer. when i am in the MDI parent, the login form is haunting me. thats why i am wondering where it is coming from, but alas, cannot figure out where its coming from.
-
Dec 20th, 2005, 08:31 AM
#7
Re: destroy timer question
 Originally Posted by BrailleSchool
the login form isnt loaded until the splash form is either clicked on or automatically closed by the timer. when i am in the MDI parent, the login form is haunting me. thats why i am wondering where it is coming from, but alas, cannot figure out where its coming from.
Well, it can only be loaded after an explicit .Show has been performed. So, take a look at every place in your code where it says frmLogin.Show
That is where it is coming from.
-
Dec 20th, 2005, 08:39 AM
#8
Thread Starter
PowerPoster
Re: destroy timer question
 Originally Posted by Hack
Well, it can only be loaded after an explicit .Show has been performed. So, take a look at every place in your code where it says frmLogin.Show
That is where it is coming from.
These are the places its coming from.
frmAccessDenied = Form_Unload
frmAccessDenied = cmdAccessDeniedOK_Click()
frmInternalSplash = Private Sub cmdLogout_Click()
frmMain = MDIForm_Unload
frmMain = Private Sub mnuLogout_Click() (MDI Form)
frmSplash = Private Sub imgSplash_Click()
frmSplash = Private Sub tmrSplash_Timer()
frmAccountDisabled = Private Sub cmdAccountDisabledOK_Click()
frmAccountDisabled = Private Sub Form_Unload
Last edited by BrailleSchool; Dec 20th, 2005 at 08:43 AM.
-
Dec 20th, 2005, 08:49 AM
#9
Re: destroy timer question
Is frmSplash your startup form, or is that called from somewhere else?
Is this issue with the login form happening only at startup time, or periodically, throughout the application?
-
Dec 20th, 2005, 08:54 AM
#10
Hyperactive Member
Re: destroy timer question
Here's your new code... all I did was comment out the Bold lines... and it worked properly for me...
VB Code:
Option Explicit
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 As Long = (-20)
Private Const WS_EX_LAYERED As Long = &H80000
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 Const LWA_ALPHA As Long = &H2
Private lngForNum As Long
Private lngStyle As Long
Private bolActive As Boolean
Private Sub Form_Activate()
If Not bolActive Then
bolActive = True
For lngForNum = 10 To 255
MakeWindowTransparent Me.hwnd, lngForNum
DoEvents
Next
End If
End Sub
Private Sub Form_Load()
MakeWindowTransparent Me.hwnd, 10
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'when the splash screen is automatically closed, set the timer to nothing so that the
'login form doesnt haunt the end user
[B]Set tmrSplash = Nothing[/B]
End Sub
Private Sub Form_Terminate()
'when the splash screen is clicked on, set the timer to nothing so that the
'login form doesnt haunt the end user
[B]Set tmrSplash = Nothing[/B]
End Sub
Private Sub Form_Unload(Cancel As Integer)
'when the splash screen is clicked on, set the timer to nothing so that the
'login form doesnt haunt the end user
[B]Set tmrSplash = Nothing[/B]
End Sub
Private Sub imgSplash_Click()
'when the splash screen is clicked on, set the timer to nothing so that the
'login form doesnt haunt the end user
[B]Set tmrSplash = Nothing[/B]
frmLoginForm.Show
Unload Me
End Sub
Public Sub MakeWindowTransparent(ByVal lngHwnd As Long, _
ByVal bytRate As Byte)
lngStyle = GetWindowLong(lngHwnd, GWL_EXSTYLE)
lngStyle = lngStyle Or WS_EX_LAYERED
SetWindowLong lngHwnd, GWL_EXSTYLE, lngStyle
SetLayeredWindowAttributes lngHwnd, 0, bytRate, LWA_ALPHA
End Sub
Private Sub tmrSplash_Timer()
frmLoginForm.Show
tmrSplash.Enabled = False
Unload Me
End Sub
Make sure you have no references made to the splash form on your login form or any other subsequent form... cause this will cause the splash for to be loaded again...
Plus I would put the entire code for the fade effect in a module, including the declarations and just have a function to it... that way the form doesn't reopen if you were to call eg. frmSplash.GetWindowLong...
If my post has been helpful, then please rate it accordingly...
If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.
-
Dec 20th, 2005, 08:56 AM
#11
Thread Starter
PowerPoster
Re: destroy timer question
 Originally Posted by Hack
Is frmSplash your startup form, or is that called from somewhere else?
Is this issue with the login form happening only at startup time, or periodically, throughout the application?
when you click on the exe icon (on desktop), frmSplash is loaded, then if the user clicks on frmSplash then frmLoginForm is loaded, otherwise frmLoginForm is loaded when the timer reaches its limit and closes frmSplash. Then when the user logins in and the information is wrong, frmAccessDenied comes up. if the account has been disabled (either by an admin or entering wrong info 4x) then frmAccountDisabled is shown. But this is where I am having the problem (when the frmLoginForm is haunting me...) frmMain is the MDI form and I am using an internal form to show buttons called frmInternalSplash, so I am thinking it has to be either frmMain or frmInternalSplash (i am not sure if its the timer on frmSplash.) So least I have narrowed it down to 3 of the forms. However, the .Show is within a click event of cmdLogout (frmInternalSplash) or mnuLogout within frmMain, and of course the MDIForm_Unload event when the red X is clicked on.
-
Dec 20th, 2005, 09:09 AM
#12
-
Dec 20th, 2005, 09:56 AM
#13
Hyperactive Member
Re: destroy timer question
Is frmSplash and frmLogin an MDI Child form... cause if it is then that could be where your problem lies...
Check the AutoShowChildren property and make sure it's enabled to false...
If my post has been helpful, then please rate it accordingly...
If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.
-
Dec 20th, 2005, 01:23 PM
#14
Thread Starter
PowerPoster
Re: destroy timer question
 Originally Posted by Protocol
Is frmSplash and frmLogin an MDI Child form... cause if it is then that could be where your problem lies...
Check the AutoShowChildren property and make sure it's enabled to false...
no, they are regular forms outside the MDI
-
Dec 20th, 2005, 01:27 PM
#15
Re: destroy timer question
Try something like this and see if it works.
Create a public boolean. Something like IsLoggedIn.
After a successful log, set the Boolean to true, and then in every place where frmLogin can be called, prior to calling it, check the state of this Boolean. If it is true, then don't do a .Show
You may need to reset it to False in other places like frmAccessDenied, or whatever. I'm not familiar with exacly how your app works, but this approach may help you out.
-
Dec 20th, 2005, 01:36 PM
#16
Thread Starter
PowerPoster
Re: destroy timer question
 Originally Posted by Hack
Try something like this and see if it works.
Create a public boolean. Something like IsLoggedIn.
After a successful log, set the Boolean to true, and then in every place where frmLogin can be called, prior to calling it, check the state of this Boolean. If it is true, then don't do a .Show
You may need to reset it to False in other places like frmAccessDenied, or whatever. I'm not familiar with exacly how your app works, but this approach may help you out.
Ill try it and see what happens. havent done much with flags before
-
Dec 20th, 2005, 01:40 PM
#17
Thread Starter
PowerPoster
Re: destroy timer question
frmAccessDenied is a form that is used like a message box to tell end user that login details are wrong. Same for frmAccountDisabled. I dislike the look of the MsgBox so use forms in their place to make them a little nicer in appearance.
-
Dec 21st, 2005, 01:44 AM
#18
Thread Starter
PowerPoster
Re: destroy timer question
ok, i set the IsLoggedIn to true or false and the frmLoginForm hasnt haunted me yet, let's see if it stays that way. will report back if it doesn't. hope the ghost has been laid to rest. hehehe.
-
Dec 21st, 2005, 03:25 AM
#19
Thread Starter
PowerPoster
Re: destroy timer question
unfortunately, no change. the login form still haunts me.
-
Dec 21st, 2005, 06:53 AM
#20
Re: destroy timer question
 Originally Posted by BrailleSchool
unfortunately, no change. the login form still haunts me.
Is the problem still coming from one of the three forms that mentioned previously?
-
Dec 21st, 2005, 07:00 AM
#21
Re: [STILL UNRESOLVED] destroy timer question
I don't understand why you can't just set .Enabled to False ?
-
Dec 21st, 2005, 07:04 AM
#22
Re: [STILL UNRESOLVED] destroy timer question
 Originally Posted by penagate
I don't understand why you can't just set .Enabled to False ?
Set .Enabled to False for what control?
-
Dec 21st, 2005, 07:09 AM
#23
Re: [STILL UNRESOLVED] destroy timer question
The Timer. I don't understand why you need a timer for this anyway, maybe I'm being thick.
-
Dec 21st, 2005, 07:13 AM
#24
Re: [STILL UNRESOLVED] destroy timer question
 Originally Posted by penagate
The Timer. I don't understand why you need a timer for this anyway, maybe I'm being thick.
No, you aren't thick...he wants to provide two ways of opening his app from the splash screen.
1. The traditional way of just clicking an Ok button on the splash screen.
2. If nothing is done within X amount of time, the splash screen closes all by itself and calls his login form...hence the use of the timer.
-
Dec 21st, 2005, 07:22 AM
#25
Re: [STILL UNRESOLVED] destroy timer question
 Originally Posted by Hack
No, you aren't thick...he wants to provide two ways of opening his app from the splash screen.
1. The traditional way of just clicking an Ok button on the splash screen.
2. If nothing is done within X amount of time, the splash screen closes all by itself and calls his login form...hence the use of the timer.
so cant it be like this:
-the splash screen is loaded and it fires the timer.
-let the timer do its work until user clicks the button.
-if the user clicks the button before the time (of the timer) completes, then disable the timer.
or am i saying something wrong?
-
Dec 21st, 2005, 07:30 AM
#26
Member
Re: [STILL UNRESOLVED] destroy timer question
From the code provided, it seems that the timer is being disabled in the timer event, and not the click event.
From my limited experience, I have found that the timer is activated anytime a control, sub, or any event is triggered on the form that the timer resides.
I suggest disabling the timer in the click event, timer event, and the form unload event.
-
Dec 21st, 2005, 07:41 AM
#27
Thread Starter
PowerPoster
Re: destroy timer question
 Originally Posted by Hack
Is the problem still coming from one of the three forms that mentioned previously?
Yes, because those forms are the only places where frmLoginForm is shown (unload and click events)
-
Dec 21st, 2005, 07:42 AM
#28
Thread Starter
PowerPoster
Re: [STILL UNRESOLVED] destroy timer question
 Originally Posted by Hack
No, you aren't thick...he wants to provide two ways of opening his app from the splash screen.
1. The traditional way of just clicking an Ok button on the splash screen.
2. If nothing is done within X amount of time, the splash screen closes all by itself and calls his login form...hence the use of the timer.
exactly. however, i dont have a button on the splash screen, the splash image is in a picturebox and when the image/picure box is clicked, it closes the splash screen and calls the login form
-
Dec 21st, 2005, 07:43 AM
#29
Junior Member
Re: [STILL UNRESOLVED] destroy timer question
 Originally Posted by Hack
No, you aren't thick...he wants to provide two ways of opening his app from the splash screen.
1. The traditional way of just clicking an Ok button on the splash screen.
2. If nothing is done within X amount of time, the splash screen closes all by itself and calls his login form...hence the use of the timer.
it's right, I think there are something missing, and i think it's a little problem, he should zip the project and send it, to see the whole functions
-
Dec 21st, 2005, 07:45 AM
#30
Re: destroy timer question
 Originally Posted by BrailleSchool
Yes, because those forms are the only places where frmLoginForm is shown (unload and click events)
And you have incorporate the boolean flag, especially in the .Show on these three forms, right?
If so, then somehow that boolean is getting reset to False when it hits one of them.
I'm almost afraid to ask this question because I just know you are going to say: No ....but I gotta ask anyway....is there any consistent pattern to when your login form shows up uninvited?
-
Dec 21st, 2005, 07:45 AM
#31
Thread Starter
PowerPoster
Re: [STILL UNRESOLVED] destroy timer question
 Originally Posted by zeusspider
From the code provided, it seems that the timer is being disabled in the timer event, and not the click event.
From my limited experience, I have found that the timer is activated anytime a control, sub, or any event is triggered on the form that the timer resides.
I suggest disabling the timer in the click event, timer event, and the form unload event.
This is what I have so far for frmSplash
VB Code:
Option Explicit
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 As Long = (-20)
Private Const WS_EX_LAYERED As Long = &H80000
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 Const LWA_ALPHA As Long = &H2
Private lngForNum As Long
Private lngStyle As Long
Private bolActive As Boolean
Private Sub Form_Activate()
If Not bolActive Then
bolActive = True
For lngForNum = 10 To 255
MakeWindowTransparent Me.hwnd, lngForNum
DoEvents
Next
End If
End Sub
Private Sub Form_Load()
MakeWindowTransparent Me.hwnd, 10
End Sub
Private Sub imgSplash_Click()
IsLoggedIn = False
frmLoginForm.Show
tmrSplash.Enabled = False
Unload Me
End Sub
Public Sub MakeWindowTransparent(ByVal lngHwnd As Long, _
ByVal bytRate As Byte)
lngStyle = GetWindowLong(lngHwnd, GWL_EXSTYLE)
lngStyle = lngStyle Or WS_EX_LAYERED
SetWindowLong lngHwnd, GWL_EXSTYLE, lngStyle
SetLayeredWindowAttributes lngHwnd, 0, bytRate, LWA_ALPHA
End Sub
Private Sub tmrSplash_Timer()
IsLoggedIn = False
frmLoginForm.Show
Unload Me
End Sub
-
Dec 21st, 2005, 07:47 AM
#32
Thread Starter
PowerPoster
Re: destroy timer question
 Originally Posted by Hack
And you have incorporate the boolean flag, especially in the .Show on these three forms, right?
If so, then somehow that boolean is getting reset to False when it hits one of them.
I'm almost afraid to ask this question because I just know you are going to say: No ....but I gotta ask anyway....is there any consistent pattern to when your login form shows up uninvited?
I am not sure if I have setup the boolean flag correctly or not. I havent worked with boolean until the other day so i am very new to it.
-
Dec 21st, 2005, 07:50 AM
#33
Member
Re: [STILL UNRESOLVED] destroy timer question
Do you reference the spalsh screen or any subs/controls etc anywhere else in your project?
Try these changes:
VB Code:
Private Sub tmrSplash_Timer()
IsLoggedIn = False
tmrSplash.Enabled = False
frmLoginForm.Show
Unload Me
End Sub
Private Sub Form_UnLoad()
MakeWindowTransparent Me.hwnd, 10
tmrSplash.Enabled = False
End Sub
-
Dec 21st, 2005, 08:04 AM
#34
Thread Starter
PowerPoster
Re: [STILL UNRESOLVED] destroy timer question
 Originally Posted by zeusspider
Do you reference the spalsh screen or any subs/controls etc anywhere else in your project?
Try these changes:
VB Code:
Private Sub tmrSplash_Timer()
IsLoggedIn = False
tmrSplash.Enabled = False
frmLoginForm.Show
Unload Me
End Sub
Private Sub Form_UnLoad()
MakeWindowTransparent Me.hwnd, 10
tmrSplash.Enabled = False
End Sub
made the changes except for including MakeWindowTransparent Me.hwnd, 10
into the unload event because that part is what makes the form fade in and you cant fade in if the form is unloaded
-
Dec 21st, 2005, 08:09 AM
#35
Junior Member
Re: [STILL UNRESOLVED] destroy timer question
declare then in a module and make them public
-
Dec 21st, 2005, 08:16 AM
#36
Thread Starter
PowerPoster
Re: [STILL UNRESOLVED] destroy timer question
 Originally Posted by zeusspider
Do you reference the spalsh screen or any subs/controls etc anywhere else in your project?
Everything starts from Sub Main() and this is where the splash screen is started
Sub Main() looks like so:
VB Code:
Option Explicit
Public Sub Main()
If App.PrevInstance Then
Beep
frmAppAlreadyRunning.Show
IsLoggedIn = False
Else
If Not App.PrevInstance Then
If LenB(Dir("license.lic")) Then
frmSplash.Show
IsLoggedIn = False
ElseIf LenB(Dir("licence.lic")) = 0 Then
frmRegister.Show
IsLoggedIn = False
Else
End
End If
End If
End If
End Sub
-
Dec 21st, 2005, 08:25 AM
#37
Re: destroy timer question
 Originally Posted by BrailleSchool
I am not sure if I have setup the boolean flag correctly or not. I havent worked with boolean until the other day so i am very new to it.
Show me an example of how you are using it.
-
Dec 21st, 2005, 08:29 AM
#38
Junior Member
Re: [STILL UNRESOLVED] destroy timer question
man send all the project we already have this code
-
Dec 21st, 2005, 08:40 AM
#39
Thread Starter
PowerPoster
Re: [STILL UNRESOLVED] destroy timer question
 Originally Posted by TheMinime
man send all the project we already have this code
if i sent the project then it would check for the .lic file based on your hard drive volumn number
-
Dec 21st, 2005, 08:45 AM
#40
Junior Member
Re: [STILL UNRESOLVED] destroy timer question
I think I cant' comment the check code, it's not a big deal
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|