如何检测窗口媒体播放器是否以全屏模式运行 [英] how to detect if window media player is running in full screen mode

查看:136
本文介绍了如何检测窗口媒体播放器是否以全屏模式运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在处理的应用程序是一个MFC独立应用程序。我需要根据Windows上全屏运行的应用程序采取一些措施。例如,如果全屏打开mspaint或全屏打开任何其他应用程序。下面是代码片段



Hi,

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

TestFullScreenApp()
{
    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.rcClient.top == wi.rcWindow.top && wi.rcWindow.top== deskRect.top) &&
        ((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;
    }
}



此逻辑适用于除Windows媒体播放器之外的所有应用程序。如果桌面上的Windows媒体播放器以全屏模式运行,则只要显示控件(播放,暂停等)处于图片中,此逻辑就会失败,如果不是,则会运行。



请做必要。


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.

推荐答案

我认为你需要使用 GetWindowPlacement [ ^ ] API。



该函数将告诉您窗口的当前状态。在你的情况下,如果窗口刚刚拉伸到桌面的大小,你的功能仍将返回TRUE。



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.

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





在旁注中,代码中有两个可能的错误。首先,在调用此函数(wi.cbSize = sizeof(WINDOWINFO))之前,需要将cbSize成员设置为sizeof(WINDOWINFO)。其次,你需要测试GetWindowInfo的返回代码



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


我确定你的逻辑将对所有媒体播放器都失败,因为正在播放的实际媒体是播放器窗口顶部的叠加层。因此,在全屏幕中,播放器窗口不是全屏,而是覆盖全屏。



对于Windows Media Player,有几个COM接口可用供您使用。

您正在寻找的方法是 IWMPPlayer :: get_fullScreen



调用这个方法可能有点复杂。

你可以从这里开始 - Windows Media Player对象模型参考 [ ^ ]
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[^]


这篇关于如何检测窗口媒体播放器是否以全屏模式运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