|
-
Aug 22nd, 2002, 01:28 PM
#1
Thread Starter
Junior Member
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
-
Aug 22nd, 2002, 01:30 PM
#2
Try this...
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
-
Aug 22nd, 2002, 01:55 PM
#3
Fanatic Member
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)
-
Aug 27th, 2002, 06:53 AM
#4
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
Last edited by alex_read; Aug 27th, 2002 at 07:20 AM.
-
Aug 27th, 2002, 07:15 AM
#5
The error of my ways (FlashWindow vs FlashWindowEx) is appreciated. You are correct.
I will update the snippet in my code library appropriately.
Cheers!
-
Aug 27th, 2002, 09:19 AM
#6
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|