Results 1 to 6 of 6

Thread: Flashing form

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Location
    Nigeria
    Posts
    16

    Flashing form

    Hi Guys,

    Please does anyone know how I can make a small form flash on the screen? I need my program to pop up little announcements once in a while.

    Thanks

    Nanfa

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Try this...

    VB Code:
    1. Private Declare Function GetActiveWindow Lib "user32.dll" () As Long
    2. Private Declare Function FlashWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal wActive As Long) As Long
    3. Private Declare Sub Sleep Lib "kernel32" (ByVal dMilliseconds As Long)
    4.  
    5. Dim i As Integer
    6. Dim handle As Long ' Handle for the active window
    7. Dim rval As Long
    8. handle = GetActiveWindow()  'Get the handle of active window
    9. For i = 1 To 10  ' Flash five times
    10. rval = FlashWindow(handle, 1)  'Flash the window
    11. Sleep 500  
    12. Next
    13. rval = FlashWindow(handle, 0) ' Bring the window to normal position

  3. #3
    Fanatic Member
    Join Date
    Jun 2001
    Posts
    521
    First of all, this question has been asked 100 times before, and you could've done a search.

    You could use FlashWindowEx instead of FlashWindow, which would eliminate some of the code Hack posted, as well as giving you more features... (if you ask how, here's the answer: do a search)

  4. #4
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Well first off Victor calm the heck down! Though it's a bit annoying, you don't need to go off on one.

    Here's the flashwindowex code, though I normally like to slag off Hack's coding I'd go with his one. A lot of the options added to the flashwindowex call aren't needed and just take up extra lines of code - the main difference between the 2 calls is that you can specify the amount of times it should flash - something which Hack's code has done anyway.

    I fail to see how this is shorter though ...
    VB Code:
    1. Private Declare Function FlashWindowEx Lib "user32" (pfwi As FLASHWINFO) As Boolean
    2.  
    3. Private Const FLASHW_CAPTION As Long = &H1
    4. Private Const FLASHW_TRAY As Long = &H2
    5. Private Const FLASHW_ALL As Long = (FLASHW_CAPTION Or FLASHW_TRAY)
    6. Private Const FLASHW_TIMER As Long = &H4
    7.  
    8. Private Type FLASHWINFO
    9.     cbSize As Long
    10.     hwnd As Long
    11.     dwFlags As Long
    12.     uCount As Long
    13.     dwTimeout As Long
    14. End Type
    15.  
    16. Private Sub Form_Load()
    17.  
    18.     Dim FlashInfo As FLASHWINFO
    19.  
    20.     With FlashInfo
    21.         .cbSize = Len(FlashInfo)
    22.         .dwFlags = FLASHW_ALL Or FLASHW_TIMER
    23.         .dwTimeout = 0
    24.         .hwnd = Me.hwnd
    25.         .uCount = 0
    26.     End With
    27.    
    28.     FlashWindowEx FlashInfo
    29. End Sub
    Last edited by alex_read; Aug 27th, 2002 at 07:20 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    The error of my ways (FlashWindow vs FlashWindowEx) is appreciated. You are correct.

    I will update the snippet in my code library appropriately.

    Cheers!

  6. #6
    Fanatic Member
    Join Date
    Jun 2001
    Posts
    521
    I did not realize that I was especially excited. The issue is that some people expect to be served what they ask for and not have to do any work besides register in the forum and ask their question. They would get their question answered faster by just doing a simple search, especially for flashing a window. Someone's gotta let newbies know that searching is the thing to do before asking a question.

    Whether those extra options are unnecessary is a very subjective statement. The big difference is that Hack's code will halt any further processing (sleep suspends the current thread) until the flashing is done. FlashWindowEx(...) is also cleaner, in the sense that the code is more simplified.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width