⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trayicon.frm

📁 软件名称: 实现托盘程序
💻 FRM
字号:
VERSION 4.00
Begin VB.Form frmTrayIcon 
   Caption         =   "Mind's Tray Icon Example"
   ClientHeight    =   1485
   ClientLeft      =   2625
   ClientTop       =   2175
   ClientWidth     =   3480
   Height          =   1890
   Icon            =   "TrayIcon.frx":0000
   Left            =   2565
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   ScaleHeight     =   1485
   ScaleWidth      =   3480
   Top             =   1830
   Width           =   3600
   Begin VB.CommandButton cmdExit 
      Caption         =   "E&xit"
      Height          =   375
      Left            =   1200
      TabIndex        =   0
      Top             =   840
      Width           =   1215
   End
   Begin VB.Image imgIcon2 
      Height          =   480
      Left            =   1920
      Picture         =   "TrayIcon.frx":030A
      Top             =   240
      Width           =   480
   End
   Begin VB.Image imgIcon1 
      Height          =   480
      Left            =   1200
      Picture         =   "TrayIcon.frx":074C
      Top             =   240
      Width           =   480
   End
   Begin VB.Menu mnuPopUp 
      Caption         =   "PopUp_Menu"
      Visible         =   0   'False
      Begin VB.Menu mnuChange 
         Caption         =   "Change &Icon"
      End
      Begin VB.Menu line2 
         Caption         =   "-"
      End
      Begin VB.Menu mnuExit 
         Caption         =   "E&xit"
      End
      Begin VB.Menu line 
         Caption         =   "-"
      End
      Begin VB.Menu mnuAbout 
         Caption         =   "&About"
      End
   End
End
Attribute VB_Name = "frmTrayIcon"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit

Private Sub cmdExit_Click()

    Unload Me
    
End Sub


Private Sub Form_Load()

    
    'centers form
    Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2

    'sets cbSize to the Length of TrayIcon
    TrayIcon.cbSize = Len(TrayIcon)
    ' Handle of the window used to handle messages - which is the this form
    TrayIcon.hWnd = Me.hWnd
    ' ID code of the icon
    TrayIcon.uId = vbNull
    ' Flags
    TrayIcon.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    ' ID of the call back message
    TrayIcon.ucallbackMessage = WM_MOUSEMOVE
    ' The icon - sets the icon that should be used
    TrayIcon.hIcon = imgIcon1.Picture
    ' The Tooltip for the icon - sets the Tooltip that will be displayed
    TrayIcon.szTip = "Mind's Tray Icon Example" & Chr$(0)
    
    ' Add icon to the tray by calling the Shell_NotifyIcon API
    'NIM_ADD is a Constant - add icon to tray
    Call Shell_NotifyIcon(NIM_ADD, TrayIcon)
    
    ' Don't let application appear in the Windows task list
    App.TaskVisible = False

End Sub


Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

Static Message As Long
Static RR As Boolean
    
    'x is the current mouse location along the x-axis
    Message = X / Screen.TwipsPerPixelX
    
    If RR = False Then
        RR = True
        Select Case Message
            ' Left double click (This should bring up a dialog box)
            Case WM_LBUTTONDBLCLK
                Me.Show
            ' Right button up (This should bring up a menu)
            Case WM_RBUTTONUP
                Me.PopupMenu mnuPopUp
        End Select
        RR = False
    End If
    
End Sub


Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

    TrayIcon.cbSize = Len(TrayIcon)
    TrayIcon.hWnd = Me.hWnd
    TrayIcon.uId = vbNull
    'Remove icon for Tray
    Call Shell_NotifyIcon(NIM_DELETE, TrayIcon)
    
End Sub


Private Sub mnuAbout_Click()

    frmAbout.Show

End Sub

Private Sub mnuChange_Click()

    'checks to find what icon is currently displayed
    If TrayIcon.hIcon = imgIcon1.Picture Then
        'changes the icon to display
        TrayIcon.hIcon = imgIcon2.Picture
        'removes current icon from tray
        Call Shell_NotifyIcon(NIM_DELETE, TrayIcon)
         'calls the API to add in new icon
        Call Shell_NotifyIcon(NIM_ADD, TrayIcon)
    Else
        'changes the icon to display
        TrayIcon.hIcon = imgIcon1.Picture
        'removes current icon from tray
         Call Shell_NotifyIcon(NIM_DELETE, TrayIcon)
        'calls the API to add in new icon
        Call Shell_NotifyIcon(NIM_ADD, TrayIcon)
    End If
        
End Sub


Private Sub mnuExit_Click()

    Unload Me

End Sub


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -