Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SetWindowsHookEx - focus on a particular application

Posted on 1998-10-24
3
Medium Priority
?
540 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 300 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

Industry Leaders: 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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

688 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