Mark wrote:
Hi All,
Does anyone know of a way that I can get a task bar button to flash if a
form is open? I have created something like a messenger application within
my database but there are a few people who have it open but do not use it
exclusivley. If someone was to send them a message, it could be hours before
they see it so if I could get the taskbar button to flash if the form opens,
they can be alerted instantly.
Many thanks,
Mark
I went to Google and was referred to the following kb article at
http://support.microsoft.com...Q147815.
OK, this KB is referring to VB. Plus, it needed to be modified for the
taskbar, not the window. So if you want a quick demo of how I modified
it, do the following.
Create a form...Form1. Add a text field (Text0) and a command button
CommandExit.
Set the tab order to command button first, text0 last, since when you
put your mouse onto Text0 it will stop the blinking.
Now, drop the following code into the form1's module by cut/paste
'start cut
Option Compare Database
Option Explicit
Dim Success As Long
Dim lngHwnd As Long
Private Sub Form_Load()
'get the hwnd of Access
lngHwnd = fEnumWindows()
Me.TimerInterval = GetCaretBlinkTime()
End Sub
Private Sub CommandExit_Click()
DoCmd.Close
End Sub
Private Sub Form_Timer()
Success = FlashWindow(lngHwnd, 1)
End Sub
Private Sub Text0_GotFocus()
Me.TimerInterval = 0
End Sub
'end cut
What happens is that when the form loads, it will start blinking.
Minimize Access if you like...the taskbar for Access should be blinking.
Now when you maxmize Access and go to Text0, the blinking will stop.
In order to make this work, you need to get the hwnd of Access. So I
swiped the code at
http://www.mvps.org/access/api/api0013.htm and
modified it slightly. First, I added the function calls for
GetCaretBlinkTime and FlashWindow and removed the calls to get the class
name. I do a search for the phrase "Microsoft Access". You may want to
change the search for something else. Anyway.........
Create a new code module and cut/paste the following code. Save the
module. Now save/close Form1. Now open it. Minimize it. It should be
blinking.
'start cut here
Option Compare Database
Option Explicit
Declare Function FlashWindow Lib "user32" ( _
ByVal Hwnd As Long, _
ByVal bInvert As Long) As Long
Declare Function GetCaretBlinkTime Lib "user32" () As Long
Private Declare Function apiGetDesktopWindow Lib "user32" Alias _
"GetDesktopWindow" () As Long
Private Declare Function apiGetWindow Lib "user32" Alias _
"GetWindow" (ByVal Hwnd As Long, _
ByVal wCmd As Long) As Long
Private Declare Function apiGetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal Hwnd As Long, ByVal _
nIndex As Long) As Long
Private Declare Function apiGetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal Hwnd As Long, ByVal _
lpString As String, ByVal aint As Long) As Long
Private Const mcGWCHILD = 5
Private Const mcGWHWNDNEXT = 2
Private Const mcGWLSTYLE = (-16)
Private Const mcWSVISIBLE = &H10000000
Private Const mconMAXLEN = 255
Function fEnumWindows()
Dim lngx As Long, lngLen As Long
Dim lngStyle As Long, strCaption As String
lngx = apiGetDesktopWindow()
'Return the first child to Desktop
lngx = apiGetWindow(lngx, mcGWCHILD)
Do While Not lngx = 0
strCaption = fGetCaption(lngx)
If Len(strCaption) > 0 Then
lngStyle = apiGetWindowLong(lngx, mcGWLSTYLE)
'enum visible windows only
If lngStyle And mcWSVISIBLE Then
'CHANGE YOUR SEARCH STRING HERE. I USE MS ACCESS
'YOU CAN SEARCH FOR YOUR APP NAME TOO. THE DEBUG
'PRINT SHOULD HELP YOU OUT TO DETERMINE WHAT
'WINDOW TO SEARCH FOR,
If InStr(fGetCaption(lngx), "Microsoft Access") > 0 Then
fEnumWindows = lngx
Exit Do
End If
'Debug.Print lngx
'Debug.Print "Caption = " & fGetCaption(lngx)
'Debug.Print
End If
End If
lngx = apiGetWindow(lngx, mcGWHWNDNEXT)
Loop
End Function
Private Function fGetCaption(Hwnd As Long) As String
Dim strBuffer As String
Dim intCount As Integer
strBuffer = String$(mconMAXLEN - 1, 0)
intCount = apiGetWindowText(Hwnd, strBuffer, mconMAXLEN)
If intCount > 0 Then
fGetCaption = Left$(strBuffer, intCount)
End If
End Function
'end cut here