Microsoft DirectX 9.0

Using ATL 3.0 to Host the Video Control

This topic applies to Windows XP only.

This article shows how to host the Video Control using ATL 3.0. The application hosts the Video Control inside a composite control. (A composite control is a type of ActiveX object that contains other controls.) To create the application, you must perform the following steps:

The remainder of this article describes these steps in more detail.

Create the Framework

Create a new project using the ATL COM AppWizard. Select Executable (EXE) for the server type. Include the header file Msvidctl.h, and link to the Strmiids.lib library.

Add the Composite Control

Use the ATL Object Wizard to create a composite control. For this example, the default attributes are fine. Give the control a name; for example, MyComposite.

Add the Video Control

Use the Dialog Editor to add the Video Control to the composite control, by doing the following:

  1. Right click the dialog box.
  2. Choose Insert ActiveX Control.
  3. Select MS TV Video Control. It should appear in the list if Msvidctl.dll is registered on your system.

Also, check Visible in the dialog properties. Otherwise, the control will not be visible.

Show the Composite Control

The ATL Object Wizard creates a generic WinMain function. Inside this function, add code before the message loop that creates and displays the composite control. The following code snippet shows the code that you need to add, in bold:

extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, 
    HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/)
{
    /* ... */

    //Create the window and show the composite control.
    AtlAxWinInit();
    HWND hWnd = ::CreateWindow(TEXT("AtlAxWin"), 
        Text("Your Control's ProgID Here"), 
        // Example: TEXT("MyTVApp.MyComposite")
        NULL,
        CW_USEDEFAULT, CW_USEDEFAULT,
        CW_USEDEFAULT, CW_USEDEFAULT,
        NULL, NULL,
        ::GetModuleHandle(NULL), NULL);

    MSG msg;
    while (GetMessage(&msg, 0, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    /* ... */
}

Also, add a message handler for the WM_CLOSE message. In it, destroy the window and post a quit message:

LRESULT MyComposite::OnClose(
    UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    DestroyWindow();
    PostQuitMessage(0);
    return 0;
}

Now you can get a pointer to the Video Control from within the control class as follows:

CComPtr<IMSVidCtl> pVidControl;
hr = GetDlgControl(IDC_MSVIDCTL1, __uuidof(IMSVidCtl), 
        reinterpret_cast<void **>(&pVidControl));