简体   繁体   English

向Media Foundation Interfaces视频屏幕添加按钮的正确方法是什么

[英]What is the right way to add buttons to the Media Foundation Interfaces video screen

I'm currently trying to build a player literally from scratch using Media Foundation Interfaces. 我目前正在尝试使用Media Foundation Interface从头开始构建一个播放器。

I use the example taken from here: https://msdn.microsoft.com/en-us/library/windows/desktop/dd979592(v=vs.85).aspx 我使用从这里获取的示例: https : //msdn.microsoft.com/zh-cn/library/windows/desktop/dd979592(v=vs.85).aspx

As the basis for the player. 作为玩家的基础。

I want to add buttons (back/forward button , progress bar etc.) to the video screen window, but it isn't so clear to me how. 我想在视频屏幕窗口中添加按钮(后退/前进按钮,进度条等),但我不清楚如何操作。

I can not simply add a button as a child of the main window because it is hidden by the player, I tried to add the buttons as children of Video window but it did not work ... 我不能简单地将按钮添加为主窗口的子级,因为它已被播放器隐藏,因此我尝试将按钮添加为“视频”窗口的子级,但是它无法正常工作...

What is the right way to add buttons to a video window? 向视频窗口添加按钮的正确方法是什么?

This is part of the code where you register to the player window (to the full code please enter the link I have attached). 这是您在播放器窗口中注册的代码的一部分(有关完整代码,请输入我随附的链接)。

// create the instance of the player hwnd = handle of main window
HRESULT hr = CPlayer::CreateInstance(hwnd, hwnd, &g_pPlayer);

// inner call to cplayer
CPlayer *pPlayer = new (std::nothrow) CPlayer(hVideo, hEvent);

// Create a partial topology. (m_hwndVideo == hVideo == hwnd)
hr = CreatePlaybackTopology(m_pSource, pSourcePD, m_hwndVideo, &pTopology);

i try to use this function in order to change video paint so i will have some place left at the bottom to put there my buttons, here is my function: 我尝试使用此功能来更改视频绘画,因此我将在底部留一些地方以放置我的按钮,这是我的功能:

VOID update_lower_window(HWND hwnd)
{
    PAINTSTRUCT ps;
    HDC hdc = BeginPaint(hwnd, &ps);

    RECT rc;
    GetClientRect(hwnd, &rc);

    //rc = father size
    RECT repaint;
    memcpy(&repaint, &rc, sizeof(RECT));
    repaint.top = repaint.bottom - DOWN_SPACE; // DOWN_SPACE == 50

    // paint back bottom to white
    FillRect(hdc, &repaint, (HBRUSH)COLOR_WINDOW);

    EndPaint(hwnd, &ps);
}

i call this function when: 我在以下情况下调用此函数:

  1. WM_PAINT happend WM_PAINT发生了
  2. WM_SIZE happend WM_SIZE发生
  3. WM_CREATE happend WM_CREATE发生了

With this said I still could not achieve my goals: 如此说,我仍然无法实现我的目标:

  1. When the movie starts playing it starts full screen and does not leave the space I wanted down (I can not seem to find the message sent when the movie is played or in other words when the movie paint on the screen it's not sent one of the messages on which I inserted my function) 当电影开始播放时,它将开始全屏播放,并且不会离开我想要的空间(我似乎无法找到播放电影时发送的消息,或者换句话说,当屏幕上的电影绘画时,未发送以下消息之一)我插入功能的消息)
  2. When I reduce the screen, the remnants of the previous screen still remain down and I can't see the background. 当我缩小屏幕时,前一个屏幕的残留物仍然保持向下状态,而我看不到背景。
  3. When using the Minimize button it get the same phenomenon as in 2. 使用“最小化”按钮时,会出现与2中相同的现象。

Another interesting detail The phenomenon I mentioned in 2 occurs only when I change window size by drag from the bottom up, if I change window size by drag from one corner (enlarges or decreases height and width simultaneously) then the window corrects itself and I see in the bottom white part (the background) all the time. 另一个有趣的细节我在第2节中提到的现象仅在我通过从下至上拖动来更改窗口大小时发生,如果我通过从一个角拖动来更改窗口大小(同时放大或减小高度和宽度),则窗口会自行校正,并且我看到始终位于底部白色部分(背景)。

You can reposition video area so your win32 GUI (buttons and progress) is below. 您可以重新放置视频区域,以便您的win32 GUI(按钮和进度)位于下面。 See WM_SIZE handler in that sample for how to do it, they calculate rectangle to occupy the window, you can adjust to accommodate your controls. 请参阅该示例中的WM_SIZE处理程序,了解如何执行操作,它们计算占用窗口的矩形,您可以进行调整以适应您的控件。

If you want translucent overlaid controls you can write a EVR Presenter. 如果您想要半透明的重叠控件,则可以编写一个EVR Presenter。 https://msdn.microsoft.com/en-us/library/windows/desktop/bb530107(v=vs.85).aspx https://github.com/Microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/multimedia/mediafoundation/evrpresenter https://msdn.microsoft.com/zh-cn/library/windows/desktop/bb530107(v=vs.85).aspx https://github.com/Microsoft/Windows-classic-samples/tree/master/样本/ Win7Samples /多媒体/ mediafoundation / evrpresenter

But that's relatively hard. 但这比较困难。

PS If you just want a simple solution, use something higher-level. PS:如果您只需要一个简单的解决方案,请使用更高级别的工具。 Like Windows Media Player control note they have a C++ example, or .NET for GUI and MediaElement in it. Windows Media Player控件注释一样,它们具有一个C ++示例,或用于GUI和MediaElement的.NET。

Update: I think the right place to set initial video position in that sample is likely CPlayer::OnTopologyStatus, after MFGetService(MR_VIDEO_RENDER_SERVICE) line. 更新:我认为在该示例中设置初始视频位置的正确位置可能是MFGetService(MR_VIDEO_RENDER_SERVICE)行之后的CPlayer :: OnTopologyStatus。

Anyway, another approach that might be simpler for your task, create a child window dedicated to the video. 无论如何,对于您的任务而言,另一种可能更简单的方法是创建专用于视频的子窗口。 Position it so it occupies the majority of your app's main window, and only leaves bottom 50px unoccupied. 对其进行定位,使其占据应用程序主窗口的大部分,并且只保留底部50px的空间。 Don't forget to handle at least WM_SIZE to reposition and ideally also WM_DISPLAYCHANGED, WM_ENDSESSION, WM_GETMINMAXINFO. 不要忘记处理至少WM_SIZE来重新定位,并且理想情况下还要处理WM_DISPLAYCHANGED,WM_ENDSESSION,WM_GETMINMAXINFO。 Setup the MF playback so that video occupies the complete child video window. 设置MF播放,以使视频占据整个子视频窗口。 This will ensure the video won't interfere with Win32 stuff you're painting on your bottom 50px panel. 这样可以确保视频不会干扰您在底部50像素面板上绘制的Win32内容。

BTW that's what MPC-HC is doing, see the pic. 顺便说一句,MPC-HC就是这样做的,请参见图片。 在此处输入图片说明 As you see on Spy++ screenshot, they have dedicated video window, and also other child windows for Win32 controls of the player. 正如您在Spy ++屏幕截图上看到的那样,它们具有专用的视频窗口以及用于播放器Win32控件的其他子窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM