اقرأ باللغة الإنجليزية

مشاركة عبر


When to Render (deprecated)

This page documents a feature that may be unavailable in future versions of Windows Media Player and the Windows Media Player SDK.

Windows Media Player rendering plug-ins that render data visually must be created to handle rendering in both windowed and windowless modes. Windowless mode is a rendering mode supported by the Windows Media Player ActiveX control where rendering occurs without a child window. This permits enhanced effects like layering or alpha-blending. When a rendering plug-in renders in windowless mode, it calls IWMPNodeWindowlessHost::InvalidateRect to direct the Player to invalidate the rendering region. Eventually, this results in a call to the plug-in implementation of IWMPNodeWindowless::OnDraw. This method receives a handle to a device context for drawing and a pointer to a RECT structure that represents the drawing region. OnDraw is the method where you implement your own code for drawing in windowless mode. The following code is an excerpt from the sample rendering plug-in implementation of OnDraw:

c++

if ( prcDraw )
{
    HDC hDC = ( HDC )hdc;

    // Set the text color.
    COLORREF oldTextColor = ::SetTextColor( hDC, m_TextColor );
    // Set the text background color.
    COLORREF oldBkColor = ::SetBkColor( hDC, rgbWhite );

    hr = DoRendering( hDC, prcDraw );

    // Restore the original colors.
    ::SetBkColor( hDC, oldBkColor );
    ::SetTextColor( hDC, oldTextColor );
}

Notice that the code casts the device context handle from type OLE_HDC to type HDC. The remaining code uses standard Windows drawing functions to prepare to draw the text data from the buffer. The text color is set based on the user selection in the plug-in property page. The code then calls the custom function named DoRendering to perform the actual drawing work. This is convenient because it centralizes most of the drawing and painting code in a single function regardless of drawing mode. Finally, the code cleans-up the changes it made earlier to the supplied device context.

When a rendering plug-in renders in windowed mode, it must invalidate the rendering region in its own window and update the window. This results in the operating system posting a WM_PAINT message to the plug-in window message queue. Upon receiving this message, the plug-in can paint in its own window. Because the sample code generated by the plug-in wizard uses ATL COM, the plug-in maps the WM_PAINT message to a function named OnPaint. This function acts as the windowed mode counterpart to IWMPNodeWindowlessHost::OnDraw. The following code is an excerpt from the sample plug-in implementation of OnPaint:

c++

PAINTSTRUCT ps;
HDC hDC;

hDC = BeginPaint( &ps );

if( NULL == hDC )
{
    return 1;
}

// Set the text background to white.
COLORREF oldBkColor = ::SetBkColor( hDC, rgbWhite );
// Set the text color to the selection.
COLORREF oldTextColor = ::SetTextColor( hDC, m_TextColor );

hr = DoRendering(hDC, &m_rctDisplay);

// Restore the colors.
::SetBkColor( hDC, oldBkColor );
::SetTextColor( hDC, oldTextColor );

EndPaint( &ps );

The preceding code looks remarkably similar to the code from OnDraw. The main differences are:

  • The plug-in must create its own device context using BeginPaint. This is because the plug-in is painting in its window instead of a windowless region supplied by the Player.
  • The RECT pointer (&m_rctDisplay) the function passes to DoRendering is from a member variable instead of directly supplied by the Player. This RECT is calculated in IWMPNodeRealEstate::SetRects, which is the method that the Player calls to supply the plug-in with information about the rendering region when rendering in windowed mode. See the section titled About SetRects (deprecated).

Implementing Your Rendering Code (deprecated)