重写Notification有感~~

为了给程序添加一个Balloon Notification又不使用opennetcf,就花了几个小时功夫把opennetcf里面有关Notification类的c#程序提取出来整理了,最终翻译成了VB.net,感触颇深。本人才疏学浅,就写写自己的一些感受吧~~
1、vb.net与c#之间还是有一定的差异,对于大段的程序用c# to vb.net Convertor程序反而起不到好大的效果,却会使程序变得混乱。建议小段程序使用Convertor,自己整理代码。
2、vb.net里面直接声明public event eventName(byval Param1 as object,...) 这样比用c#的委托那样搞过去搞过来写一大堆代码方便。我就郁闷c#里面没有看到过类似的用法呢?是不是c#不支持这样的语法哦~~声明:我对c#不是很熟悉哈~~~
3、Platform Invoke看起来比较复杂,但是做起来还是简单。只要理解了如何把各个变量的指针找到很多事情就好办了。Opennetcf里面又很多关于P/Invoke的例子,可以借鉴学习。
例如关于如何提取图标的例子(vb.net):
 
ExpandedBlockStart.gif ContractedBlock.gif Private   Declare   Function ExtractIconEx() Function ExtractIconEx Lib "coredll.dll" (ByVal fileName As StringByVal index As IntegerByVal hIconLarge As IntegerByRef hIconSmall As IntPtr, ByVal nIcons As IntegerAs IntPtr
InBlock.gif
private mIcon as Intptr
InBlock.gif
InBlock.gifExtractIconEx(fullname, 
00, mIcon, 1)

4、Opennetcf太大了,直接用不太好。如果需要其中很小一块功能而给客户安装一个新的类库有些浪费了,可以通过代码重写来达到要求。有些东西可以找替换的。比如在.net cf没有guid.newGuid方法,虽然opennetcf里面有GuidEx类,但如果层层深入翻译成vb.net代码会遇到很多问题。最为严重的就是c#里面的移位操作所带来的麻烦。这是,变通一下,找到了微软的MSDN里面的PocketGuid解决了这个问题(见下)
介绍文章请见: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/PPCGuidGen.asp
None.gif Imports  System.Runtime.InteropServices
None.gif
None.gif
'
None.gif'
 Generate GUIDs on  the  .NET Compact Framework.
None.gif'
ExpandedBlockStart.gifContractedBlock.gif
Public   Class PocketGuid Class PocketGuid
InBlock.gif
InBlock.gif    
' guid variant types
ExpandedSubBlockStart.gifContractedSubBlock.gif
    Private Enum GuidVariantEnum GuidVariant
InBlock.gif        ReservedNCS 
= &H0
InBlock.gif        Standard 
= &H2
InBlock.gif        ReservedMicrosoft 
= &H6
InBlock.gif        ReservedFuture 
= &H7
ExpandedSubBlockEnd.gif    
End Enum

InBlock.gif
InBlock.gif    
' guid version types
ExpandedSubBlockStart.gifContractedSubBlock.gif
    Private Enum GuidVersionEnum GuidVersion
InBlock.gif        TimeBased 
= &H1
InBlock.gif        Reserved 
= &H2
InBlock.gif        NameBased 
= &H3
InBlock.gif        Random 
= &H4
ExpandedSubBlockEnd.gif    
End Enum

InBlock.gif
InBlock.gif    
' constants  that are used in the class
ExpandedSubBlockStart.gifContractedSubBlock.gif
    Private Class ConstValuesClass ConstValues
InBlock.gif        
' number of  bytes in guid
InBlock.gif
        Public Const ByteArraySize As Integer = 16
InBlock.gif
InBlock.gif        
' multiplex  variant  info
InBlock.gif
        Public Const VariantByte As Integer = 8
InBlock.gif        
Public Const VariantByteMask As Integer = &H3F
InBlock.gif        
Public Const VariantByteShift As Integer = 6
InBlock.gif
InBlock.gif        
' multiplex  version  info
InBlock.gif
        Public Const VersionByte As Integer = 7
InBlock.gif        
Public Const VersionByteMask As Integer = &HF
InBlock.gif        
Public Const VersionByteShift As Integer = 4
ExpandedSubBlockEnd.gif    
End Class

InBlock.gif
InBlock.gif    
' imports for the crypto api functions
ExpandedSubBlockStart.gifContractedSubBlock.gif
    Private Class WinApiClass WinApi
InBlock.gif        
Public Const PROV_RSA_FULL As Integer = 1
InBlock.gif        
Public Const CRYPT_VERIFYCONTEXT As Integer = &HF0000000
InBlock.gif
InBlock.gif        
<DllImport("coredll.dll")> _
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Shared Function CryptAcquireContext()Function CryptAcquireContext( _
InBlock.gif           
ByRef phProv As IntPtr, ByVal pszContainer As String, _
InBlock.gif           
ByVal pszProvider As StringByVal dwProvType As Integer, _
InBlock.gif           
ByVal dwFlags As IntegerAs Boolean
ExpandedSubBlockEnd.gif        
End Function

InBlock.gif
InBlock.gif        
<DllImport("coredll.dll")> _
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Shared Function CryptReleaseContext()Function CryptReleaseContext( _
InBlock.gif           
ByVal hProv As IntPtr, ByVal dwFlags As IntegerAs Boolean
ExpandedSubBlockEnd.gif        
End Function

InBlock.gif
InBlock.gif        
<DllImport("coredll.dll")> _
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Shared Function CryptGenRandom()Function CryptGenRandom( _
InBlock.gif           
ByVal hProv As IntPtr, ByVal dwLen As Integer, _
InBlock.gif           
ByVal pbBuffer() As ByteAs Boolean
ExpandedSubBlockEnd.gif        
End Function

ExpandedSubBlockEnd.gif    
End Class

InBlock.gif
InBlock.gif    
' all static methods
ExpandedSubBlockStart.gifContractedSubBlock.gif
    Private Sub New()Sub New()
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
InBlock.gif    
' Return a new System.Guid object.
ExpandedSubBlockStart.gifContractedSubBlock.gif
    Public Shared Function NewGuid()Function NewGuid() As Guid
InBlock.gif        
Dim hCryptProv As IntPtr = IntPtr.Zero
InBlock.gif        
Dim guid As Guid = guid.Empty
InBlock.gif
InBlock.gif        
Try
InBlock.gif            
' holds  random bits  for  guid
InBlock.gif
            Dim bits(ConstValues.ByteArraySize - 1As Byte
InBlock.gif
InBlock.gif            
' get crypto provider handle
InBlock.gif
            If Not WinApi.CryptAcquireContext(hCryptProv, NothingNothing, _
InBlock.gif               WinApi.PROV_RSA_FULL, WinApi.CRYPT_VERIFYCONTEXT) 
Then
InBlock.gif                
Throw New SystemException( _
InBlock.gif                   
"Failed  to acquire cryptography  handle.")
InBlock.gif            
End If
InBlock.gif
InBlock.gif            
' generate a 128 bit (16 byte) cryptographically random  number
InBlock.gif
            If Not WinApi.CryptGenRandom(hCryptProv, bits.Length, bits) Then
InBlock.gif                
Throw New SystemException( _
InBlock.gif                   
"Failed  to generate  cryptography random  bytes.")
InBlock.gif            
End If
InBlock.gif
InBlock.gif            
' set the variant
InBlock.gif
            bits(ConstValues.VariantByte) = bits(ConstValues.VariantByte) And _
InBlock.gif               
CByte(ConstValues.VariantByteMask)
InBlock.gif            bits(ConstValues.VariantByte) 
= bits(ConstValues.VariantByte) Or _
InBlock.gif               
CByte(GuidVariant.Standard << ConstValues.VariantByteShift)
InBlock.gif
InBlock.gif            
' set the version
InBlock.gif
            bits(ConstValues.VersionByte) = bits(ConstValues.VersionByte) And _
InBlock.gif               
CByte(ConstValues.VersionByteMask)
InBlock.gif            bits(ConstValues.VersionByte) 
= bits(ConstValues.VersionByte) Or _
InBlock.gif               
CByte(GuidVersion.Random << ConstValues.VersionByteShift)
InBlock.gif
InBlock.gif            
' create the new System.Guid object
InBlock.gif
            guid = New Guid(bits)
InBlock.gif        
Finally
InBlock.gif            
' release the crypto provider handle
InBlock.gif
            If Not hCryptProv.Equals(IntPtr.Zero) Then
InBlock.gif                WinApi.CryptReleaseContext(hCryptProv, 
0)
InBlock.gif            
End If
InBlock.gif        
End Try
InBlock.gif
InBlock.gif        
Return guid
ExpandedSubBlockEnd.gif    
End Function

ExpandedBlockEnd.gif
End Class

None.gif
None.gif
如果想直接应用opennetcf里面的guidex类的话vb.net会花费很大的功夫来改写,具体可以看看opennetcf的源代码。
6、最后一个:想得到,就做得到!

好了,睡觉了~~~很晚了,最后把我翻译的代码贴在这里供大家参考评价,有些c#的我不太明确的都已用#######注释标明。
None.gif Imports  System.Runtime.InteropServices
ExpandedBlockStart.gifContractedBlock.gif
Namespace PocketBallon Namespace PocketBallon
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Class NotificationClass Notification
InBlock.gif        
Private WithEvents msgwnd As NotificationMessageWindow
InBlock.gif        
Private Shared notifications As Hashtable
InBlock.gif        
Private Shared id As Integer
InBlock.gif        
Private Shared clsid As Guid = PocketGuid.NewGuid
InBlock.gif
InBlock.gif        
Private m_data As SHNOTIFICATIONDATA
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Private Structure SHNOTIFICATIONDATAStructure SHNOTIFICATIONDATA
InBlock.gif            
Public cbStruct As Integer
InBlock.gif            
Public dwId As Integer
InBlock.gif            
Public npPriority As SHNP
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Public Enum SHNPEnum SHNP As Integer
InBlock.gif                INFORM 
= &H1B1
InBlock.gif                ICONIC 
= 0
ExpandedSubBlockEnd.gif            
End Enum

InBlock.gif            
Public csDuration As Integer
InBlock.gif            
Public hicon As IntPtr
InBlock.gif            
Public grfFlags As SHNF
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Public Enum SHNFEnum SHNF As Integer
InBlock.gif                STRAIGHTTOTRAY 
= &H1
InBlock.gif                CRITICAL 
= &H2
InBlock.gif                FORCEMESSAGE 
= &H8
InBlock.gif                DISPLAYON 
= &H10
InBlock.gif                SILENT 
= &H20
ExpandedSubBlockEnd.gif            
End Enum

InBlock.gif            
Public clsid As Guid
InBlock.gif            
Public hwndSink As IntPtr
InBlock.gif            
Public pszHTML As IntPtr
InBlock.gif            
Public pszTitle As IntPtr
InBlock.gif            
Public lParam As Integer
ExpandedSubBlockEnd.gif        
End Structure

InBlock.gif
InBlock.gif        
Private mIcon As IntPtr
InBlock.gif        
Private mDuration As Integer = 10
InBlock.gif        
Private mText As String = String.Empty
InBlock.gif        
Private mCaption As String = String.Empty
InBlock.gif        
Private mCritical As Boolean = False
InBlock.gif        
Private mVisible As Boolean = False
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
Properties#Region "Properties"
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Property Caption()Property Caption() As String
InBlock.gif            
Get
InBlock.gif                
Return mCaption
InBlock.gif            
End Get
InBlock.gif            
Set(ByVal value As String)
InBlock.gif                mCaption 
= value
InBlock.gif            
End Set
ExpandedSubBlockEnd.gif        
End Property

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Property Critical()Property Critical() As Boolean
InBlock.gif            
Get
InBlock.gif                
Return mCritical
InBlock.gif            
End Get
InBlock.gif            
Set(ByVal value As Boolean)
InBlock.gif                mCritical 
= value
InBlock.gif            
End Set
ExpandedSubBlockEnd.gif        
End Property

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Property IconHandle()Property IconHandle() As IntPtr
InBlock.gif            
Get
InBlock.gif                
Return mIcon
InBlock.gif            
End Get
InBlock.gif            
Set(ByVal value As IntPtr)
InBlock.gif                mIcon 
= value
InBlock.gif            
End Set
ExpandedSubBlockEnd.gif        
End Property

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Property InitialDuration()Property InitialDuration() As Integer
InBlock.gif            
Get
InBlock.gif                
Return mDuration
InBlock.gif            
End Get
InBlock.gif            
Set(ByVal value As Integer)
InBlock.gif                mDuration 
= value
InBlock.gif            
End Set
ExpandedSubBlockEnd.gif        
End Property

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Property Text()Property Text() As String
InBlock.gif            
Get
InBlock.gif                
Return mText
InBlock.gif            
End Get
InBlock.gif            
Set(ByVal value As String)
InBlock.gif                mText 
= value
InBlock.gif            
End Set
ExpandedSubBlockEnd.gif        
End Property

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Property Visiable()Property Visiable() As Boolean
InBlock.gif            
Get
InBlock.gif                
Return mVisible
InBlock.gif            
End Get
InBlock.gif            
Set(ByVal value As Boolean)
InBlock.gif                mVisible 
= value
InBlock.gif                
If value = True Then
InBlock.gif                    Show()
InBlock.gif                
Else
InBlock.gif                    Remove()
InBlock.gif                
End If
InBlock.gif            
End Set
ExpandedSubBlockEnd.gif        
End Property

ExpandedSubBlockEnd.gif
#End Region

InBlock.gif
InBlock.gif        
'#Region "events"
InBlock.gif
        '        'Code here are probably not be well written.
InBlock.gif

InBlock.gif        
'        Public Event BalloonChanged As BalloonChangedEventHandler
InBlock.gif
        '        Public Delegate Sub BalloonChangedEventHandler(ByVal sender As Object, ByVal balevent As BalloonChangedEventArgs)
InBlock.gif
        '        Public Class BalloonChangedEventArgs
InBlock.gif
        '            Inherits EventArgs
InBlock.gif
        '            Private m_visible As Boolean
InBlock.gif

InBlock.gif        
'            Public Sub New(ByVal visible As Boolean)
InBlock.gif
        '                m_visible = visible
InBlock.gif
        '            End Sub
InBlock.gif

InBlock.gif        
'            Public ReadOnly Property Visible() As Boolean
InBlock.gif
        '                Get
InBlock.gif
        '                    Return m_visible
InBlock.gif
        '                End Get
InBlock.gif
        '            End Property
InBlock.gif
        '        End Class
InBlock.gif
        '        Friend Sub OnBalloonChanged(ByVal e As BalloonChangedEventArgs)
InBlock.gif
        '            mVisible = e.Visible
InBlock.gif
        '            '#####################################
InBlock.gif
        '            'C# code:
InBlock.gif
        '            '            if(this.BalloonChanged!=null)
InBlock.gif
        '            '    {
InBlock.gif
        '            '        this.BalloonChanged(this, e);
InBlock.gif
        '            '    }
InBlock.gif
        '            '#####################################
InBlock.gif
        '            RaiseEvent BalloonChanged(Me, e)
InBlock.gif
        '        End Sub
InBlock.gif

InBlock.gif        
'        Public Class ResponseSubmittedEventArgs
InBlock.gif
        '            Inherits EventArgs
InBlock.gif
        '            Private m_response As String
InBlock.gif
        '            Public Sub New(ByVal response As String)
InBlock.gif
        '                m_response = response
InBlock.gif
        '            End Sub
InBlock.gif
        '            Public ReadOnly Property Response() As String
InBlock.gif
        '                Get
InBlock.gif
        '                    Return m_response
InBlock.gif
        '                End Get
InBlock.gif
        '            End Property
InBlock.gif
        '        End Class
InBlock.gif
        '        Public Delegate Sub ResponseSubmittedEventHandler(ByVal sender As Object, ByVal respevent As ResponseSubmittedEventArgs)
InBlock.gif
        '        Public Event ResponseSubmitted As ResponseSubmittedEventHandler
InBlock.gif
        '        Friend Sub OnResponseSubmitted(ByVal e As ResponseSubmittedEventArgs)
InBlock.gif
        '            RaiseEvent ResponseSubmitted(Me, e)
InBlock.gif
        '        End Sub
InBlock.gif

InBlock.gif        
'        Public Class CmdClickedEventArgs
InBlock.gif
        '            Inherits EventArgs
InBlock.gif
        '            Private m_response As String
InBlock.gif
        '            Private m_ID As Integer
InBlock.gif
        '            Public Sub New(ByVal m_ID As Integer, ByVal cmd As String)
InBlock.gif
        '                m_response = cmd
InBlock.gif
        '            End Sub
InBlock.gif
        '            Public ReadOnly Property Cmd() As String
InBlock.gif
        '                Get
InBlock.gif
        '                    Return m_response
InBlock.gif
        '                End Get
InBlock.gif
        '            End Property
InBlock.gif

InBlock.gif        
'            Public ReadOnly Property ID() As Integer
InBlock.gif
        '                Get
InBlock.gif
        '                    Return m_ID
InBlock.gif
        '                End Get
InBlock.gif
        '            End Property
InBlock.gif
        '        End Class
InBlock.gif
        '        Public Delegate Sub CmdClickedEventHandler(ByVal sender As Object, ByVal respevent As CmdClickedEventArgs)
InBlock.gif
        '        Public Event CmdClicked As CmdClickedEventHandler
InBlock.gif
        '        Friend Sub OnCmdClicked(ByVal e As CmdClickedEventArgs)
InBlock.gif
        '            RaiseEvent CmdClicked(Me, e)
InBlock.gif
        '        End Sub
InBlock.gif

InBlock.gif        
'#End Region
InBlock.gif
        Public Event CmdClicked(ByVal cmd As Integer)
InBlock.gif        
Public Event LinkClicked(ByVal link As String)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Private Sub OnClicked()Sub OnClicked(ByVal cmd As IntegerHandles msgwnd.CmdClicked
InBlock.gif            
RaiseEvent CmdClicked(cmd)
ExpandedSubBlockEnd.gif        
End Sub

ExpandedSubBlockStart.gifContractedSubBlock.gif        
Private Sub OnLinkClicked()Sub OnLinkClicked(ByVal link As StringHandles msgwnd.LinkClicked
InBlock.gif            
RaiseEvent LinkClicked(link)
ExpandedSubBlockEnd.gif        
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Sub New()Sub New()
InBlock.gif            notifications 
= New Hashtable()
InBlock.gif            msgwnd 
= New NotificationMessageWindow(notifications)
InBlock.gif            
Dim fullname As String = System.Reflection.Assembly.GetCallingAssembly.GetModules()(0).FullyQualifiedName
InBlock.gif            ExtractIconEx(fullname, 
00, mIcon, 1)
InBlock.gif
InBlock.gif            m_data 
= New SHNOTIFICATIONDATA
InBlock.gif            
With m_data
InBlock.gif                .clsid 
= clsid
InBlock.gif                .hwndSink 
= msgwnd.Hwnd
InBlock.gif                .dwId 
= id
InBlock.gif                .cbStruct 
= Marshal.SizeOf(m_data)
InBlock.gif            
End With
InBlock.gif            notifications.Add(id, 
Me)
InBlock.gif            id 
+= 1
ExpandedSubBlockEnd.gif        
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Protected Sub Dispose()Sub Dispose(ByVal disposing As Boolean)
InBlock.gif            Visiable 
= False
InBlock.gif            notifications.Remove(m_data.dwId)
ExpandedSubBlockEnd.gif        
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Private Sub Show()Sub Show()
InBlock.gif            
With m_data
InBlock.gif                .pszHTML 
= StringToHGlobalUni(mText)
InBlock.gif                .pszTitle 
= StringToHGlobalUni(mCaption)
InBlock.gif                .hicon 
= mIcon
InBlock.gif                .csDuration 
= mDuration
InBlock.gif                
If mDuration = 0 Then
InBlock.gif                    .npPriority 
= SHNOTIFICATIONDATA.SHNP.ICONIC
InBlock.gif                
Else
InBlock.gif                    .npPriority 
= SHNOTIFICATIONDATA.SHNP.INFORM
InBlock.gif                
End If
InBlock.gif
InBlock.gif                
'C# code here !!!!!!!!!
InBlock.gif
                '##########################################
InBlock.gif
                '            if(mCritical)
InBlock.gif
                '{
InBlock.gif
                '    m_data.grfFlags |= SHNF.CRITICAL;
InBlock.gif
                '}
InBlock.gif
                'else
InBlock.gif
                '{
InBlock.gif
                '    m_data.grfFlags ^= (m_data.grfFlags & SHNF.CRITICAL);
InBlock.gif
                '}
InBlock.gif
                '###########################################
InBlock.gif

InBlock.gif                
If mCritical Then
InBlock.gif                    .grfFlags 
= .grfFlags Or SHNOTIFICATIONDATA.SHNF.CRITICAL
InBlock.gif                
Else
InBlock.gif                    .grfFlags 
= .grfFlags Or (.grfFlags And SHNOTIFICATIONDATA.SHNF.CRITICAL)
InBlock.gif                
End If
InBlock.gif
InBlock.gif                
Dim hresult As Integer = SHNotificationAdd(m_data)
InBlock.gif                
If (.pszTitle.ToInt32 <> IntPtr.Zero.ToInt32) Then
InBlock.gif                    LocalFree(.pszTitle)
InBlock.gif                    .pszTitle 
= IntPtr.Zero
InBlock.gif                
End If
InBlock.gif                
If (.pszHTML.ToInt32 <> IntPtr.Zero.ToInt32) Then
InBlock.gif                    LocalFree(.pszHTML)
InBlock.gif                    .pszHTML 
= IntPtr.Zero
InBlock.gif                
End If
InBlock.gif            
End With
ExpandedSubBlockEnd.gif        
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Private Sub Remove()Sub Remove()
InBlock.gif            
Dim hresult As Integer = SHNotificationRemove(clsid, m_data.dwId)
ExpandedSubBlockEnd.gif        
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Private Function StringToHGlobalUni()Function StringToHGlobalUni(ByVal s As StringAs IntPtr
InBlock.gif            
Dim LPTR As Integer = &H0 Or &H40
InBlock.gif            
If s Is Nothing Then Return IntPtr.Zero
InBlock.gif            
Dim i As Integer = (s.Length + 1* System.Text.UnicodeEncoding.CharSize
InBlock.gif            
Dim ptr As IntPtr = LocalAlloc(LPTR, i)
InBlock.gif            
'Dim ptr As IntPtr = LocalAlloc(CUInt(LPTR), CUInt(i))
InBlock.gif
            Dim data As Byte() = System.Text.Encoding.Unicode.GetBytes(s)
InBlock.gif            Marshal.Copy(data, 
0, ptr, data.Length)
InBlock.gif            
Return ptr
ExpandedSubBlockEnd.gif        
End Function

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Private Declare Function ExtractIconEx()Function ExtractIconEx Lib "coredll.dll" (ByVal fileName As StringByVal index As IntegerByVal hIconLarge As IntegerByRef hIconSmall As IntPtr, ByVal nIcons As IntegerAs IntPtr
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Private Declare Function LocalAlloc()Function LocalAlloc Lib "coredll.dll" (ByVal uFlags As IntegerByVal Bytes As IntegerAs IntPtr
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Private Declare Function LocalFree()Function LocalFree Lib "coredll.dll" (ByVal hMem As IntPtr) As IntPtr
InBlock.gif        
<DllImport("aygshell.dll", EntryPoint:="#155", SetLastError:=True)> _
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Private Shared Function SHNotificationAdd()Function SHNotificationAdd(ByRef shinfo As SHNOTIFICATIONDATA) As Integer
ExpandedSubBlockEnd.gif        
End Function

InBlock.gif
InBlock.gif        
<DllImport("aygshell.dll", EntryPoint:="#157", SetLastError:=True)> _
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Private Shared Function SHNotificationRemove()Function SHNotificationRemove(ByRef clsid As Guid, ByVal dwID As IntegerAs Integer
ExpandedSubBlockEnd.gif        
End Function

ExpandedSubBlockEnd.gif    
End Class

ExpandedBlockEnd.gif
End Namespace

None.gif Imports  System.Runtime.InteropServices
None.gif
Imports  Microsoft.WindowsCE
ExpandedBlockStart.gifContractedBlock.gif
Namespace PocketBallon Namespace PocketBallon
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Friend Class NotificationMessageWindowClass NotificationMessageWindow
InBlock.gif        
Inherits Microsoft.WindowsCE.Forms.MessageWindow
InBlock.gif        
Private m_notifications As Hashtable
InBlock.gif        
Public Event BallonChanged(ByVal visible As Boolean)
InBlock.gif        
Public Event CmdClicked(ByVal cmd As Integer)
InBlock.gif        
Public Event LinkClicked(ByVal link As String)
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Sub New()Sub New(ByVal notifications As Hashtable)
InBlock.gif            m_notifications 
= notifications
ExpandedSubBlockEnd.gif        
End Sub

ExpandedSubBlockStart.gifContractedSubBlock.gif        
Protected Overrides Sub WndProc()Sub WndProc(ByRef m As Message)
InBlock.gif            
Select Case m.Msg
InBlock.gif                
Case 78
InBlock.gif                    
Dim nm As NMSHN = CType(Marshal.PtrToStructure(m.LParam, GetType(NMSHN)), NMSHN)
InBlock.gif                    
Dim n As Notification = CType(m_notifications(nm.idFrom), Notification)
InBlock.gif                    
Select Case nm.code
InBlock.gif                        
Case NMSHN.SHNN.DISMISS
InBlock.gif                            
RaiseEvent BallonChanged(True)
InBlock.gif                            
'n.OnBalloonChanged(New PocketBallon.Notification.BalloonChangedEventArgs(False))
InBlock.gif
                        Case NMSHN.SHNN.SHOW
InBlock.gif                            
RaiseEvent BallonChanged(False)
InBlock.gif                            
'n.OnBalloonChanged(New PocketBallon.Notification.BalloonChangedEventArgs(True))
InBlock.gif
                        Case NMSHN.SHNN.LINKSEL
InBlock.gif                            
Dim link As String = Marshal.PtrToStringUni(New IntPtr(nm.union1))
InBlock.gif                            
RaiseEvent LinkClicked(link)
InBlock.gif                            
'n.OnResponseSubmitted(New PocketBallon.Notification.ResponseSubmittedEventArgs(link))
InBlock.gif
                    End Select
InBlock.gif                
Case &H111
InBlock.gif                    
'Dim nm As NMSHN = CType(Marshal.PtrToStructure(lastLParam, GetType(NMSHN)), NMSHN)
InBlock.gif
                    'Dim n As Notification = CType(m_notifications(nm.idFrom), Notification)
InBlock.gif
                    'n.OnCmdClicked(New PocketBallon.Notification.CmdClickedEventArgs(1, "1"))
InBlock.gif
                    RaiseEvent CmdClicked(m.WParam.ToInt32)
InBlock.gif            
End Select
InBlock.gif            
MyBase.WndProc(m)
ExpandedSubBlockEnd.gif        
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Private Structure NMSHNStructure NMSHN
InBlock.gif            
Public hwndFrom As IntPtr
InBlock.gif            
Public idFrom As Integer
InBlock.gif            
Public code As SHNN
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Public Enum SHNNEnum SHNN As Integer
InBlock.gif                LINKSEL 
= -1000
InBlock.gif                DISMISS 
= -1001
InBlock.gif                SHOW 
= -1002
ExpandedSubBlockEnd.gif            
End Enum

InBlock.gif            
Public lParam As Integer
InBlock.gif            
Public dwReturn As Integer
InBlock.gif            
Public union1 As Integer
InBlock.gif            
Public union2 As Integer
ExpandedSubBlockEnd.gif        
End Structure

InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif    
End Class

ExpandedBlockEnd.gif
End Namespace
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值