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
Printable View
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
VB Code:
Private Declare Function GetActiveWindow Lib "user32.dll" () As Long Private Declare Function FlashWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal wActive As Long) As Long Private Declare Sub Sleep Lib "kernel32" (ByVal dMilliseconds As Long) Dim i As Integer Dim handle As Long ' Handle for the active window Dim rval As Long handle = GetActiveWindow() 'Get the handle of active window For i = 1 To 10 ' Flash five times rval = FlashWindow(handle, 1) 'Flash the window Sleep 500 Next rval = FlashWindow(handle, 0) ' Bring the window to normal position
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)
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:
Private Declare Function FlashWindowEx Lib "user32" (pfwi As FLASHWINFO) As Boolean Private Const FLASHW_CAPTION As Long = &H1 Private Const FLASHW_TRAY As Long = &H2 Private Const FLASHW_ALL As Long = (FLASHW_CAPTION Or FLASHW_TRAY) Private Const FLASHW_TIMER As Long = &H4 Private Type FLASHWINFO cbSize As Long hwnd As Long dwFlags As Long uCount As Long dwTimeout As Long End Type Private Sub Form_Load() Dim FlashInfo As FLASHWINFO With FlashInfo .cbSize = Len(FlashInfo) .dwFlags = FLASHW_ALL Or FLASHW_TIMER .dwTimeout = 0 .hwnd = Me.hwnd .uCount = 0 End With FlashWindowEx FlashInfo End Sub
The error of my ways (FlashWindow vs FlashWindowEx) is appreciated. You are correct.
I will update the snippet in my code library appropriately.
Cheers! :D
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.