Microsoft DirectX 9.0 |
Next, add a command for the user to grab a poster frame from a file. Create a menu item with a resource ID of IDM_BITMAP, and add the following case statement to the window procedure:
case WM_COMMAND:
switch (LOWORD(wparam))
{
case IDM_BITMAP:
{
HRESULT hr = DoShowBitmap(hwnd, &pbmi);
if (SUCCEEDED(hr))
{
pBuffer = reinterpret_cast<BYTE*>(pbmi) +
sizeof(BITMAPINFOHEADER);
InvalidateRect(hwnd, NULL, TRUE);
}
else
{
MessageBox(hwnd, TEXT("Cannot display the image."),
TEXT("Error"), MB_OK | MB_ICONERROR);
}
}
break; // IDM_BITMAP
}
break; // WM_COMMAND
The DoShowBitmap function will return the allocated buffer in pbmi. Assuming the function succeeds, the address of the bitmap (pBuffer) can be calculated as an offset from pbmi. In the DoShowBitmap function, display an Open File dialog box for the user to choose a file, and then call the application-defined GetBitmap function, which will retrieve the bitmap:
HRESULT DoShowBitmap(HWND hwnd, BITMAPINFOHEADER** ppbmih)
{
OPENFILENAME ofn; // common dialog box structure
// Initialize OPENFILENAME (not shown).
// Display the Open File dialog box.
if (GetOpenFileName(&ofn) != TRUE) // failed to open file
{
return E_FAIL;
}
return GetBitmap(ofn.lpstrFile, ppbmih);
}