0

I can't seem to find the answer to this seemingly simple question anywhere D:

I want to detect if a form/window is focused so that I can only flash the window If Not Focused, here is the bit of the code:

If Me.Focused = False Then ' Doesn't work D: please fix
    Dim flash As New FLASHWINFO
    flash.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(flash) '/// size of structure in bytes
    flash.hwnd = MyBase.Handle '/// Handle to the window to be flashed
    flash.dwFlags = FLASHW_ALL '/// to flash both the caption bar + the tray
    flash.uCount = 5 '/// the number of flashes
    flash.dwTimeout = 1000 '/// speed of flashes in MilliSeconds ( can be left out )
    '/// flash the window you have specified the handle for...
    FlashWindowEx(flash)
End If

Is there a simple way to make this work?

Goulash
  • 3,708
  • 6
  • 29
  • 48
  • possible duplicate of [Determine Whether Program is the Active Window in .NET](http://stackoverflow.com/questions/893669/determine-whether-program-is-the-active-window-in-net) – Doc Brown Sep 17 '12 at 16:31
  • did you read answer #2? And even if that answer were not VB.NET but C#, that should not make a real difference. – Doc Brown Sep 17 '12 at 16:33
  • not when you're new to VB and not even met C# yet – Goulash Sep 17 '12 at 17:03
  • please, read the answers. Answer #1 is language-independent. Answer #2 shows you a ready-made VB.NET solution. So where is your problem? – Doc Brown Sep 18 '12 at 06:07

1 Answers1

0
  Private Sub Form1_LostFocus(sender As Object, e As System.EventArgs) Handles Me.LostFocus
    Dim flash As New FLASHWINFO
    flash.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(flash) '/// size of structure in bytes
    flash.hwnd = MyBase.Handle '/// Handle to the window to be flashed
    flash.dwFlags = FLASHW_ALL '/// to flash both the caption bar + the tray
    flash.uCount = 5 '/// the number of flashes
    flash.dwTimeout = 1000 '/// speed of flashes in MilliSeconds ( can be left out )
    '/// flash the window you have specified the handle for...
    FlashWindowEx(flash)

  End Sub
SSS
  • 4,807
  • 1
  • 23
  • 44
  • wasent exactly what I was looking for but i;ve worked it into my code ;P using a variable that set to false if this function is called, then true when focus is reestablished. :) so that the asynchronous background worker can tell if focused or not – Goulash Sep 18 '12 at 20:19