Получилось вот что:
I
- Код: Выделить всё
mports System
Imports System.IO
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Reflection
Imports System.Runtime.InteropServices
Public Class Form1
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Integer, ByVal lpData As NOTIFYICONDATA) As Integer
Private Const NIM_ADD As Short = &H0
Private Const NIM_DELETE As Short = &H2
Private Const NIM_MODIFY As Short = &H1
Private Const WM_MOUSEMOVE As Short = &H200
Private Const NIF_MESSAGE As Short = &H1
Private Const NIF_TIP As Short = &H4
Private Const NIF_ICON As Short = &H2
Private Const WM_LBUTTONDBLCLK As Short = &H203
Private Const WM_LBUTTONDOWN As Short = &H20
Private Const WM_LBUTTONUP As Short = &H202
Private Const WM_RBUTTONDBLCLK As Short = &H206
Private Const WM_RBUTTONDOWN As Short = &H204
Private Const WM_RBUTTONUP As Short = &H205
<StructLayout(LayoutKind.Sequential)> Structure NOTIFYICONDATA
Dim cbSize As Integer
Dim hwnd As Integer
Dim uID As Integer
Dim uFlags As Integer
Dim uCallbackMessage As Integer
Dim hIcon As Integer
End Structure
Private Tray As NOTIFYICONDATA
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Tray.cbSize = Marshal.SizeOf(GetType(Project_01.Form1.NOTIFYICONDATA))
Tray.hwnd = Me.Handle.ToInt32
Tray.uID = 0
Tray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
Tray.uCallbackMessage = WM_MOUSEMOVE
Tray.hIcon = Me.Icon.ToBitmap.GetHicon.ToInt32
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Shell_NotifyIcon(NIM_ADD, Tray)
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Shell_NotifyIcon(NIM_DELETE, Tray) End Sub
End Class
Выдает такое сообщение:
AccessViolationExctption was unhandled
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Что необходимо поправить, подскажите кто в курсе.