Share via


Responding to User Commands (Windows Embedded CE 6.0)

1/6/2010

The following code example shows a simple messaging loop followed by instructions at the end of WinMain() to release the DVD-Video API interfaces.

// Message loop.
while (GetMessage (&msg, NULL, 0, 0)) 
{
    TranslateMessage (&msg);
    DispatchMessage (&msg);
}

// Clean-up DVD-Video API Interfaces
pNavMan->Release();
pAnnexJ->Release();
pVolume->Release();
pDisk->Release();

Within you message processor, you can use the IDVDUserOperation interface methods to map keyboard commands directly to playback commands as shown by the following code example.

In this example, a function named OnKeyDown was created to contain the message handling for navigation commands.

LRESULT CALLBACK MainWindowProc (
    IN  HWND hwnd,
    IN  UINT uMsg,
    IN  WPARAM wParam,
    IN  LPARAM lParam)
{
    switch (uMsg) {

    // Code for processing Windows messages goes here
    // ...

    case WM_KEYDOWN:
        if (OnKeyDown(wParam))
            return 0;

        switch (wParam) {
        case VK_F4:
            if (GetKeyState(VK_MENU) {
                DestroyWindow(hwnd);
            }
            break;
        }

        return 0;
    }   // switch (uMsg)

    // The message is not processed, so pass it along to the default
    // window processing routine.
    return DefWindowProc (hwnd, uMsg, wParam, lParam);
}

The definition of the OnKeyDown function is shown in the following code example. Note how the code for handling a menu request must consider the contextual possibilities allowed by the DVD-Video standard before it executes any operations.

BOOL OnKeyDown(WPARAM wParam)
{
    HRESULT hr;

    if (wParam >= '1' &&  wParam <= '9')
    {
        pAnnexJ->ChangeAngle((BYTE) wParam-'0');
        return TRUE;
    }

    switch (wParam) 
    {
        // Menu call
        case VK_HOME: 
        {
            //try to resume first
            hr = pAnnexJ->Resume();
            if (FAILED(hr) && hr == E_UNEXPECTED)
            {
                //no resume record so probably you want to call menu?
                if (FAILED(pAnnexJ->MenuCall(DVD_MENU_TITLE)) && 
                    FAILED(pAnnexJ->MenuCall(DVD_MENU_ROOT)))
                {
                    //start playback
                    pAnnexJ->TitlePlay(0);
                }
            }
        }
        break;

        case VK_UP:
            pAnnexJ->ButtonSelect(DVD_SELECT_UPPER);
        break;

        case VK_RIGHT:
            pAnnexJ->ButtonSelect(DVD_SELECT_RIGHT);
        break;

        case VK_DOWN:
            pAnnexJ->ButtonSelect(DVD_SELECT_LOWER);
        break;

        case VK_LEFT:
            pAnnexJ->ButtonSelect(DVD_SELECT_LEFT);
        break;

        case VK_RETURN:
            pAnnexJ->ButtonActivate();
        break;

        case 'O':
            pAnnexJ->StillOff();
        break;

        case VK_ESCAPE:
            pAnnexJ->Pause(!!((g_Paused++) & 1));
        break;

        case VK_F1:
            if (FAILED(pAnnexJ->MenuCall(0)))
                pAnnexJ->MenuCall(1);
        break;

        case VK_F4:
            DestroyWindow(g_hwndMain);
        break;

        //Unhandled messages
        default:
            // Your debugging code goes here
            // . . . 
        return FALSE;

    }   // switch (wParam)

    return TRUE;
}

See Also

Reference

IDVDUserOperation
IDVDUserOperation::ButtonSelect
IDVDUserOperation::ButtonActivate
IDVDUserOperation::ChangeAngle
IDVDUserOperation::MenuCall
IDVDUserOperation::Pause
IDVDUserOperation::Resume
IDVDUserOperation::StillOff
IDVDUserOperation::TitlePlay

Concepts

Creating a Simple DVD Player