User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 426,815 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,924 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 314 | Replies: 8
Reply
Join Date: Jul 2008
Posts: 5
Reputation: sickle is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sickle sickle is offline Offline
Newbie Poster

How to know when a window of another process is activated

  #1  
Jul 24th, 2008
Hi,

This concerns Microsoft Windows. I want to know when a window from other processes is made visible. Also, I want the handle of the window. I've tried to catch the message WM_SHOWWINDOW with SetWindowsHookEx(WH_GETMESSAGE, &MessageProc, g_hInstance, 0) but I receive no events ! The only events I receive is when I do a call to MessageBox after the call to SetWindowsHookEx. But the events only come from user32.dll. I call MessageBox to tell me that the call to SetWindowsHookEx is successful. Please, I need your help. Thank you.
Attached Files
File Type: cpp HideMeHook.cpp (2.8 KB, 6 views)
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to know when a window of another process is activated

  #2  
Jul 24th, 2008
You have to hook external objects using global hooks (those residing in a DLL). Process hooks can only be used with your own application's processes.
Reply With Quote  
Join Date: Jul 2008
Posts: 5
Reputation: sickle is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sickle sickle is offline Offline
Newbie Poster

Re: How to know when a window of another process is activated

  #3  
Jul 24th, 2008
Originally Posted by Duoas View Post
You have to hook external objects using global hooks (those residing in a DLL). Process hooks can only be used with your own application's processes.


Sorry, but I don't understand. My hook is already in a DLL, or do you mean that exists other hook functions that are more global to the system ? What I don't understand, is this is supposed to work according to Microsoft documentation :

Originally Posted by Platform SDK: Windows User Interface
SetWindowsHookEx
...
These events are associated either with a specific thread or with all threads in the same desktop as the calling thread.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to know when a window of another process is activated

  #4  
Jul 24th, 2008
I'm sorry, I mixed-up that last two arguments to SetWindowsHookEx() and thought you were installing a process hook.

The WM_SHOWWINDOW message is not a queued message --it is sent directly to the target window procedure. Hence, the WH_GETMESSAGE hook will never see it. You'll need to install a WH_CALLWNDPROC hook to catch it.

Annoying, isn't it?

(Sorry it took me this long to pay enough attention to answer your question...)
Reply With Quote  
Join Date: Jul 2008
Posts: 5
Reputation: sickle is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sickle sickle is offline Offline
Newbie Poster

Re: How to know when a window of another process is activated

  #5  
Jul 24th, 2008
Thanks for your answer. Yes, I already tried WH_CALLWNDPROC with no luck. Please, see the file attachment to my first message.
Reply With Quote  
Join Date: Apr 2008
Posts: 27
Reputation: marco93 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 4
marco93 marco93 is offline Offline
Light Poster

Re: How to know when a window of another process is activated

  #6  
Jul 25th, 2008
see news://194.177.96.26/comp.os.ms-wind...ogrammer.win32
where it has been explained hundreds of times...
Reply With Quote  
Join Date: Jul 2008
Posts: 5
Reputation: sickle is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sickle sickle is offline Offline
Newbie Poster

Re: How to know when a window of another process is activated

  #7  
Jul 26th, 2008
Originally Posted by marco93 View Post
see news://194.177.96.26/comp.os.ms-wind...ogrammer.win32
where it has been explained hundreds of times...


If you know how, it will be great that you explain it here. Newsgroups have no archives as I know. If I ask it here, it's because I found nothing. This will take you 5 minutes or less.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to know when a window of another process is activated

  #8  
Jul 26th, 2008
Newsgroups are archived. For ever and ever. (But they are annoying to search.)

Yes, I already tried WH_CALLWNDPROC with no luck. Please, see the file attachment to my first message.
No, you tried WH_CALLWNDPROCRET, which is entirely different.

If you are still having problems I'll see if I can't compile your code myself and figure out what's wrong.
Reply With Quote  
Join Date: Jul 2008
Posts: 5
Reputation: sickle is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sickle sickle is offline Offline
Newbie Poster

Re: How to know when a window of another process is activated

  #9  
Jul 26th, 2008
I also tried with WH_CALLWNDPROC and it doesn't work. Ok, I have no choice to send you the complete code, make what you want with it It was supposed to be a simple program to practice and learn C/C++. It's developped under Visual Studio .NET 2002. I'll do cleanup when the hook will work.
Attached Files
File Type: zip HideMe.zip (76.3 KB, 0 views)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 8:12 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC