Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Converting NOTIFYICONDATA from VB6 to VB.NET

Posted on 2004-08-03
5
1,844 Views
Last Modified: 2008-01-16
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.Sequential, 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.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=64)> Public szTip As String

    End Structure
0
Comment
Question by:d532335
  • 3
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11707026
Are you trying to show a balloon on the task bar:

   Public Shared Sub ShowNotifyIconBalloon(ByVal ptrHandle As IntPtr, _
      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_MODIFY, uNIF)

      Catch ex As Exception

         MsgBox(ex.ToString)

      End Try

   End Sub 'ShowNotifyIconBalloon'

Bob
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 300 total points
ID: 11707132
Forgot the definitions:

   <StructLayout(LayoutKind.Sequential)> Private Structure NOTIFYICONDATA
      Dim cbSize As Int32
      Dim hwnd As IntPtr
      Dim uID As Int32
      Dim uFlags As Int32
      Dim uCallbackMessage As IntPtr
      Dim hIcon As IntPtr
      <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> Dim szTip As String
      Dim dwState As Int32
      Dim dwStateMask As Int32
      <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Dim szInfo As String
      Dim uVersion As Int32
      <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)> Dim szInfoTitle As String
      Dim dwInfoFlags As Int32
   End Structure

   Private Const NIF_MESSAGE As Int32 = &H1
   Private Const NIF_ICON As Int32 = &H2
   Private Const NIF_STATE As Int32 = &H8
   Private Const NIF_INFO As Int32 = &H10
   Private Const NIF_TIP As Int32 = &H4
   Private Const NIM_ADD As Int32 = &H0
   Private Const NIM_MODIFY As Int32 = &H1
   Private Const NIM_DELETE As Int32 = &H2
   Private Const NIM_SETVERSION As Int32 = &H4
   Private Const NOTIFYICON_VERSION As Int32 = &H5
   Private Const NIS_HIDDEN As Int32 = &H1
   Private Const NIS_SHAREDICON As Int32 = &H2
   Private Const NIIF_ERROR As Int32 = &H3
   Private Const NIIF_INFO As Int32 = &H1
   Private Const NIIF_NONE As Int32 = &H0
   Private Const NIIF_WARNING As Int32 = &H2
   Private Const NIM_SETFOCUS As Int32 = &H4
   Private Const NIIF_GUID As Int32 = &H5

   Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" _
      (ByVal dwMessage As Int32, ByRef lpData As NOTIFYICONDATA) As Boolean

Bob
0
 

Author Comment

by:d532335
ID: 11708322
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
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11709612
Usage is something like this (from a form with an icon):

ShowNotifyIconBalloon(Me.Handle, Me.Icon.Handle, "Application", "This is a test of the radio broadcast system.")
0
 

Expert Comment

by:raetrace
ID: 12578637
Be sure to add

Imports System.Runtime.InteropServices

to the project
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Gridview selected row 9 49
vb.net help 4 34
how to apply link to datagridview cell in vb.net without looping the grid rows 1 28
VB.Net. Reading xml value 6 29
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question