I'm trying to port a application over from vb to vb.net 2005, the application uses the sendmessage and windows hooks to talk to other apps.. I am working on receiving the messages at the moment. Now I have found a bit of code that hooks my app into windows and I do get a message box up when something has been received, but I dont know how to display the message thats been received as a string.
Below is the code I have started to adapt..
In the Form1 I have..
In a Subclass Form I have..
Now I know the message should in the m.LParam but its not...
Also I am unsure about unloading this hook as in VB you needed to do it, but as there doesnt seem to be a Form_Unload here where would I cancel the hook on ending the program ?
hope someone can help..
Steve
Below is the code I have started to adapt..
In the Form1 I have..
VB.NET:
'The Object of Subclassing to SubClass any Control
Dim WithEvents abc As theAngrycodeR.SubClassing
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
abc = New theAngrycodeR.SubClassing(Me.Handle)
abc.SubClass = True
End Sub
Private Sub abc_CallBackProc(ByRef m As System.Windows.Forms.Message) Handles abc.CallBackProc
Dim bytes() As Byte
Select Case m.Msg
Case WM_COPYDATA
MsgBox(m.LParam)
End Select
End Sub
In a Subclass Form I have..
VB.NET:
Imports System.Windows.Forms
Namespace theAngrycodeR
'To Subclass any Control, You need to Inherit From NativeWindow Class
Public Class SubClassing
Inherits System.Windows.Forms.NativeWindow
'Event Declaration. This event will be raised when any Message will be posted to the Control
Public Event CallBackProc(ByRef m As Message)
'Flag which indicates that either Event should be raised or not
Private m_Subclassed As Boolean = False
'During Creation of Object of this class, Pass the Handle of Control which you want to SubClass
Public Sub New(ByVal handle As IntPtr)
MyBase.AssignHandle(handle)
End Sub
'Terminate The SubClassing
'There is no need to Create this Method. Cuz, when you will create the Object
'Of this class, You will have the Method Named ReleaseHandle.
'Just call that as you can see in this Sub
'Public Sub RemoveHandle()
' MyBase.ReleaseHandle()
'End Sub
'To Enable or Disable Receiving Messages
Public Property SubClass() As Boolean
Get
Return m_Subclassed
End Get
Set(ByVal Value As Boolean)
m_Subclassed = Value
End Set
End Property
Protected Overrides Sub WndProc(ByRef m As Message)
If m_Subclassed Then 'If Subclassing Enabled then RaiseEvent
RaiseEvent CallBackProc(m)
End If
MyBase.WndProc(m)
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class
End Namespace
Now I know the message should in the m.LParam but its not...
Also I am unsure about unloading this hook as in VB you needed to do it, but as there doesnt seem to be a Form_Unload here where would I cancel the hook on ending the program ?
hope someone can help..
Steve