d532335
asked on
Converting NOTIFYICONDATA from VB6 to VB.NET
I have some VB6 code that I am converting to .NET. It is going fairly well but I have a structure that is defined and passed from the Shell_NotifyIcon shell32 method. Below is how i converted it from the VB6 code. The problem I am having is that the hIcon is an Integer and I need to set it as a Form.Icon object. This apparently was allowed in VB6 but not in .NET. How can I do what I am looking to do.
<StructLayout(LayoutKind.S equential, CharSet:=CharSet.ANSI)> Public 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
<VBFixedString(64), System.Runtime.InteropServ ices.Marsh alAs(Syste m.Runtime. InteropSer vices.Unma nagedType. ByValTStr, SizeConst:=64)> Public szTip As String
End Structure
<StructLayout(LayoutKind.S
Dim cbSize As Integer
Dim hwnd As Integer
Dim uId As Integer
Dim uFlags As Integer
Dim uCallBackMessage As Integer
Dim hIcon As Integer
<VBFixedString(64), System.Runtime.InteropServ
End Structure
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
How do you convert an icon into an IntPtr?
With nid
.cbSize = Len(nid)
.hwnd = New IntPtr(Me.Handle.ToInt32)
.uId = VariantType.Null
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallBackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon
End With
With nid
.cbSize = Len(nid)
.hwnd = New IntPtr(Me.Handle.ToInt32)
.uId = VariantType.Null
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallBackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon
End With
Usage is something like this (from a form with an icon):
ShowNotifyIconBalloon(Me.H andle, Me.Icon.Handle, "Application", "This is a test of the radio broadcast system.")
ShowNotifyIconBalloon(Me.H
Be sure to add
Imports System.Runtime.InteropServ ices
to the project
Imports System.Runtime.InteropServ
to the project
Public Shared Sub ShowNotifyIconBalloon(ByVa
ByVal ptrIcon As IntPtr, ByVal strTitle As String, ByVal strText As String)
Try
Dim uNIF As NOTIFYICONDATA
With uNIF
.cbSize = Marshal.SizeOf(uNIF)
.hwnd = ptrHandle
.uID = 1
.dwInfoFlags = NIF_ICON Or NIF_MESSAGE Or NIIF_WARNING
.uCallbackMessage = New IntPtr(&H500)
.uVersion = NOTIFYICON_VERSION
.hIcon = ptrIcon
End With
Dim boolResult As Boolean = Shell_NotifyIcon(NIM_ADD, uNIF)
'// Send a balloon message
With uNIF
.uFlags = NIF_INFO
.uVersion = 2000
.szInfoTitle = strTitle
.szInfo = strText
.dwInfoFlags = NIIF_INFO
End With
boolResult = Shell_NotifyIcon(NIM_MODIF
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub 'ShowNotifyIconBalloon'
Bob