[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SysTray Icon Problems

Posted on 2005-04-12
4
Medium Priority
?
334 Views
Last Modified: 2012-08-13
I found some code on the Inet & im trying to implement it in my app but having Variable Not Defined error. What is highlighted is the " Result = " Im sure this is an easy fix I just cant think of what else it could be.

Public Function ShowProgramInTray()
INTRAY = True  
   
    NI.cbSize = Len(NI)
    NI.hwnd = TrayIcon.hwnd
    NI.uID = 0
    NI.uID = NI.uID + 1
    NI.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
    NI.uCallbackMessage = WM_MOUSEMOVE
    NI.hIcon = TrayIcon.Picture

    NI.szTip = "Desktop Manager" + Chr$(0)
    Result = Shell_NotifyIconA(NIM_ADD, NI)
End Function
0
Comment
Question by:thaburner
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 500 total points
ID: 13764682
'Download the full source+pictures+... at http://kpdteam.hypermart.net/download/tray.zip
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 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_LBUTTONDBLCLK = &H203
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_RBUTTONUP = &H205

Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Dim TrayI As NOTIFYICONDATA
Private Sub Form_Load()
    TrayI.cbSize = Len(TrayI)
    'Set the window's handle (this will be used to hook the specified window)
    TrayI.hWnd = pichook.hWnd
    'Application-defined identifier of the taskbar icon
    TrayI.uId = 1&
    'Set the flags
    TrayI.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    'Set the callback message
    TrayI.ucallbackMessage = WM_LBUTTONDOWN
    'Set the picture (must be an icon!)
    TrayI.hIcon = imgIcon(2).Picture
    'Set the tooltiptext
    TrayI.szTip = "Recent" & Chr$(0)
    'Create the icon
    Shell_NotifyIcon NIM_ADD, TrayI

    Me.Hide
End Sub
Private Sub Form_Unload(Cancel As Integer)
    'remove the icon
    TrayI.cbSize = Len(TrayI)
    TrayI.hWnd = pichook.hWnd
    TrayI.uId = 1&
    Shell_NotifyIcon NIM_DELETE, TrayI
    End
End Sub
Private Sub mnuPop_Click(Index As Integer)
    Select Case Index
        Case 0
            MsgBox "KPD-Team 1998" + Chr$(13) + "URL: http://www.allapi.net/" + Chr$(13) + "E-Mail: KPDTeam@Allapi.net", vbInformation + vbOKOnly
        Case 2
            Unload Me
    End Select
End Sub
Private Sub pichook_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Msg = X / Screen.TwipsPerPixelX
    If Msg = WM_LBUTTONDBLCLK Then
        'Left button double click
        mnuPop_Click 0
    ElseIf Msg = WM_RBUTTONUP Then
        'Right button click
        Me.PopupMenu mnuPopUp
    End If
End Sub
Private Sub Timer1_Timer()
    Static Tek As Integer
    'Animate the icon
    Me.Icon = imgIcon(Tek).Picture
    TrayI.hIcon = imgIcon(Tek).Picture
    Tek = Tek + 1
    If Tek = 3 Then Tek = 0
    Shell_NotifyIcon NIM_MODIFY, TrayI
End Sub
0
 

Author Comment

by:thaburner
ID: 13766208
0
 

Assisted Solution

by:DaveHurley
DaveHurley earned 500 total points
ID: 13768162
Being a beginner, only a suggestion

when adding the System tray Icon... You are storing the return value from the "Shell_NotifyIconA"

Do you plan to use this??

Try simply Shell_NotifyIconA(NIM_ADD, NI)
0
 

Author Comment

by:thaburner
ID: 13768271
Ok some how i got it to work (Weird) So i just split the points for you trying thank you
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

864 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