Click here to Skip to main content
15,936,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

The application I am working on is a MFC standalone application. I need to take some action based on the applications running in fullscreen on Windows. For example if mspaint is opened in fullscreen or any other application is opened in fullscreen. Below is the code snippet

    HWND hForeGndWnd = ::GetForegroundWindow();
    if (hForeGndWnd == NULL)
        return FALSE;

    RECT deskRect = {0};
    HWND hDesktopWnd = ::GetDesktopWindow();
    if (hDesktopWnd)
        ::GetClientRect(hDesktopWnd, &deskRect);

    WINDOWINFO wi = {0};
    ::GetWindowInfo(hForeGndWnd, &wi);

    if ((wi.rcClient.left == wi.rcWindow.left && wi.rcWindow.left == deskRect.left) &&
        ( == && &&
        ((wi.rcWindow.right-wi.rcClient.right <= 2) && wi.rcWindow.right == deskRect.right) &&
        ((wi.rcWindow.bottom-wi.rcClient.bottom <= 2) && wi.rcWindow.bottom == deskRect.bottom))

        return TRUE;

This logic works fine for all applications except windows media player. If windows media player on desktop is running in fullscreen then this logic fails whenever there is display controls (play, pause etc) is in picture and works if they are not.

Please do the needful.
Updated 23-Jan-13 19:30pm

I think you need to use GetWindowPlacement[^] API.

The function will tell you the current state of the window. In you case, if the window is just stretched to the size of the desktop, your function will still return TRUE.

wp.length = sizeof(WINDOWPLACEMENT);
if(::GetWindowPlacement(hForeGndWnd, &wp) && wp.showCmd & SW_SHOWMAXIMIZED)
    return TRUE;

On the side note there are two possible bugs in your code. First, you need to set the cbSize member to sizeof(WINDOWINFO) before calling this function (wi.cbSize = sizeof(WINDOWINFO)). Second, you need to test the return code of GetWindowInfo
Share this answer
I'm sure your logic will fail for all media players because the actual media being played is an overlay on top of the player window. So in full screen, the player window is not in full screen, but the overlay is in full screen.

For the Windows Media Player, there are several COM interfaces available for you to use.
The method you're looking for is IWMPPlayer::get_fullScreen.

Calling this method could be a little complicated.
You can start here - Windows Media Player Object Model Reference[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900