• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

system tray tool tip.

I have made a visual basic program that minimizes the program into the system tray. i have tried everything to try and get it to update the tool tip, i went through all this site and got everything about it and read everything still no luck. Can i send in the code for someone to have a look at?
0
Gunjitsu
Asked:
Gunjitsu
1 Solution
 
PepsterCommented:
OK
0
 
caraf_gCommented:
Just post it here and someone will look at it. This is a knowledge sharing site so avoid sending e-mails as we cannot all participate in them.
0
 
olisaacCommented:
Ok

You can give your code...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
GunjitsuAuthor Commented:
well there is a fair bit of code but here is the whole lot

if you have a look under timer1 you can see where i tried to get it to work.

Option Explicit

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
   
Const NIM_ADD = 0
Const NIM_MODIFY = 1
Const NIM_DELETE = 2
Const NIF_MESSAGE = 1
Const NIF_ICON = 2
Const NIF_TIP = 4

Const WM_MOUSEMOVE = &H200
   
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function Shell_NotifyIconA Lib "SHELL32" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Integer

' SetWindowPos Flags
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOREDRAW = &H8
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_FRAMECHANGED = &H20        '  The frame changed: send WM_NCCALCSIZE
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_HIDEWINDOW = &H80
Private Const SWP_NOCOPYBITS = &H100
Private Const SWP_NOOWNERZORDER = &H200      '  Don't do owner Z ordering
Public aot As Integer

Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
Private Const SWP_NOREPOSITION = SWP_NOOWNERZORDER

' SetWindowPos() hwndInsertAfter values
Private Const HWND_TOP = 0
Private Const HWND_BOTTOM = 1
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Dim TimeCaption As String
Dim UpTime As Variant
Dim temp As Variant
Dim temp2 As Variant
Dim TotalTime As Variant
Dim LastRecord As Variant
Dim startup As Variant
Dim record As Variant
Dim delaytime As String
Dim LastTime As String
Dim logtftf As String
Dim logfilename As String

Private Sub cmddetails_Click()
Form2.Show
Form1.Enabled = False
End Sub

Private Sub cmddetails_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
cmddetails.ForeColor = vbRed
End Sub

Private Sub cmddetails_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
cmddetails.ForeColor = vbBlue
End Sub

Private Sub cmdexit_Click()
    Dim i As Integer
    Dim nid As NOTIFYICONDATA

    nid = setNOTIFYICONDATA(Form1.hwnd, vbNull, NIF_MESSAGE Or NIF_ICON Or NIF_TIP, vbNull, Form1.Icon, "")

    i = Shell_NotifyIconA(NIM_DELETE, nid)
End
End Sub


Private Sub cmdexit_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
cmdexit.ForeColor = vbRed
End Sub

Private Sub cmdhide_Click()
Form1.Hide
End Sub

Private Sub Command2_Click()
Dim i As Integer
Dim nid As NOTIFYICONDATA
nid = setNOTIFYICONDATA(Form1.hwnd, vbNull, NIF_MESSAGE Or NIF_ICON Or NIF_TIP, vbNull, Form1.Icon, "")
i = Shell_NotifyIconA(NIM_DELETE, nid)
   
End
End Sub

Private Sub cmdhide_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
cmdhide.ForeColor = vbRed
End Sub

Private Sub cmdhide_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
cmdhide.ForeColor = vbBlue
End Sub

Private Sub cmdoptions_Click()
Form3.Show
Form1.Enabled = False

End Sub

Private Sub cmdoptions_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
cmdoptions.ForeColor = vbRed
End Sub

Private Sub cmdoptions_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
cmdoptions.ForeColor = vbBlue
End Sub

Private Sub Form_Load()
Dim i As Integer
Dim s As String
Dim nid As NOTIFYICONDATA

Open ".\record.rut" For Random As #1
Get #1, 4, startup
If startup = "true" Then cmdhide_Click
Get #1, 5, delaytime
If delaytime = "" Then delaytime = "10"
Get #1, 7, logtftf
If logtftf = "yes" Then
 lblcantsee.Caption = "yes"
 Get #1, 8, logfilename
End If
Timer1.Interval = Val(delaytime) * 100
Close #1
Timer1_Timer
s = "Pre-Release Raspberg Up Time v1.2"
nid = setNOTIFYICONDATA(Form1.hwnd, vbNull, NIF_MESSAGE Or NIF_ICON Or NIF_TIP, WM_MOUSEMOVE, Form1.Icon, s)
i = Shell_NotifyIconA(NIM_ADD, nid)
End Sub
 
Public Function GetTime()
UpTime = GetTickCount / 1000 / 60
Select Case UpTime
Case 1 To 60
 TimeCaption = Int(UpTime) & " Minute(s)"
