VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Display an icon in the system tray

by miss Suprava (1 Submission)
Category: Windows System Services
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 30th March 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Display an icon in the system tray

API Declarations


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 WM_MOUSEMOVE = &H200
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4

Private Const WM_LBUTTONDBLCLK = &H203 'Double-click
Private Const WM_LBUTTONDOWN = &H201 'Button down
Private Const WM_LBUTTONUP = &H202 'Button up

Private Const WM_RBUTTONDBLCLK = &H206 'Double-click
Private Const WM_RBUTTONDOWN = &H204 'Button down
Private Const WM_RBUTTONUP = &H205 'Button up

Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Dim nid As NOTIFYICONDATA


Rate Display an icon in the system tray



   nid.cbSize = Len(nid)
   nid.hWnd = Form1.hWnd
   nid.uId = vbNull
   nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
   nid.uCallBackMessage = WM_MOUSEMOVE
   nid.hIcon = Form1.Icon
   nid.szTip = "Taskbar Status Area Sample Program" & vbNullChar
   Shell_NotifyIcon NIM_ADD, nid
End Sub

Private Sub Command2_Click()
   Shell_NotifyIcon NIM_DELETE, nid
End Sub

Private Sub Form_Load()
   Command1.Caption = "Add an Icon"
   Command2.Caption = "Delete Icon"
End Sub

Private Sub Form_Terminate()
   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
    Dim sFilter As String
    msg = X / Screen.TwipsPerPixelX
    Select Case msg
       Case WM_LBUTTONDOWN
       Case WM_LBUTTONUP
       Case WM_LBUTTONDBLCLK
       CommonDialog1.DialogTitle = "Select an Icon"
       sFilter = "Icon Files (*.ico)|*.ico"
       sFilter = sFilter & "|All Files (*.*)|*.*"
       CommonDialog1.Filter = sFilter
       CommonDialog1.ShowOpen
       If CommonDialog1.FileName <> "" Then
          Form1.Icon = LoadPicture(CommonDialog1.FileName)
          nid.hIcon = Form1.Icon
          Shell_NotifyIcon NIM_MODIFY, nid
       End If
       Case WM_RBUTTONDOWN
          Dim ToolTipString As String
          ToolTipString = InputBox("Enter the new ToolTip:", "Change ToolTip")
          If ToolTipString <> "" Then
             nid.szTip = ToolTipString & vbNullChar
             Shell_NotifyIcon NIM_MODIFY, nid
          End If
       Case WM_RBUTTONUP
       Case WM_RBUTTONDBLCLK
    End Select
End Sub

Download this snippet    Add to My Saved Code

Display an icon in the system tray Comments

No comments have been posted about Display an icon in the system tray. Why not be the first to post a comment about Display an icon in the system tray.

Post your comment

Subject:
Message:
0/1000 characters