[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Windows Hooks: Hooking a closing app

Posted on 2004-04-19
5
Medium Priority
?
1,107 Views
Last Modified: 2008-02-26
Hi all,
I've been working on this solution for quite some time. Im trying to display a message everytime an app closes. So far i have been able to code a program that displays a message every time an app closes using Win32 API's CBTProc Callback function

LRESULT CALLBACK CBTProc(int code, WPARAM wParam, LPARAM lParam)
{

      if(code == HCBT_DESTROYWND){
            ...            
      }
      
      return CallNextHookEx(... , .., .. , ..);
}

a was able to display a message "Closed!!" every time media player closed but it's a problem for winword.exe .. iexplore.exe and some of the program files items on the desktop.. when i execute these "Closed!!" appears before the window is exited by the user. Would anyone know how to properly hook applications using SetWindowsHookEx() API ?
0
Comment
Question by:ogoy
[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
5 Comments
 
LVL 2

Expert Comment

by:anupvijay
ID: 10866863
Do you mean to say that without the user performing any action to close the window the hook gets the close event ?

I don't suppose so.Just checking.
I assume that the event is received just before the window is not visible anymore in case of IE,MS Word etc.....right?

Will WH_GETMESSAGE work for you instead of WH_CBT ? But yes you will get all the windows messages. You have
to apply a filter for WM_CLOSE i think.

Just thinking aloud..........the problem you are facing could be because the event is posted before the windows is actually
made invisible by the applications in question........again.....not sure...

Cheers.
0
 

Author Comment

by:ogoy
ID: 10948870
Thanks for replying. I was hoping email notifications for this forum would alert me for any posts but it didn't.. i tried CallWndProc, GetMsgProc.. and the rest of the win32 api for SetWindowsHookEx(..) but the "Closed!" message still appeared even when im not closing it..

Anyway i found a solution that required me to do a SetWindowLong(..) that opens a window handle to the activated window.. this allowed me to trap closing windows events properly.. the site i got the idea from was

www.venkydude.com/article.htm
0
 
LVL 2

Expert Comment

by:anupvijay
ID: 10948973
Good for you.
Yeah I have also experience a long delay in the mail notification.But I generally get it some day :-)

All the best for your project
Cheers.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 11728407
PAQed, with points refunded (250)

modulo
Community Support Moderator
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

650 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