471,627 Members | 1,508 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

Taskbar event listening to OS messages via Win32 API?

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

Jan 24 '06 #1
3 2536
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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jan 24 '06 #2
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]
- mv*@spam.guard.caspershouse.com

"JDeats" <Je**********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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

Jan 24 '06 #3
Just wanted to say thanks... That did the trick.

Regards,
Jeremy

Nicholas Paldino [.NET/C# MVP] wrote:
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]
- mv*@spam.guard.caspershouse.com

"JDeats" <Je**********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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


Jan 26 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by JohnK | last post: by
5 posts views Thread by Adam | last post: by
2 posts views Thread by Brian | last post: by
2 posts views Thread by vooose | last post: by
1 post views Thread by Marek Murin | last post: by
2 posts views Thread by jay.maiurano | last post: by
3 posts views Thread by Jimmy | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.