I have created a simple console application that acts as a messenger between client and server (in fact there is a clinet.exe and a server.exe)..
Now, I want it to play a sound sample if a message arrives and it does not have the focus
(Something like what the MSN Live Messenger does) so as to get user's attention..
I use the Beep() function to play the sound(ok it's kind of silly but i only do it for fun.. :)) but i don't know how to detect if my application has the focus.
May someone help please?
I think you want to check the foreground window rather than the focus, something like the following:
hForegnd = GetForegroundWindow();
if ( pidWindow != GetCurrentProcessId() )
/* Play sound. */
Thanks a lot.. :)