Search code examples
windowswinapims-media-foundation

Prevent video from overdrawing window background


I have a 640x480 sized window. I want to put a 100x100 sized video in the top-left corner of that window. So I do:

RECT r;

r.left = 0;
r.top = 0;
r.right = 100;
r.bottom = 100;

m_pVideoDisplay->SetVideoPosition(NULL, &r);

This correctly puts the video in the top-left corner and scales it to 100x100 pixels but for some reason the Media Foundation video renderer will also fill all space in my window that is not occupied by the video with black now. How can I stop it from doing so? I've explicitly told the IMFVideoDisplayControl to only draw to the top-left 100x100 pixels of my window. But still it fills the remaining space of my window with black! What can I do to make Media Foundation not touch the rest of my window?

My WM_PAINT looks like this:

GetClientRect(hwnd, &rc);
BeginPaint(hwnd, &ps);      
FillRect(ps.hdc, &rc, GetStockObject(WHITE_BRUSH));         
m_pVideoDisplay->RepaintVideo();
EndPaint(hwnd, &ps); 

I'd expect all window space that is not occupied by the video to be white but it is black instead.

I've also tried to do this but it didn't help either:

m_pVideoDisplay->SetRenderingPrefs(MFVideoRenderPrefs_DoNotRenderBorder);

Any ideas? Thanks!


Solution

  • To answer my own question, the trick here is to simply add a child window to my parent window using CreateWindowEx() and have Media Foundation render to the child window instead of the parent by calling SetVideoWindow() of IMFVideoDisplayControl. Then there will be no more overdrawing and everything is fine. I don't even have to use SetVideoPosition() any longer because I can simply move the video around (or apply scaling) by calling the normal MoveWindow() Win32 API on the child window. This really works very smoothly.