Results 1 to 10 of 10

Thread: Grab sent messages/text

  1. #1

    Thread Starter
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    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::


  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    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::


  4. #4
    Member
    Join Date
    Feb 2006
    Posts
    61

    Re: Grab sent messages/text

    /N = sn0291fz4qv2

  5. #5

    Thread Starter
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    Re: Grab sent messages/text

    Quote Originally Posted by c0rrupt
    /N = sn0291fz4qv2
    Er .. what?
    Age - 15 ::: Level - Advanced
    If you find my post useful please ::Rate It::


  6. #6
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Grab sent messages/text

    VB Code:
    1. Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    2.         Console.WriteLine(m.ToString)
    3.         MyBase.WndProc(m)
    4.     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
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    2.         Debug.WriteLine(String.Format("Windows message {0} received.", DirectCast(m.Msg, WndMsg).ToString()))
    3.         MyBase.WndProc(m)
    4.     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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    Re: Grab sent messages/text

    Well this is what I have concluded so far:

    VB Code:
    1. Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    2.         Dim test As String
    3.         test = DirectCast(m.Msg, WndMsg).ToString()
    4.         If test = "WM_KEYFIRST" Then
    5.             MsgBox(m.ToString)
    6.         End If
    7.         MyBase.WndProc(m)
    8.     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::


  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width