Click here to Skip to main content
15,908,172 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralHooks and Message Blocking Pin
User 1278224-May-04 15:09
User 1278224-May-04 15:09 
GeneralRe: Hooks and Message Blocking Pin
Ryan Binns24-May-04 18:22
Ryan Binns24-May-04 18:22 
GeneralRe: Hooks and Message Blocking Pin
User 1278224-May-04 18:47
User 1278224-May-04 18:47 
GeneralRe: Hooks and Message Blocking Pin
Blake Miller25-May-04 14:53
Blake Miller25-May-04 14:53 
GeneralRe: Hooks and Message Blocking Pin
User 1278225-May-04 15:24
User 1278225-May-04 15:24 
GeneralRe: Hooks and Message Blocking Pin
Blake Miller25-May-04 15:31
Blake Miller25-May-04 15:31 
GeneralRe: Hooks and Message Blocking Pin
User 1278225-May-04 15:42
User 1278225-May-04 15:42 
GeneralRe: Hooks and Message Blocking Pin
Blake Miller25-May-04 16:01
Blake Miller25-May-04 16:01 
This looks fine, mostly.

Also, you have to 'ignore' your block code if the nCode is less than zero:

<br />
LRESULT CALLBACK MouseProc(<br />
   int    nCode, <br />
   WPARAM wParam, <br />
   LPARAM lParam<br />
){<br />
   if( HC_ACTION == nCode ){<br />
<br />
      // decide to post to main window<br />
      switch( wParam ){<br />
      case WM_MOUSEMOVE:<br />
      case WM_NCMOUSEMOVE:<br />
         PostMessage(g_hWnd,g_hMouseMove,wParam,lParam);<br />
         break;<br />
      default:<br />
         PostMessage(g_hWnd,g_hMouseAct,wParam,lParam);<br />
         break;<br />
      }<br />
<br />
      // we are currently blocking<br />
      if( g_bBlock ){<br />
         return -1;<br />
      }<br />
   }<br />
<br />
   return CallNextHookEx(g_hHookMouse,nCode,wParam,lParam);<br />
}<br />


You should do similarly for the mouse handler.
If you process a hook message while the nCode is NOT HC_ATION you will see bizarre results.

I notice you 'dont pass on' based upon the same global variable: g_bBlock

So, it would seem to me, if your 'block' variable is true, you won't see mouse or keyboard messages posted to anything but your global window.

Except, you might try changing it to
<br />
g_hHookMouse=SetWindowsHookEx(WH_MOUSE_LL,MouseProc,g_hInst,0);<br />

and
<br />
g_hHookKey=SetWindowsHookEx(WH_KEYBOARD_LL,KeyboardProc,g_hInst,0);<br />


So you get raw events, and not ones that have been translated.

Also, in your install code, you will leak a hook handle:
If you keyboard hook install fials, you should unhook the mouse hook before returning false...
GeneralRe: Hooks and Message Blocking Pin
User 1278225-May-04 16:36
User 1278225-May-04 16:36 
GeneralRe: Hooks and Message Blocking Pin
Blake Miller26-May-04 7:09
Blake Miller26-May-04 7:09 
GeneralRe: Hooks and Message Blocking Pin
User 1278226-May-04 10:30
User 1278226-May-04 10:30 
GeneralRe: Hooks and Message Blocking Pin
Blake Miller26-May-04 10:37
Blake Miller26-May-04 10:37 
GeneralRe: Hooks and Message Blocking Pin
User 1278226-May-04 10:40
User 1278226-May-04 10:40 
GeneralRe: Hooks and Message Blocking Pin
Anonymous14-Jul-04 10:03
Anonymous14-Jul-04 10:03 
GeneralRe: Hooks and Message Blocking Pin
Blake Miller14-Jul-04 10:41
Blake Miller14-Jul-04 10:41 
GeneralRe: Hooks and Message Blocking Pin
Blake Miller14-Jul-04 10:25
Blake Miller14-Jul-04 10:25 
GeneralMFC IO Pin
ANDYFA24-May-04 14:30
ANDYFA24-May-04 14:30 
GeneralRe: MFC IO Pin
valikac24-May-04 14:38
valikac24-May-04 14:38 
GeneralRe: MFC IO Pin
Antony M Kancidrowski25-May-04 1:18
Antony M Kancidrowski25-May-04 1:18 
GeneralImage scaling Pin
RalfPeter24-May-04 12:58
RalfPeter24-May-04 12:58 
GeneralRe: Image scaling Pin
Member 42102524-May-04 13:13
Member 42102524-May-04 13:13 
GeneralRe: Image scaling Pin
Christian Graus24-May-04 13:19
protectorChristian Graus24-May-04 13:19 
GeneralRe: Image scaling Pin
Johann Gerell24-May-04 23:49
Johann Gerell24-May-04 23:49 
GeneralRe: Image scaling Pin
Christian Graus25-May-04 11:53
protectorChristian Graus25-May-04 11:53 
GeneralRe: Image scaling Pin
Johann Gerell25-May-04 12:10
Johann Gerell25-May-04 12:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.