Step 4: Draw the Bitmap on the Client Area

[The feature associated with this page, DirectShow, is a legacy feature. It has been superseded by MediaPlayer, IMFMediaEngine, and Audio/Video Capture in Media Foundation. Those features have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer, IMFMediaEngine and Audio/Video Capture in Media Foundation instead of DirectShow, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

[This API is not supported and may be altered or unavailable in the future.]

This topic is Step 4 of Grabbing a Poster Frame.

The final step is to draw the bitmap onto the client area of the application window, using the SetDIBitsToDevice function. This example simply paints the bitmap in the upper-left corner of the client area, without regard to the window size:

case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hwnd, &ps);
        if (pbmi)
        {
            int result = SetDIBitsToDevice(hdc, 0, 0, 
                pbmi->biWidth,
                pbmi->biHeight,
                0, 0, 0,
                pbmi->biHeight,
                pBuffer,
                reinterpret_cast<BITMAPINFO*>(pbmi),
                DIB_RGB_COLORS);
        }
        EndPaint(hwnd, &ps);
    }
    break;

The pBuffer and pbmi variables are declared in Step 1: Create the Windows Framework, and their values are obtained in Step 3: Implement the Frame-Grabbing Function.

Grabbing a Poster Frame