Taskbar event listening to OS messages via Win32 API?

  • Thread starter Thread starter JDeats
  • Start date Start date
J

JDeats

I have a Windows Forms application in which I need to be able to trap
on an event when the application itself has lost focus (e.g. if the
user clicks on another application they have opened on the task bar and
that application comes into focus -or- if the go to the Start menu and
launch another application, any scenaio that would lead to a
application being launched or one that's already running taking primary
focus away from my app, I need to trap on)

So, from what I can tell there is no event off of
System.Windows.Forms.Form to handle this, so I'm looking to the Win32
API and wondering if there is an OS message I can listen for in my C#
application (you'll have to excuse my ignorance of the Win32 API
process model, it's been a while) to tell me when the user has decided
to switch to another application... and when they decide to switch back
to mine.

Thanks
Jeremy
 
Jeremy,
wondering if there is an OS message I can listen for in my C#
application (you'll have to excuse my ignorance of the Win32 API
process model, it's been a while) to tell me when the user has decided
to switch to another application... and when they decide to switch back
to mine.

Yes, check out the WM_ACTIVATEAPP message.


Mattias
 
Jeremy,

I would have thought that the Form would expose this as an event, but I
can't find it.

Anyways, what you want to do is override the WndProc method on your
form, and then catch the WM_ACTIVATEAPP message (the value of the message is
0x001C). It will be sent to you with a value of false in the wParam
parameter if the window is being deactivated (false as in 0, not false in
..NET).

Hope this helps.
 
Just wanted to say thanks... That did the trick.

Regards,
Jeremy
Jeremy,

I would have thought that the Form would expose this as an event, but I
can't find it.

Anyways, what you want to do is override the WndProc method on your
form, and then catch the WM_ACTIVATEAPP message (the value of the message is
0x001C). It will be sent to you with a value of false in the wParam
parameter if the window is being deactivated (false as in 0, not false in
.NET).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

JDeats said:
I have a Windows Forms application in which I need to be able to trap
on an event when the application itself has lost focus (e.g. if the
user clicks on another application they have opened on the task bar and
that application comes into focus -or- if the go to the Start menu and
launch another application, any scenaio that would lead to a
application being launched or one that's already running taking primary
focus away from my app, I need to trap on)

So, from what I can tell there is no event off of
System.Windows.Forms.Form to handle this, so I'm looking to the Win32
API and wondering if there is an OS message I can listen for in my C#
application (you'll have to excuse my ignorance of the Win32 API
process model, it's been a while) to tell me when the user has decided
to switch to another application... and when they decide to switch back
to mine.

Thanks
Jeremy
 

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

Back
Top