共用方式為


The OnPaint Method

[The feature associated with this page, Windows Media Player SDK, is a legacy feature. It has been superseded by MediaPlayer. MediaPlayer has been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer instead of Windows Media Player SDK, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

The OnPaint method is called whenever the plug-in window should paint itself. This occurs when the plug-in window receives a WM_PAINT message, which is mapped to the OnPaint method in the message map described earlier. The wizard provides an implementation of this method that paints the background black and places the name of the plug-in in the plug-in window. The only modification that is necessary for the Search UI plug-in is the removal of the code that displays the text.

The following code is used to implement this method:

LRESULT OnPaint(UINT nMsg, WPARAM wParam, 
                         LPARAM lParam, BOOL& bHandled)
{
    PAINTSTRUCT ps;

    HDC hDC = BeginPaint(&ps);

    RECT rc;
    GetClientRect(&rc);

    HBRUSH hNewBrush = ::CreateSolidBrush( RGB(0, 0, 0) );

    if (hNewBrush)
    {
        ::FillRect(hDC, &rc, hNewBrush );
        ::DeleteObject( hNewBrush );
    }

    EndPaint(&ps);
    return 0;
}

Implementing CPluginWindow