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?
Private Sub Form_Resize()
If (WindowState <> vbMinimized) Then
Timer1.Enabled = False
End If
End Sub
Did you even test this? dont work..
UserLoser's suggestion would work if the bot is minimize & you change the Timer1.Enabled = False to = True instead, wouldn't it?
eh..
Quote
I need the form to flash only when it losses focus. When the form gets focus, I need the flashing to stop.
Check to see if the form has focus or not before flashing it?
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?
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.
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
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
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.