tags:

views:

49

answers:

1

Hi,

I need to know when my application is activated explicitly by the user, i.e., my application lets users open office documents, when they do that the office window becomes active and my application's window becomes deactivate. What I need to know is when the user re-activates my application's window either by Alt+Tab or through the taskbar.

I've tried to use WM_NCACTIVATE and WM_ACTIVATEAPP messages but this these messages are thrown in many other situations. Is there a way I can get this information with these or other messages?

thanks, José Pedro Tavares

A: 

Why don't you use the Activated event from the form?

riffnl
Well.. it's complicated :)My code is injected in other WinForm applications so I can record events in the application. The Activated event from the form is also launched when Activate is explicitly called in the code, and I don't want to record in this situation. It isn't also easy to get the handle of the windows that are part of the application. So my solution, for the close, maximize, minimize events was to install a hook for win32 events and process them. And I'm searching for a similar solution for the activate event.
jpsstavares
Which would also be your problem when hooking on the Activate event in the API. I'd concieve a work-around for your problem (like setting a switch "dontrecordnextactivate" or something like that I think), because the basic principle on either the API or the native code remains the same.
riffnl
Sorry for the delay answering. That's right I have the same problem with the API event, but I can't get the handle for every window in the application as they appear, so I thought it would be easier through the API. The reason I can't get the handle is because my code is injected in 3rd party applications, therefore I don't know how many windows there will be and their behaviour.
jpsstavares
Most likely you'll end up with an (even more) unmaintanable mess of API calls ;-)Can't you question the sender object on which object the callee is?
riffnl