Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. intercepting WM_CHAR message

intercepting WM_CHAR message

Scheduled Pinned Locked Moved C / C++ / MFC
debugging
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Adno
    wrote on last edited by
    #1

    im trying to get the WM_CHAR message and this set up is not doing it. i have an edit text box in my window and all im getting is the keydown message when i type to it. LRESULT CALLBACK GetMsgProc(int code, WPARAM wParam, LPARAM lParam){ if(code == HC_ACTION){ MSG* pMsg = (MSG*)lParam; if(pMsg->message == WM_CHAR){ int i=0; i = i +10;//test for WM_CHAR breakpoint } } return CallNextHookEx(g_KeybdHook, code, wParam, lParam); } hook in main: g_KeybdHook = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, 0,GetCurrentThreadId()); thanks

    M 1 Reply Last reply
    0
    • A Adno

      im trying to get the WM_CHAR message and this set up is not doing it. i have an edit text box in my window and all im getting is the keydown message when i type to it. LRESULT CALLBACK GetMsgProc(int code, WPARAM wParam, LPARAM lParam){ if(code == HC_ACTION){ MSG* pMsg = (MSG*)lParam; if(pMsg->message == WM_CHAR){ int i=0; i = i +10;//test for WM_CHAR breakpoint } } return CallNextHookEx(g_KeybdHook, code, wParam, lParam); } hook in main: g_KeybdHook = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, 0,GetCurrentThreadId()); thanks

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      lParam is not a MSG pointer in a keyboard hook proc. See KeyboardProc Function[^]. It seems to me it would be simpler to subclass the edit control than to use a keyboard hook. Safe Subclassing in Win32[^] Mark

      Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the letter Z

      A 1 Reply Last reply
      0
      • M Mark Salsbery

        lParam is not a MSG pointer in a keyboard hook proc. See KeyboardProc Function[^]. It seems to me it would be simpler to subclass the edit control than to use a keyboard hook. Safe Subclassing in Win32[^] Mark

        Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the letter Z

        A Offline
        A Offline
        Adno
        wrote on last edited by
        #3

        hi mark, im using "WH_GETMESSAGE" one of the options here and i should be dealing with this GetMsgProc Function right? obviously not since is not working :sigh: what tells you that im dealing with "keyboard hook proc", more importantly how do i fix it. im practicing to write a dll so i want to get my head around this hooking business. Thank You

        M 1 Reply Last reply
        0
        • A Adno

          hi mark, im using "WH_GETMESSAGE" one of the options here and i should be dealing with this GetMsgProc Function right? obviously not since is not working :sigh: what tells you that im dealing with "keyboard hook proc", more importantly how do i fix it. im practicing to write a dll so i want to get my head around this hooking business. Thank You

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Lamefif wrote:

          im using "WH_GETMESSAGE"

          :doh: Got it. I apparently can't read :) Your code works for me. What's going wrong on your end? Mark

          Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the letter Z

          A 1 Reply Last reply
          0
          • M Mark Salsbery

            Lamefif wrote:

            im using "WH_GETMESSAGE"

            :doh: Got it. I apparently can't read :) Your code works for me. What's going wrong on your end? Mark

            Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the letter Z

            A Offline
            A Offline
            Adno
            wrote on last edited by
            #5

            i cleaned it up alot due to experimenting lol but this is it. CODE

            M 1 Reply Last reply
            0
            • A Adno

              i cleaned it up alot due to experimenting lol but this is it. CODE

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              Try this message loop:

              g_KeybdHook = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, 0,GetCurrentThreadId());

              while (GetMessage(&msg, 0, 0, 0))
              {
              TranslateMessage(&msg);
              DispatchMessage(&msg);
              }

              UnhookWindowsHookEx(g_KeybdHook);

              Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the letter Z

              A 1 Reply Last reply
              0
              • M Mark Salsbery

                Try this message loop:

                g_KeybdHook = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, 0,GetCurrentThreadId());

                while (GetMessage(&msg, 0, 0, 0))
                {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
                }

                UnhookWindowsHookEx(g_KeybdHook);

                Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the letter Z

                A Offline
                A Offline
                Adno
                wrote on last edited by
                #7

                :laugh: Thank You ps have you any idea how to load and use .klc files done with Microsoft Keyboard Layout Creator

                M 1 Reply Last reply
                0
                • A Adno

                  :laugh: Thank You ps have you any idea how to load and use .klc files done with Microsoft Keyboard Layout Creator

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #8

                  Lamefif wrote:

                  ps have you any idea how to load and use .klc files

                  No, sorry. Maybe the section "Languages, Locales, and Keyboard Layouts" here[^] will help? Mark

                  Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the letter Z

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups