Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: GoSu_KaOs on January 20, 2005, 11:24 PM

Title: Flashing Form.
Post by: GoSu_KaOs on January 20, 2005, 11:24 PM
I need the form to flash only when it losses focus. When the form gets focus, I need the flashing to stop. I cant get this to work.

Private Declare Function FlashWindow Lib "user32" (ByVal hWnd As Long, ByVal bInvert As Long) As Long

Private Sub Form_GotFocus()
timer1.enabled = false
End Sub

Private Sub Form_LostFocus()
Timer1.Enabled = True
End Sub

Private Sub Command1_Click()
timer1.enabled = true
End If

Private Sub timer1_timer()
FlashWindow hWnd, 1
End Sub


Help?
Title: Re: Flashing Form.
Post by: UserLoser. on January 21, 2005, 12:25 AM

Private Sub Form_Resize()
    If (WindowState <> vbMinimized) Then
        Timer1.Enabled = False
    End If
End Sub
Title: Re: Flashing Form.
Post by: GoSu_KaOs on January 22, 2005, 08:11 AM
Did you even test this? dont work..
Title: Re: Flashing Form.
Post by: CrAz3D on January 22, 2005, 10:58 AM
UserLoser's suggestion would work if the bot is minimize & you change the Timer1.Enabled = False to = True instead, wouldn't it?
Title: Re: Flashing Form.
Post by: GoSu_KaOs on January 23, 2005, 10:35 AM
eh..

Quote
I need the form to flash only when it losses focus. When the form gets focus, I need the flashing to stop.
Title: Re: Flashing Form.
Post by: CrAz3D on January 23, 2005, 11:28 AM
Check to see if the form has focus or not before flashing it?
Title: Re: Flashing Form.
Post by: MyndFyre on January 24, 2005, 11:45 AM
Quote from: GoSu_KaOs on January 23, 2005, 10:35 AM
eh..

Quote
I need the form to flash only when it losses focus. When the form gets focus, I need the flashing to stop.

When the form gains focus stop flashing it?
Title: Re: Flashing Form.
Post by: warz on January 24, 2005, 07:47 PM
Quote from: UserLoser on January 21, 2005, 12:25 AM

Private Sub Form_Resize()
    If (WindowState <> vbMinimized) Then
        Timer1.Enabled = False
    End If
End Sub


This should work.  Remember to begin the flashing though when you minimize it. All this code does is check to see if the window is not minimized, and if it isn't, it disabled the flash timer.
Title: Re: Flashing Form.
Post by: Dyndrilliac on January 24, 2005, 08:45 PM
This should've been answered long ago.

Public HasFocus as Boolean
Public Declare Function FlashWindow Lib "user32" (ByVal hWnd As Long, ByVal bInvert As Long) As Long

Private Sub Form_GotFocus()
    HasFocus = True
End Sub

Private Sub Form_LostFocus()
    HasFocus = False
End Sub

Private Sub tmrIdle_Timer()
    If HasFocus = False Then
        FlashWindow Me.hWnd, 1
    End If
End Sub
Title: Re: Flashing Form.
Post by: Grok on January 28, 2005, 11:10 AM

Public Const FLASHW_STOP = 0
Public Const FLASHW_CAPTION = &H1
Public Const FLASHW_TRAY = &H2
Public Const FLASHW_ALL = (FLASHW_CAPTION + FLASHW_TRAY)
Public Const FLASHW_TIMER = &H4
Public Const FLASHW_TIMERNOFG = &HC

Public Type FLASHWINFO
    cbSize As Long
    hWnd As Long
    dwFlags As Long
    uCount As Long
    dwTimeout As Long
End Type
Public Declare Function FlashWindowEx Lib "user32" (lpFWI As FLASHWINFO) As Long

'-------------------------------------------------------------------
'FlashWin procedure flashes the given window a number of times at some rate.
'-------------------------------------------------------------------
Private Function FlashWin(ByVal pWnd As Long, ByVal pCount As Long, ByVal pTimeout As Long) As Long
   
    Dim pFW As FLASHWINFO
   
    pFW.cbSize = Len(pFW)
    pFW.dwFlags = FLASHW_ALL
    pFW.dwTimeout = pTimeout
    pFW.hWnd = pWnd
    pFW.uCount = pCount
    FlashWin = FlashWindowEx(pFW)
   
End Function


EXAMPLE USAGE -- flash current window 10 times at 150ms interval:

    FlashWin Me.hWnd, 10, 150
Title: Re: Flashing Form.
Post by: iNsaNe on March 05, 2006, 04:54 PM
Hmm... I had the code for this... except I forgot it.

Your code is wrong with the GetFocus and LostFocus

The code I had flashed the form when it had focus. It has nothing to do with getfocus or lostfocus.