关闭

将程序放入托盘中

标签: integerbuttonstringshellfunctiondelete
679人阅读 评论(0) 收藏 举报
分类:

'以下是一个完整的托盘程序代码****************************************************************************
'************************************************************************************************************
'以下中模块代码
Public Type NOTIFYICONDATA '托盘结构
    cbSize As Long
    hwnd As Long
    uID As Long
    uFlags As Long
    uCallbackMessage As Long
    hIcon As Long
    szTip As String * 128
    dwState As Long
    dwStateMask As Long
    szInfo As String * 256
    uTimeoutAndVersion As Long
    szInfoTitle As String * 64
    dwInfoFlags As Long
End Type

Const niif_info = &H1

Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Const NIF_INFO = &H10


Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_RBUTTONUP = &H205
Public Const WM_MOUSEMOVE As Long = &H200

Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean '托盘函数
Public Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long

Public TrayI As NOTIFYICONDATA
Public Title_tray As String
'*****************************************************************************************************************

Option Explicit
'以下是窗体代码
Private Sub Form_Load()
On Error Resume Next
    Title_tray = "你好,这是一个托盘程序演示"
    With TrayI
       .cbSize = Len(TrayI)
       .hwnd = Form1.hwnd
       .uID = vbNull
       .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
       .uCallbackMessage = WM_MOUSEMOVE
       .hIcon = Form1.Icon
       .szTip = Title_tray & vbNullChar
    End With
    Call Shell_NotifyIcon(NIM_ADD, TrayI)
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
     If Button = 1 Then
       Me.WindowState = vbNormal
       Me.Visible = True
       SetForegroundWindow Me.hwnd
       Form1.PopupMenu Form1.bb '弹出菜单
     End If
     If Button = 2 Then
     '右键
       
     End If
End Sub

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:23153次
    • 积分:433
    • 等级:
    • 排名:千里之外
    • 原创:18篇
    • 转载:2篇
    • 译文:0篇
    • 评论:3条
    文章分类
    最新评论