🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8011

Re: Help with Message hook

#8011
From: mike
Date: Tue, 07 Dec 2004 00:51
127 lines
5056 bytes
Remy,

Well I said I would be back if I could not get this to work, and guess what,
I'm back. I setup a WH_MSGFILTER hook and I am not receiving any messages at
all through the hook. I have posted the code below, and please bear in mind
it is simply test code at this point so that I can try and understand how it
all works.

This is contained in a DLL and the calls to the DLL are working as I traced
them and saw the address assigned to the message hook handle.

Here is the calling procedure:

             hMsgFilterHook =   SetWindowsHookEx( WH_MSGFILTER ,

(HOOKPROC)MessageProc,

hInst,

0) ;


Here is the hook procedure:

LRESULT CALLBACK MessageProc(int nCode, WPARAM wParam, LPARAM lParam)
{
AnsiString DataVal
;


                   if ( nCode < 0 )
                   {
                         return CallNextHookEx (hMsgFilterHook, nCode,
wParam, lParam);
                    }

// this is only here to see if any messages are being seen inside the hook
                      DataVal               = "Filter Hook "
;
                      COPYDATASTRUCT cds     = {0}
;
                      cds.dwData             = 0x4D696B65;
                      cds.cbData             = DataVal.Length()
;
                      cds.lpData             = DataVal.c_str()
;

                      ::SendMessage( hWindowForMessages , WM_COPYDATA, 0,
reinterpret_cast<LPARAM>( &cds ) ) ;


                      if ( nCode == MSGF_MENU)
                     {
                           DataVal               = "Filter Hook -- Menu
Message"                                    ;

                           COPYDATASTRUCT cds     = {0}
;
                           cds.dwData             =  0x4D696B65;
                           cds.cbData              = DataVal.Length()
;
                           cds.lpData               = DataVal.c_str()
;

                           ::SendMessage( hWindowForMessages , WM_COPYDATA,
0, reinterpret_cast<LPARAM>( &cds ) ) ;

                          CWPSTRUCT *cwpsParam = (CWPSTRUCT *) lParam;

                          if( cwpsParam->message == WM_MENUSELECT )
                         {
                              DataVal               = "Filter Hook -- Menu
Select Message"    ;

                             COPYDATASTRUCT cds     = {0}
;
                             cds.dwData             = 0x4D696B65;
                            cds.cbData             = DataVal.Length()
;
                            cds.lpData             = DataVal.c_str()
;

                            ::SendMessage( hWindowForMessages , WM_COPYDATA,
0, reinterpret_cast<LPARAM>( &cds ) ) ;
                          }
                      }
                     return CallNextHookEx (hMsgFilterHook, nCode, wParam,
lParam);
}

So as I said I am not receiving any messages pumped through this hook. What
I am trying to accomplish is to find out what menu was opened in any
application running in the system.I am actually surprised I am not getting
anything through the hook.

So if you can point me in the right direction I would be most appreciated.

Thanks Mike




"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:41b412e1$1@newsgroups.borland.com...
>
> "mike" <mfbrowne@earthlink.net> wrote in message
> news:41b2766c$1@newsgroups.borland.com...
>
> > I have created a system wide windows message hook and I am trying
> > to figure out how to detect when a menu is selected. Here is the code
> > I am using right.
>
> You are using a WH_CALLWNDPROC hook, which is only invoked when
> SendMessage() is used to deliver a message to a window.  Try using a
> WH_GETMESSAGE hook as well so that you can intercept GetMessage() in
> addition to SendMessage().  Also, have a look at using a WH_MSGFILTER or
> WH_SYSMSGFILTER hook instead.  They can return menu-specific
notifications.
>
> > I never see a hit.
>
> How exactly did you install the hook?  You did not show that code.
>
>
> Gambit
>
>
Technical Details
Message-ID: <41b4fee6@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <41b2766c$1@newsgroups.borland.com> <41b412e1$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,21323583e8de481a
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "mike" <mfbrowne@earthlink.net>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <41b2766c$1@newsgroups.borland.com> <41b412e1$1@newsgroups.borland.com>
Subject: Re: Help with Message hook
Date: Mon, 6 Dec 2004 19:51:41 -0500
Lines: 129
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 68.204.189.169
Message-ID: <41b4fee6@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1102380774 68.204.189.169 (6 Dec 2004 16:52:54 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail