473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 2594
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JohnK | last post by:
I have an event raiser, I have instantiated 20,000 objects, each which "listen" for the event (call it event 1)... each of those 20K objects also raise another event (event 2).... and for each of...
5
by: Adam | last post by:
Hi, How do i listen for windows messages in c# on compact.net? I have a window containing an instantiation of the HTML viewer control, which is a child of the main form. As the compact...
2
by: Brian | last post by:
Dear my friends, I have been helped by many C# gurus here, thank you very much. My small application can help you fetch some good pictures from Internet. You can get it from...
3
by: bb | last post by:
I have a windows network device driver written in c++ and a user interface im porting to c#, my problem is i dont seem to be getting notified of the event calls from the driver to the c# app im...
2
by: vooose | last post by:
Does anyone know how to put a textbox in the windows tray or taskbar (a la google desktop search) There is plenty of info on how to make your app. appear as an icon in there but not adding...
1
by: Marek Murin | last post by:
Hi all, I have created vb.net user control that has to be used by vb6 form. Everything goes well with putting the vb.net user control on the VB6 form until I want to receive any event from my...
2
by: jay.maiurano | last post by:
I'd like to get the handle of any application that is clicked in the taskbar. Any thoughts? Thanks!
3
by: Jimmy | last post by:
I'm kinda newbie to python and wxPython. Now I'm confronting a thorny problem: how can I make my program minimize to the taskbar represented as an ico, and when there is some message from network...
10
by: Mark Rae [MVP] | last post by:
Hi, This is really just a theoretical question for my own interest, and not for any nefarious purpose... :-) Say we have three applications running - Notepad, Wordpad and Excel - and each...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.