Solved

system tray tool tip.

Posted on 2000-03-28
12
189 Views
Last Modified: 2008-02-01
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
Comment
Question by:Gunjitsu
12 Comments
 
LVL 2

Expert Comment

by:Pepster
ID: 2663954
OK
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2663973
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
 
LVL 1

Expert Comment

by:olisaac
ID: 2664008
Ok

You can give your code...
0
 

Author Comment

by:Gunjitsu
ID: 2664074
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
 

Author Comment

by:Gunjitsu
ID: 2664100
Adjusted points from 170 to 179
0
 
LVL 6

Expert Comment

by:st_steve
ID: 2664104
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Gunjitsu
ID: 2664133
Adjusted points from 179 to 279
0
 

Author Comment

by:Gunjitsu
ID: 2664134
st steve,

that site was for vb6 +
im using vb5.
0
 

Author Comment

by:Gunjitsu
ID: 2664185
Adjusted points from 279 to 529
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2664268
;-) 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
 
LVL 2

Accepted Solution

by:
nunga earned 529 total points
ID: 2664274
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
 

Author Comment

by:Gunjitsu
ID: 2664594
YES FINALLY!!!!

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

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now