|
-
May 1st, 2006, 12:01 AM
#1
Thread Starter
Frenzied Member
Grab sent messages/text
Is there a way to grab all messages that are globally sent to your program. Like if the user has your form active and starts typing, or pressing keys, is it possible to grab these? This goes for entering text into like a textbox or something as well. I just need to catch everything that has to do with my program. Is it possible, and how to do it? Thanks in advanced
Age - 15 ::: Level - Advanced
If you find my post useful please ::Rate It::

-
May 1st, 2006, 12:08 AM
#2
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.
-
May 1st, 2006, 12:11 AM
#3
Thread Starter
Frenzied Member
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?
Age - 15 ::: Level - Advanced
If you find my post useful please ::Rate It::

-
May 1st, 2006, 12:12 AM
#4
Member
Re: Grab sent messages/text
-
May 1st, 2006, 12:16 AM
#5
Thread Starter
Frenzied Member
Re: Grab sent messages/text
 Originally Posted by c0rrupt
/N = sn0291fz4qv2
Er .. what?
Age - 15 ::: Level - Advanced
If you find my post useful please ::Rate It::

-
May 1st, 2006, 12:19 AM
#6
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
-
May 1st, 2006, 12:21 AM
#7
Re: Grab sent messages/text
 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.
-
May 1st, 2006, 09:38 AM
#8
Thread Starter
Frenzied Member
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:
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?
Age - 15 ::: Level - Advanced
If you find my post useful please ::Rate It::

-
May 1st, 2006, 03:01 PM
#9
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.
-
May 1st, 2006, 03:10 PM
#10
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|