Sign in to follow this  

How to watch for system events in .net?

This topic is 4376 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am trying to recognize when a user makes another program active by clicking it when my program is minimized. Eg, when my .net winform program starts, it is minimized and hidden and has an icon shown in the tray. I want my program to maximize and show itself when the user makes another program active. For example, they start my program and its running in the background, they then click on a notepad window then my program shows itself. Is there a way to do this without hooks because a really dont get how to use them with .net. Thanks :)

Share this post


Link to post
Share on other sites
You could P/Invoke a call to GetForegroundWindow every second or so (in a timer, for example) and if the window you're after becomes the active one then you can do whatever.

Though I would question the value of this. Why do you want your program to pop up when a certain window becomes active? Perhaps there's a better solution, but we can't help you if you don't give us some more background...

Share this post


Link to post
Share on other sites
Thanks Dean,

I am making a program that calculates poker statistics on the fly by watching what cards come out on online poker clients.

The way my program is supposed to work is, the user starts it and it will run in the background with a tray icon. When a user activates a poker table, my program displays and starts doing the stats.

The reason i need to know what window is active is because, some people have 2-4 poker tables open at once but only one can be active at a time. When they click a table, my program will know which cards to read so that way they can use one program for many tables instead of trying to cram in 4 instances of my program with 4 tables.

I'll look into your solution,

Cheers :)

Share this post


Link to post
Share on other sites

This topic is 4376 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this