VB6 How to write the application icon in the Tray

Source: Internet
Author: User
Tags integer

This article describes in detail how VB6 writes the application icon in the Tray

Related articles:

Realization of tray animation icon with VB

VB Tray Program detailed a

VB Tray Program detailed two

VB Tray Program detailed three

VB Tray Program detailed four

VB Tray Program detailed five

Also talk about automatic disk saving under Windows

Using WINDOWSAPI to get advanced features of the system

1, the new establishment of a VB6 project, the Form1 ShowInTaskbar property set to False

2, Menu: Project--Add Module Press "OPEN" This adds a new module, named Module1, save as Module1.bas

3, write down the following code in the Module1:

Option Explicit
Public Const Max_tooltip as Integer = 64
Public Const Nif_icon = &h2
Public Const nif_message = &h1
Public Const Nif_tip = &h4
Public Const Nim_add = &h0
Public Const Nim_delete = &h2
Public Const wm_mousemove = &h200
Public Const Wm_lbuttondown = &h201
Public Const Wm_lbuttonup = &h202
Public Const WM_LBUTTONDBLCLK = &h203
Public Const Wm_rbuttondown = &h204
Public Const Wm_rbuttonup = &h205
Public Const WM_RBUTTONDBLCLK = &h206
Public Const Sw_restore = 9
Public Const sw_hide = 0
Public Nficondata as Notifyicondata
Public Type Notifyicondata
cbsize as Long
HWnd as Long
UID as Long
Uflags as Long
Ucallbackmessage as Long
Hicon as Long
Sztip as String * max_tooltip
End Type
Public Declare Function ShowWindow Lib "user32" (ByVal hWnd as Long, ByVal nCmdShow as long) as long
Public Declare Function Shell_NotifyIcon Lib "Shell32.dll" Alias "Shell_notifyicona" (ByVal dwmessage as Long, lpdata as N Otifyicondata) as Long

4, write down the following code in the Form1 Load event:

Private Sub Form_Load()
  '以下把程序放入System Tray====================================System Tray Begin
  With nfIconData
   .hWnd = Me.hWnd
   .uID = Me.Icon
   .uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
   .uCallbackMessage = WM_MOUSEMOVE
   .hIcon = Me.Icon.Handle
   '定义鼠标移动到托盘上时显示的Tip
   .szTip = App.Title + "(版本 " & App.Major & "." & App.Minor & "." & App.Revision & ")" & vbNullChar
   .cbSize = Len(nfIconData)
  End With
  Call Shell_NotifyIcon(NIM_ADD, nfIconData)
  '=============================================================System Tray End
  Me.Hide
End Sub

5. Write the following code in the Form1 QueryUnload event:

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call Shell_NotifyIcon(NIM_DELETE, nfIconData)
End Sub

6. Write the following code in the Form1 MouseMove event:

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Dim lMsg As Single
  lMsg = X / Screen.TwipsPerPixelX
  Select Case lMsg
   Case WM_LBUTTONUP
    'MsgBox "请用鼠标右键点击图标!", vbInformation, "实时播音专家"
    '单击左键,显示窗体
    ShowWindow Me.hWnd, SW_RESTORE
    '下面两句的目的是把窗口显示在窗口最顶层
    'Me.Show
    'Me.SetFocus
    '' Case WM_RBUTTONUP
    '' PopupMenu MenuTray '如果是在系统Tray图标上点右键,则弹出菜单MenuTray
    '' Case WM_MOUSEMOVE
    '' Case WM_LBUTTONDOWN
    '' Case WM_LBUTTONDBLCLK
    '' Case WM_RBUTTONDOWN
    '' Case WM_RBUTTONDBLCLK
    '' Case Else
  End Select
End Sub

7, now save the program to run to see if the system tray added a project icon. Click this icon and the Form1 will automatically bounce out.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.