Case 60 To 1440
 temp = Int(UpTime / 60)
 UpTime = UpTime - temp * 60
 TimeCaption = TimeCaption & temp & " Hour(s) "
 temp = Int(UpTime)
 TimeCaption = TimeCaption & temp & " Minute(s)"
Case Is > 1440
 temp = Int(UpTime / 60 / 24)
 UpTime = UpTime - temp * 24 * 60
 TimeCaption = temp & " Day(s) "
 temp = Int(UpTime / 60)
 UpTime = UpTime - temp * 60
 TimeCaption = TimeCaption & temp & " Hour(s) "
 temp = Int(UpTime)
 TimeCaption = TimeCaption & temp & " Minute(s)"
End Select

End Function

Private Sub lblabout_Click()
Form1.Enabled = False
Form4.Show
End Sub

Private Sub lblabout_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
lblabout.ForeColor = vbRed
End Sub

Private Sub lblabout_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
lblabout.ForeColor = vbBlue
End Sub

Private Sub lbluptime_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
cmdhide.ForeColor = vbBlack
cmdoptions.ForeColor = vbBlack
cmddetails.ForeColor = vbBlack
cmdexit.ForeColor = vbBlack
lblabout.ForeColor = vbBlack
End Sub

Private Sub Timer1_Timer()
Dim i As Integer
Dim s As String
Dim nid As NOTIFYICONDATA

Open ".\record.rut" For Random As #1

TimeCaption = ""
GetTime

nid.szTip = TimeCaption & vbNullChar
i = Shell_NotifyIconA(NIM_MODIFY, nid)

If TimeCaption = "" Then TimeCaption = "Under one minute"
lbluptime.Caption = TimeCaption

Get #1, 8, logfilename
If lblcantsee.Caption = "yes" Then
  Open logfilename For Output As #2
  Print #2, TimeCaption
  Close #2
End If

temp = GetTickCount / 1000 / 60
 Get #1, 1, record
 If temp > record Then
  record = temp
  Put #1, 1, record
 End If

Get #1, 2, LastRecord
If LastRecord > temp Then
 LastTime = LastRecord
 Put #1, 6, LastTime
 Get #1, 3, TotalTime
 TotalTime = TotalTime + LastRecord
 Put #1, 3, TotalTime
End If

LastRecord = GetTickCount / 1000 / 60
Put #1, 2, LastRecord

Close #1
 
End Sub

Private Function setNOTIFYICONDATA(hwnd As Long, ID As Long, Flags As Long, CallbackMessage As Long, Icon As Long, tip As String) As NOTIFYICONDATA
    Dim nidTemp As NOTIFYICONDATA

    nidTemp.cbSize = Len(nidTemp)
    nidTemp.hwnd = hwnd
    nidTemp.uID = ID
    nidTemp.uFlags = Flags
    nidTemp.uCallbackMessage = CallbackMessage
    nidTemp.hIcon = Icon
    nidTemp.szTip = tip & Chr$(0)

    setNOTIFYICONDATA = nidTemp
End Function

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
cmdhide.ForeColor = vbBlack
cmdoptions.ForeColor = vbBlack
cmddetails.ForeColor = vbBlack
cmdexit.ForeColor = vbBlack
   
    If Not Visible Then
        Select Case X
            Case 7695
                Form1.Show
                Dim hProcess As Long
                GetWindowThreadProcessId hwnd, hProcess
                AppActivate hProcess
        End Select
    End If
End Sub

0
 
GunjitsuAuthor Commented:
Adjusted points from 170 to 179
0
 
st_steveCommented:
0
 
GunjitsuAuthor Commented:
Adjusted points from 179 to 279
0
 
GunjitsuAuthor Commented:
st steve,

that site was for vb6 +
im using vb5.
0
 
GunjitsuAuthor Commented:
Adjusted points from 279 to 529
0
 
caraf_gCommented:
;-) That's enough. There is no need to increase the points further. If anyone is able to help you they wouldn't be so cruel as to wait until you've increased your points to some ridiculous level.
0
 
nungaCommented:
Hi Gunjitsu

The problem is that you have declared 'nid' in the Timer event. So when you are issuing the NIM_MODIFY command in Timer1_Timer, you aren't actually modifying the icon (nid) that was created in the Form_Load event.

Move the following line out of the Form_Load event and place it into the General Declarations section of the form:

Dim nid As NOTIFYICONDATA

Then remove the following line from Timer1_Timer:

Dim nid As NOTIFYICONDATA

This will make the nid variable available to the entire form.

Also, check your Command2_Click and cmdExit_Click events. If you are trying to work with the same system tray icon, remove the Dim statements and setNOTIFYICONDATA statements from those events.

I hope you find this useful.
0
 
GunjitsuAuthor Commented:
YES FINALLY!!!!

iv spend a few months searching around websites trying to figure this out. thank you so much!!!!

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now