Application Focus

This is a discussion on Application Focus within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I have created a simple console application that acts as a messenger between client and server (in fact there ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    60

    Application Focus

    Hi,
    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 06:37 AM.

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

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    60
    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, 10:24 PM
  2. Problem with com application
    By amardon in forum C++ Programming
    Replies: 3
    Last Post: 10-06-2005, 06:50 AM
  3. Changing focus in an MFC Application
    By rangalo in forum Windows Programming
    Replies: 2
    Last Post: 06-20-2005, 07:21 AM
  4. Focus & Always-On-Top :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 06-13-2002, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21