将程序放入托盘中

'以下是一个完整的托盘程序代码****************************************************************************
'************************************************************************************************************
'以下中模块代码
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

阅读更多
个人分类: myFile
上一篇将图片保存到数据库中
下一篇日历
想对作者说点什么? 我来说一句

VB把图标放入托盘中

2011年08月26日 14KB 下载

没有更多推荐了,返回首页

关闭
关闭