balasaravanan_v

Hello all,

I am trying to show use direct show to render video on a custom window. I have created a window and used put_Owner to set the parent child relationship. However, I get 2 windows viz, the window that i created and a active movie window. Can anybody point me right directions on getting this done.

The code is as follows.
#include <dshow.h>

LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
char szWinNamw[] = "MyWin";
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
LPSTR kposzArgs, int nWinMode)
{

MSG msg;
HWND hMainWindow;
WNDCLASSEX wcl;
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hThisInst;
wcl.lpszClassName = "My Window";
wcl.lpfnWndProc = WindowFunc;
wcl.style = 0;
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcl.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
wcl.lpszMenuName = NULL;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH);
if(!RegisterClassEx(&wcl)) return 0;
hMainWindow = CreateWindow(
"My Window",
"Skeleton Window",
WS_OVERLAPPEDWINDOW,
100,
100,
400,
500,
HWND_DESKTOP,
NULL,
hThisInst,
NULL
);
ShowWindow(hMainWindow, nWinMode);
UpdateWindow(hMainWindow);
//////////////////////////////////////////

IGraphBuilder *pGraph = NULL;
IMediaControl *pControl = NULL;
IMediaEvent *pEvent = NULL;

// Initialize the COM library.
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr))
{
printf("ERROR - Could not initialize COM library");
return 0;
}
else
printf("SUCCESS - initialized COM library\n");

// Create the filter graph manager and query for interfaces.
hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void **)&pGraph);
if (FAILED(hr))
{
printf("ERROR - Could not create the Filter Graph Manager.");
return 0;
}
else
printf("SUCCESS - created filter graph manager\n");

hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

IVideoWindow *pVidWin;
hr = pGraph->QueryInterface(IID_IVideoWindow, (void **)&pVidWin);
if(SUCCEEDED(hr))
printf("SUCCESS - Got the video window \n");

RECT rc;
pVidWin->put_Owner((OAHWND) hMainWindow); // We own the window now
pVidWin->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS); // you are now a child

// give the preview window all our space but where the status bar is
GetClientRect(hMainWindow, &rc);
pVidWin->SetWindowPosition(0, 0, rc.right - rc.left, rc.bottom - rc.top); // be this big
pVidWin->SetWindowForeground(OATRUE);
pVidWin->put_Visible(OATRUE);


// Build the graph. IMPORTANT: Change this string to a file on your system.
hr = pGraph->RenderFile(L"D:\\Capture.avi", NULL);
if (SUCCEEDED(hr))
{
// Run the graph.
hr = pControl->Run();
if (SUCCEEDED(hr))
{
// Wait for completion.
long evCode;
pEvent->WaitForCompletion(INFINITE, &evCode);

// Note: Do not use INFINITE in a real application, because it
// can block indefinitely.
}
}
else
printf("FAIL - to render file\n");

pControl->Release();
pEvent->Release();
pGraph->Release();
CoUninitialize();

//////////////////////////
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;

}

LRESULT CALLBACK WindowFunc(HWND hMainWindow, UINT message,
WPARAM wParam, LPARAM lParam)


{


switch(message) {
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hMainWindow, message, wParam, lParam);
}
return 0;
}

Thanks and regards,
Bala



Re: DirectShow Development Problems showing video in a custom window

Bowljoman

Set the style of the Ivideo window.





Re: DirectShow Development Problems showing video in a custom window

balasaravanan_v

Thanks for the reply. I was able to get it work.