MouseProc Hook Procedure 
Author Message
 MouseProc Hook Procedure

Hi,

I have the following code.  I would expect the UnSetHook procedure to be
called when the user presses the left mousebutton.  But its not.  Everything
I've seen in MSDN and KnowledgeBase indicates that wParam should be equal to
WM_LBUTTONDOWN when the user press the left mouse button.  But UnSetHook is
not executed.

Any clues?  Here's my code:

LRESULT CALLBACK MouseProc( int nCode,WPARAM wParam,LPARAM lParam)
{
     if(nCode<0 || nCode != HC_ACTION)
     {
      return CallNextHookEx(g_hHookMouse, nCode, wParam, lParam);
     }
     if(nCode == HC_ACTION)
     {
         if (wParam == WM_LBUTTONDOWN)
         {
           UnSetHook();
         }
     }

 return CallNextHookEx(g_hHookMouse, nCode, wParam, lParam);

Quote:
}

Any help is greatly appreciated.

Doug



Tue, 30 Jul 2002 03:00:00 GMT  
 MouseProc Hook Procedure

Quote:

> Hi,

> I have the following code.  I would expect the UnSetHook procedure to be
> called when the user presses the left mousebutton.  But its not.  Everything
> I've seen in MSDN and KnowledgeBase indicates that wParam should be equal to
> WM_LBUTTONDOWN when the user press the left mouse button.  But UnSetHook is
> not executed.

> Any clues?  Here's my code:

Is g_hHookMouse an initialized variable in a shared global section ? Are
you sure that your hook proc is called at all ?
Quote:

> LRESULT CALLBACK MouseProc( int nCode,WPARAM wParam,LPARAM lParam)
> {

*** you could eliminate these four lines and the program would work the
same
Quote:
>      if(nCode<0 || nCode != HC_ACTION)
>      {
>       return CallNextHookEx(g_hHookMouse, nCode, wParam, lParam);
>      }
***
>      if(nCode == HC_ACTION)
>      {
>          if (wParam == WM_LBUTTONDOWN)
>          {
>            UnSetHook();
>          }
>      }

>  return CallNextHookEx(g_hHookMouse, nCode, wParam, lParam);
> }

> Any help is greatly appreciated.

> Doug



Tue, 30 Jul 2002 03:00:00 GMT  
 MouseProc Hook Procedure
The hook works fine.  If I take out the If statement from around UnSetHook,
the DLL works fine.  That is, any mouse event (movement or click) will cause
UnSetHook to be executed.

The DLL has in fact been in production for a while with no problems.  A
company wants a special version of the app that requires the DLL to return
(UnSetHook) only after a left mouse click rather than on any mouse event.
Should be simple, but I can't get the DLL to recognize specifically a left
mouse click.

- Doug

Quote:
> > Hi,

> > I have the following code.  I would expect the UnSetHook procedure to be
> > called when the user presses the left mousebutton.  But its not.
Everything
> > I've seen in MSDN and KnowledgeBase indicates that wParam should be
equal to
> > WM_LBUTTONDOWN when the user press the left mouse button.  But UnSetHook
is
> > not executed.

> > Any clues?  Here's my code:

> Is g_hHookMouse an initialized variable in a shared global section ? Are
> you sure that your hook proc is called at all ?

> > LRESULT CALLBACK MouseProc( int nCode,WPARAM wParam,LPARAM lParam)
> > {
> *** you could eliminate these four lines and the program would work the
> same
> >      if(nCode<0 || nCode != HC_ACTION)
> >      {
> >       return CallNextHookEx(g_hHookMouse, nCode, wParam, lParam);
> >      }
> ***
> >      if(nCode == HC_ACTION)
> >      {
> >          if (wParam == WM_LBUTTONDOWN)
> >          {
> >            UnSetHook();
> >          }
> >      }

> >  return CallNextHookEx(g_hHookMouse, nCode, wParam, lParam);
> > }



Tue, 30 Jul 2002 03:00:00 GMT  
 MouseProc Hook Procedure
Maybe you want the LOWORD and the HIWORD of the wParam?

int wmId    = LOWORD(wParam);
int wmEvent = HIWORD(wParam);

This is just a guess because in winuser.h WM_LBUTTONDOWN is #defined as

#define WM_LBUTTONDOWN                  0x0201

which implies that is it only 16 bits (2 bytes).  WPARAM is defined as a
UINT_PTR which is an unsigned long which is 32 bits (4 bytes).
I looked it up in MSDN and it did say that the wParam is the mouse identifier.

Let us know if what you did if you have figured it out.
-Paul


Quote:
> The hook works fine.  If I take out the If statement from around UnSetHook,
> the DLL works fine.  That is, any mouse event (movement or click) will cause
> UnSetHook to be executed.

> The DLL has in fact been in production for a while with no problems.  A
> company wants a special version of the app that requires the DLL to return
> (UnSetHook) only after a left mouse click rather than on any mouse event.
> Should be simple, but I can't get the DLL to recognize specifically a left
> mouse click.

> - Doug

> > > Hi,

