Solved

SetWindowsHookEx - focus on a particular application

Posted on 1998-10-24
3
525 Views
Last Modified: 2013-11-20
I'm using the setwindowshookex function with the WH_CBT parameter.  The function calles a DLL that I created to determine several things, including if a window has been created. How would I specify this application to work with only one specific application?  For instance,  how would I make this program work and catch messages from only microsoft word?
0
Comment
Question by:jamoville
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 1323809
That's easy. As your (system-wide) hook resides in a DLL which is mapped into each processes' address space, it is executed in the context of this process. You could e.g. call 'GetCommandLine()' which returns the command line upon which the process was created, including the application's name.
0
 
LVL 5

Author Comment

by:jamoville
ID: 1323810
Were would you use this function.  Would it be in the getwindowshookex function of my application, or in the DLL.  I would think it would be in the hookex function to get the threadid.
0
 
LVL 86

Expert Comment

by:jkr
ID: 1323811
Usually you'd call this from within the hook procedure to filter the messages. Example (though it is an excerpt from an WH_GETMESSAGE hook):
LRESULT CALLBACK HookProc   (   int     nCode,  // hook code
                                WPARAM  wParam, // removal flag
                                LPARAM  lParam  // address of structure with message
                            )
{
    PMSG    pmsg    =   ( PMSG) lParam;

    if  (       0   >   nCode  
            ||  PM_NOREMOVE ==  wParam  
            ||  !strstr (   GetCommandLine  (), "winword.exe") // bail out if not Word...
        )
        {
            return  (   CallNextHookEx  (   g_hhk,
                                            nCode,
                                            wParam,
                                            lParam
                                        )
                    );
        }

    //....
}

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question