Re: Grab sent messages/text
You can obviously handle many different events of many different objects but the one thing that happens every time something happens that relates to the GUI of your app is that the WndProc method is called. You can override the WndProc method and examine all the Windows messages that are sent to your app and act on whichever you like. You would then invoke the base implementation of the method if you want the default processing to occur for that message. Note though that there will likely be multiple Windows messages received for each .NET event.
Re: Grab sent messages/text
Is there an easy way I can just "watch" what comes in without having to do serious edits? And how would I access this WndProc method?
Re: Grab sent messages/text
Re: Grab sent messages/text
Quote:
Originally Posted by c0rrupt
/N = sn0291fz4qv2
Er .. what?
Re: Grab sent messages/text
VB Code:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Console.WriteLine(m.ToString)
MyBase.WndProc(m)
End Sub
Would dump all the windows messages to the debug window for you.. obviously that can be modified to store in a file, whatever..
Bill
Re: Grab sent messages/text
Quote:
Originally Posted by Inuyasha1782
Is there an easy way I can just "watch" what comes in without having to do serious edits? And how would I access this WndProc method?
You override the method, as I said.
VB Code:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Debug.WriteLine(String.Format("Windows message {0} received.", DirectCast(m.Msg, WndMsg).ToString()))
MyBase.WndProc(m)
End Sub
The Msg property of the Message object is an Integer that corresponds to one of the Windows message constants defined in the Windows API. The WndMsg enumeration that I have referred to in that code can be found here. It's up to you to work out the meaning of each of those messages. A Net search should turn up a description of each one.
Re: Grab sent messages/text
Well this is what I have concluded so far:
VB Code:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Dim test As String
test = DirectCast(m.Msg, WndMsg).ToString()
If test = "WM_KEYFIRST" Then
MsgBox(m.ToString)
End If
MyBase.WndProc(m)
End Sub
Now if I press a key, the msgbox well return "WM_KEYDOWN" because that's the first event that happens with a key. Here is sample contents of the message:
Quote:
msg=0x100 (WM_KEYDOWN) hwnd=0x58063c wparam=0x47 lparam=0x220001 result=0x0
Now I just need to determine what key was sent, but I don't think it's in that message, and I can't find any messages that would be sent when the key was pressed, like it's ascii or character value. Any ideas?
Re: Grab sent messages/text
The Message object has other properties too. I don't know for sure as I've never tried to do it myself but I would guess that the data about the key would be contained in either the LParam or WParam property.
I just went to MSDN and searched for WM_KEYDOWN and it says that the virtual key code for the key that was depressed is contained in the WParam property.
Re: Grab sent messages/text
Yes, depending on the message the wParam and lParam will be needed and in some cases you need both. This is Subclassing in .NET done easy for you. In VB6 subclassing was a pain but you may find much more info on subclassing in VB6. Its the same messages and parameters in both languages.