I know a lot of people here are experienced with the Win32 API here, and I came up with the idea of being able to hide and show tray icons, programmatically.
I've been fiddling with the Win32 API recently, and I found it very insightful as to the operations involved 'behind the scenes'. I am using the
Shell_NotifyIconA function (a member of shell32), and am failing to remove or modify information.
I want to be able to hide and show an icon, so I thought of the idea of nulling the icon property, so the icon would still be there, but hidden, and then setting the icon back to it's previous state. However, the function doesn't seem to want to work, it always seems to want to return 0!

Here is the code I am using:
CODE
Imports System.Runtime.InteropServices
Public Class Form1
' The NOTIFYICONDATA Struct
Private Structure NOTIFYICONDATA
Public cbSize As Long
Public hWnd As Long
Public uId As Long
Public uFlags As Long
Public uCallBackMessage As Long
Public hIcon As Long
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _
Public szTip As String
End Structure
' The messages to send to the function
Private Const NIM_ADD As Int32 = &H0
Private Const NIM_MODIFY As Int32 = &H1
Private Const NIM_DELETE As Int32 = &H2
' The variable we will be using to set the icon properties.
Private pIcon As New NOTIFYICONDATA
' The API Function we will be using.
Private Declare Auto Function Shell_NotifyIconA Lib "shell32" (ByVal dwMessage As Integer, _
ByRef pnid As NOTIFYICONDATA) As Integer
' Null the MSN Icon (for test purposes, the only tray icon on my comp atm :P)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
pIcon.hWnd = 5444
pIcon.hIcon = IntPtr.Zero
Dim res As Int32 = Shell_NotifyIconA(NIM_MODIFY, pIcon)
' It seems to <3 returning zero :S.
MessageBox.Show(res)
End Sub
End Class
Any guidance or help would be appreciated, and before suspision arises I am not planning on using this to circumvent security, rather learn about the process involved for self-improvement.
EDIT: OPPS! I was using the process ID instead of a window handle. I'm so tired. LOL! I will test when I'm done using the correct parameters!
EDIT 2: Damn, thought I was on to something, that doesn't work either.

Thanks in advance!
This post has been edited by RodgerB: 24 Jan, 2008 - 04:22 AM