Solved

SetWindowsHookEx - focus on a particular application

Posted on 1998-10-24
3
475 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
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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. …
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now