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. Hook problem

Hook problem

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
2 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.
  • S Offline
    S Offline
    Silly Boy
    wrote on last edited by
    #1

    Hi every body! I have created a global hook function (in Dll) to capture Keyboard events. Every a key has been pressed, the hook function send a user-defined message to my application. My problem is: My application can only receive the message, when it has focus. Could you tell me why? And How can I correct it? Thanks! //Hook function static LRESULT CALLBACK KeyboardHook(UINT nCode, WPARAM wParam, LPARAM lParam) { if( (nCode >=0) && (nCode == HC_ACTION) && (wParam == VK_SNAPSHOT)) PostMessage(hWndReceiver, UWM_CAPTURED,0,0); return CallNextHookEx(hookKeyBoard,nCode,wParam,lParam); } //Message Map BEGIN_MESSAGE_MAP(CTestHook, CDialog) ON_REGISTERED_MESSAGE(UWM_CAPTURED,OnCapture) //{{AFX_MSG_MAP(CTestDllDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP END_MESSAGE_MAP() // afx_msg bool OnCapture(WPARAM wParam, LPARAM lParam); xyz

    D 1 Reply Last reply
    0
    • S Silly Boy

      Hi every body! I have created a global hook function (in Dll) to capture Keyboard events. Every a key has been pressed, the hook function send a user-defined message to my application. My problem is: My application can only receive the message, when it has focus. Could you tell me why? And How can I correct it? Thanks! //Hook function static LRESULT CALLBACK KeyboardHook(UINT nCode, WPARAM wParam, LPARAM lParam) { if( (nCode >=0) && (nCode == HC_ACTION) && (wParam == VK_SNAPSHOT)) PostMessage(hWndReceiver, UWM_CAPTURED,0,0); return CallNextHookEx(hookKeyBoard,nCode,wParam,lParam); } //Message Map BEGIN_MESSAGE_MAP(CTestHook, CDialog) ON_REGISTERED_MESSAGE(UWM_CAPTURED,OnCapture) //{{AFX_MSG_MAP(CTestDllDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP END_MESSAGE_MAP() // afx_msg bool OnCapture(WPARAM wParam, LPARAM lParam); xyz

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Silly Boy wrote: My application can only receive the message, when it has focus. Does that imply that the PostMessage() statement is posting the message regardless of what window has the focus? If not, I'd be curious if any of the three conditions preceding the PostMessage() statement are evaluating to FALSE.


      "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

      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