> > > I have the following code.  I would expect the UnSetHook procedure to be
> > > called when the user presses the left mousebutton.  But its not.
> Everything
> > > I've seen in MSDN and KnowledgeBase indicates that wParam should be
> equal to
> > > WM_LBUTTONDOWN when the user press the left mouse button.  But UnSetHook
> is
> > > not executed.

> > > Any clues?  Here's my code:

> > Is g_hHookMouse an initialized variable in a shared global section ? Are
> > you sure that your hook proc is called at all ?

> > > LRESULT CALLBACK MouseProc( int nCode,WPARAM wParam,LPARAM lParam)
> > > {
> > *** you could eliminate these four lines and the program would work the
> > same
> > >      if(nCode<0 || nCode != HC_ACTION)
> > >      {
> > >       return CallNextHookEx(g_hHookMouse, nCode, wParam, lParam);
> > >      }
> > ***
> > >      if(nCode == HC_ACTION)
> > >      {
> > >          if (wParam == WM_LBUTTONDOWN)
> > >          {
> > >            UnSetHook();
> > >          }
> > >      }

> > >  return CallNextHookEx(g_hHookMouse, nCode, wParam, lParam);
> > > }



Tue, 30 Jul 2002 03:00:00 GMT  
 MouseProc Hook Procedure

Heres the code from a Working MouseHook (inhibits all right mouse
button activity). Looks pretty similar to yours -- maybe the problem
is somewhere else???

LRESULT CALLBACK MouseProc(
  int    p_nCode,      // hook code
  WPARAM p_wParam,  // message identifier
  LPARAM p_lParam )  // mouse coordinates
{
   if (!(p_nCode < 0)) {
      if (p_wParam == WM_RBUTTONDOWN || p_wParam == WM_RBUTTONUP ||
         p_wParam == WM_RBUTTONDBLCLK ||
         p_wParam == WM_NCRBUTTONDOWN || p_wParam ==WM_NCRBUTTONUP ||
         p_wParam ==  WM_NCMBUTTONDBLCLK) {
         return 1; // to prevent the message from going to the process
      }
   }
   return CallNextHookEx(g_hMouseHook,p_nCode,p_wParam,p_lParam);

Quote:
}  // MouseProc

On Fri, 11 Feb 2000 09:45:44 -0500, "Doug"
Quote:

>Hi,

>I have the following code.  I would expect the UnSetHook procedure to be
>called when the user presses the left mousebutton.  But its not.  Everything
>I've seen in MSDN and KnowledgeBase indicates that wParam should be equal to
>WM_LBUTTONDOWN when the user press the left mouse button.  But UnSetHook is
>not executed.

>Any clues?  Here's my code:

>LRESULT CALLBACK MouseProc( int nCode,WPARAM wParam,LPARAM lParam)
>{
>     if(nCode<0 || nCode != HC_ACTION)
>     {
>      return CallNextHookEx(g_hHookMouse, nCode, wParam, lParam);
>     }
>     if(nCode == HC_ACTION)
>     {
>         if (wParam == WM_LBUTTONDOWN)
>         {
>           UnSetHook();
>         }
>     }

> return CallNextHookEx(g_hHookMouse, nCode, wParam, lParam);
>}

>Any help is greatly appreciated.

>Doug



Wed, 31 Jul 2002 03:00:00 GMT  
 MouseProc Hook Procedure
Doug,

The reason you are not getting a WM_LBUTTONDOWN is probably that the nCode
is HC_NOREMOVE for the WM_LBUTTONDOWN message.  (This will depend on what
you are hooking into).  Try reworking the logic so that you unhook when
nCode >= 0 and wParam == WM_LBUTTONDOWN.

This works for me. :-)

Neil Groves
Lucid Computing


Quote:
> Hi,

> I have the following code.  I would expect the UnSetHook procedure to be
> called when the user presses the left mousebutton.  But its not.
Everything
> I've seen in MSDN and KnowledgeBase indicates that wParam should be equal
to
> WM_LBUTTONDOWN when the user press the left mouse button.  But UnSetHook
is
> not executed.

> Any clues?  Here's my code:

> LRESULT CALLBACK MouseProc( int nCode,WPARAM wParam,LPARAM lParam)
> {
>      if(nCode<0 || nCode != HC_ACTION)
>      {
>       return CallNextHookEx(g_hHookMouse, nCode, wParam, lParam);
>      }
>      if(nCode == HC_ACTION)
>      {
>          if (wParam == WM_LBUTTONDOWN)
>          {
>            UnSetHook();
>          }
>      }

>  return CallNextHookEx(g_hHookMouse, nCode, wParam, lParam);
> }

> Any help is greatly appreciated.

> Doug



Wed, 31 Jul 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Hook Procedures in WIN95

2. nCode of hooking procedure

3. Keyboard Hook procedure?

4. how to avoid using hook procedures

5. Using Clipboard in CBTProc hook procedure

6. Help needed on HOOK procedure, automatisation tool

7. hook procedures

8. nCode of hooking procedure

9. Hook procedure

10. Window procedure, window class procedure and dialog procedure

11. To hook or not to hook? (...and what to hook?)

12. Testing when an __event has been hooked

 

 
Powered by phpBB® Forum Software