Thread: Application Focus

  1. #1
    Registered User
    Join Date
    Dec 2006

    Application Focus

    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?
    Last edited by tezcatlipooca; 07-16-2007 at 05:37 AM.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    I think you want to check the foreground window rather than the focus, something like the following:
    HWND  hForegnd;
    DWORD pidWindow;
    hForegnd = GetForegroundWindow();
    GetWindowThreadProcessId(hForegnd, &pidWindow);
    if ( pidWindow != GetCurrentProcessId() )
        /* Play sound. */

  3. #3
    Registered User
    Join Date
    Dec 2006
    That worked!
    Thanks a lot..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Direct Show keep playing even when window lose focus
    By mataharistudios in forum Windows Programming
    Replies: 0
    Last Post: 06-10-2008, 09:24 PM
  2. Problem with com application
    By amardon in forum C++ Programming
    Replies: 3
    Last Post: 10-06-2005, 05:50 AM
  3. Changing focus in an MFC Application
    By rangalo in forum Windows Programming
    Replies: 2
    Last Post: 06-20-2005, 06:21 AM
  4. Focus & Always-On-Top :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 06-13-2002, 05:44 PM