Valhalla Legends Forums Archive | Visual Basic Programming | Flashing Form.

AuthorMessageTime
GoSu_KaOs
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.

[code]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[/code]

Help?
January 21, 2005, 5:24 AM
UserLoser.
[code]
Private Sub Form_Resize()
    If (WindowState <> vbMinimized) Then
        Timer1.Enabled = False
    End If
End Sub
[/code]
January 21, 2005, 6:25 AM
GoSu_KaOs
Did you even test this? dont work..
January 22, 2005, 2:11 PM
CrAz3D
UserLoser's suggestion would work if the bot is minimize & you change the Timer1.Enabled = False to = True instead, wouldn't it?
January 22, 2005, 4:58 PM
GoSu_KaOs
eh..

[quote]
I need the form to flash only when it losses focus. When the form gets focus, I need the flashing to stop.
[/quote]
January 23, 2005, 4:35 PM
CrAz3D
Check to see if the form has focus or not before flashing it?
January 23, 2005, 5:28 PM
Myndfyr
[quote author=GoSu_KaOs link=topic=10255.msg96291#msg96291 date=1106498103]
eh..

[quote]
I need the form to flash only when it losses focus. When the form gets focus, I need the flashing to stop.
[/quote]
[/quote]

When the form gains focus stop flashing it?
January 24, 2005, 5:45 PM
warz
[quote author=UserLoser link=topic=10255.msg95980#msg95980 date=1106288737]
[code]
Private Sub Form_Resize()
    If (WindowState <> vbMinimized) Then
        Timer1.Enabled = False
    End If
End Sub
[/code]
[/quote]

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.
January 25, 2005, 1:47 AM
Dyndrilliac
This should've been answered long ago.

[code]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[/code]
January 25, 2005, 2:45 AM
Grok
[code]
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
[/code]

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

[code]    FlashWin Me.hWnd, 10, 150[/code]
January 28, 2005, 5:10 PM
iNsaNe
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.
March 5, 2006, 10:54 PM

Search