How to know if the "Active" application changes?

F

Flyte

Hi All.

Is there any way to be notified when the "Active" application
changes? By active I mean which application currently has
mouse and keyboard focus.

I need to be able to know when my application becomes active
and when it becomes non-active. (i.e.: via minimization, or
alt-tab, etc)

Any ideas?
 
F

Flyte

I tried this approach by handling these events (and even
tried the Deactivate event) on my main form, but this didn't
solve my problem because I have a number of top level
windows, and when anyone of those gets focus, the
event handlers fire on the main form.

What I really need to determine is if the application is in focus
or not - regardless of what form of the application looses/gains
focus.
 
F

Flyte

This is the answer:

protected override void WndProc(ref Message m) {
if (m.Msg == 0x1c) { // WM_ACTIVATEAPP
if (m.WParam == IntPtr.Zero) label1.Text = "Not active";
else label1.Text = "Active";
}
base.WndProc(ref m);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top