Solved

SetWindowsHookEx - focus on a particular application

Posted on 1998-10-24
3
509 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to retreive data from .TFS file exported by DVR 8 244
Expand LInux Boot partition remotly 3 102
Macro to save highlighted rows as a separate file 5 46
tripleUp challenge 7 92
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.

735 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