Show Balloon Tooltip (VB.NET) on the tray

zhaozj2021-02-16  49

Writing the Balloon prompt using VB is required to call Win32APi, but it is still different on VB6 and VB.NET code, and the red part is different.

Imports system.Runtime.InteropServices

Public class form1 inherits system.windows.Forms.form

#Region "Win32API_NotifyiCon" Private Declare Function Shell_notifyiCon Lib "shell32.dll" Alias ​​_ "shell_notifyicona" (ByVal dwmessage as int32, _ byref lpdata as notifyicondata) AS INT32

Private Structure NOTIFYICONDATA Public cbSize As Int32 Public hwnd As IntPtr Public uId As Int32 Public uFlags As Int32 Public uCallBackMessage As Int32 Public hIcon As IntPtr _ Public szTip As String Public dwState As Int32 Public dwStateMask As Int32 _ Public szInfo As String Public uTimeoutOrVersion As Int32 _ public szinfotitle as string public dwinfoflags as int32 End structure

Private const notifyicon_version = 3 private const notifyicon_oldversion = 0

Private const nim_add = & h0 private const nim_modify = & h1 private const nim_delete = & h2

Private const nim_setfocus = & h3 private const nim_setversion = & h4

Private const nif_message = & h1 private const nif_icon = & h2 private const nif_tip = & h4

Private const nif_state = & h8 private const nif_info = & h10

Private const nis_hidden = & h1 private const nis_sharedicon = & h2private const niif_none = & h0 private const niif_warning = & h2 private const niif_error = & h3 private const niif_info = & h1

Private nficondata as Notifyicondata

#End region

Private Sub Form1_Load (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load nfIconData = New NOTIFYICONDATA () With nfIconData .cbSize = System.Runtime.InteropServices.Marshal.SizeOf (nfIconData) .hwnd = Me. Handle .uId = vbNull .uFlags = NIF_INFO Or NIF_ICON Or NIF_TIP Or NIF_MESSAGE .hIcon = Me.Icon.Handle .szTip = "123" '& Microsoft.VisualBasic.vbNullChar .dwState = 0 .dwStateMask = 0 .szInfo = "Balloon Style Tool-Tip "& chr (13) &" haha ​​"'& vbnullchar .utimeoutorversion = 15000 .szinfotitle =" See it? "' & Microsoft.visualbasic.vbnullchar .dwinfoflags = niif_info end with

Call shell_notifyicon (nim_add, nficondata)

End Sub

Private sub form1_closed (Byval e as system.eventargs) Handles mybase.closed call shell_notifyicon (nim_delete, nficondata) End Subend Class

转载请注明原文地址:https://www.9cbs.com/read-27488.html

New Post(0)