Hi,
I am trying to update the nid.szTip text while the program is running minimized to the system tray. The program is functioning fine and I want to display the latest action performed by the Timer1 sub when you hover the mouse over the icon in the systray. Seems no matter what I try the text doesnt update the reflect the timer event.PHP Code:Option Explicit
' Constants required by Shell_NotifyIcon API call
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_MOUSEMOVE = &H200
Private Const WM_LBUTTONDOWN = &H201 'Button down
Private Const WM_LBUTTONUP = &H202 'Button up
Private Const WM_LBUTTONDBLCLK = &H203 'Double-click
Private Const WM_RBUTTONDOWN = &H204 'Button down
Private Const WM_RBUTTONUP = &H205 'Button up
Private Const WM_RBUTTONDBLCLK = &H206 'Double-click 'API call
Private Declare Function SetForegroundWindow Lib "user32" _
(ByVal hWnd As Long) As Long
Private Declare Function Shell_NotifyIcon Lib "shell32" _
Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2 'variable declaration
Private nid As NOTIFYICONDATA
'Show form icon in system tray
' User defined type required by Shell_NotifyIcon API call
Private Type NOTIFYICONDATA
cbSize As Long
hWnd As Long
uId As Long
uFlags As Long
ucallbackMessage As Long
hIcon As Long
szTip As String * 64
End Type
Private Sub Timer1_Timer()
Dim str59min As String
str59min = Left$(Right$(lblTime.Caption, 8), 5)
If lblTime.Caption <> CStr(Time) Then
lblTime.Caption = Time
End If
If str59min = "32:00" Then
If Right$(lblTime.Caption, 2) <> "AM" Then
Label1.Caption = "Last update " & lblTime.Caption
End If
End If
End Sub
Private Sub Form_Resize()
If Me.WindowState = 1 Then
Me.Hide
With nid
.cbSize = Len(nid)
.hWnd = Me.hWnd
.uId = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.ucallbackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon
.szTip = "Pending Update"
End With
Shell_NotifyIcon NIM_ADD, nid
Else
Shell_NotifyIcon NIM_DELETE, nid
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
' Remove Icon from System Tray
'if you use another unload put this there as well
Shell_NotifyIcon NIM_DELETE, nid
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim msg As Long
On Error GoTo ErrorHandler
'Respond to user interaction
msg = X / Screen.TwipsPerPixelX
Select Case msg
Case WM_LBUTTONDBLCLK
'nothing
Case WM_LBUTTONDOWN
'nothing
Case WM_LBUTTONUP
If Me.WindowState = vbMinimized Then
Me.WindowState = vbNormal
Me.Show
Else
Me.WindowState = vbMinimized
Me.Hide
End If
Case WM_RBUTTONDBLCLK
'nothing
Case WM_RBUTTONDOWN
Call PopupMenu(mnuFile, vbPopupMenuRightAlign)
Case WM_RBUTTONUP
'nothing
End Select
Exit Sub
ErrorHandler: 'Display error message
Screen.MousePointer = vbDefault
MsgBox Err.Description, vbInformation, App.ProductName & " - " & Me.Caption
End Sub
Private Sub mnu_Click(Index As Integer)
Select Case Index
Case 0 'Option 1
MsgBox "You've clicked on option1 - good for you!", _
vbInformation, App.ProductName & Me.Caption
Case 1 'Option 2
MsgBox "You've clicked on option2 - great!", _
vbInformation, App.ProductName & Me.Caption
Case 2 'Option 1
Unload Me
End
End Select
End Sub





Reply With Quote