⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playwnd.cpp

📁 playwnd application in evc++
💻 CPP
📖 第 1 页 / 共 2 页
字号:
HRESULT ToggleMute(void)
{
    HRESULT hr=S_OK;

    if ((!pGB) || (!pBA))
        return S_OK;

    // Read current volume
    hr = pBA->get_Volume(&g_lVolume);
    if (hr == E_NOTIMPL)
    {
        // Fail quietly if this is a video-only media file
        return hr;
    }
    else if (FAILED(hr))
    {
        RETAILMSG(1, (TEXT("Failed in pBA->get_Volume!  hr=0x%x\r\n"), hr));
        return hr;
    }

    if (g_lVolume == VOLUME_FULL)
        g_lVolume = VOLUME_SILENCE;
    else
        g_lVolume = VOLUME_FULL;

    // Set new volume
    JIF(pBA->put_Volume(g_lVolume));

    UpdateMainTitle();
    return hr;
}


void UpdateMainTitle(void)
{
    TCHAR szTitle[MAX_PATH], szFile[MAX_PATH];

    // If no file is loaded, just show the application title
    if (g_szFileName[0] == L'\0')
    {
        wsprintf(szTitle, TEXT("%s"), APPLICATIONNAME);
    }

    // Otherwise, show useful information, including filename and play state
    else
    {
        // Get file name without full path
        GetFilename(g_szFileName, szFile);

        // Update the window title to show muted/normal status
        wsprintf(szTitle, TEXT("%s %s%s"),
                szFile,
                (g_lVolume == VOLUME_SILENCE) ? TEXT("(Muted)") : TEXT(""),
                (g_psCurrent == psPAUSED) ? TEXT("(Paused)") : TEXT(""));
    }

    SetWindowText(ghApp, szTitle);
}


void GetFilename(TCHAR *pszFull, TCHAR *pszFile)
{
    int nLength;
    TCHAR szPath[MAX_PATH]={0};
    BOOL bSetFilename=FALSE;

    if(_tcslen(pszFull) < MAX_PATH)
        _tcscpy(szPath, pszFull);
    nLength = _tcslen(szPath);

    for (int i=nLength-1; i>=0; i--)
    {
        if ((szPath[i] == '\\') || (szPath[i] == '/'))
        {
            szPath[i] = '\0';
            lstrcpy(pszFile, &szPath[i+1]);
            bSetFilename = TRUE;
            break;
        }
    }

    // If there was no path given (just a file name), then
    // just copy the full path to the target path.
    if (!bSetFilename)
        _tcscpy(pszFile, pszFull);
}


HRESULT ToggleFullScreen(void)
{
    HRESULT hr=S_OK;
    LONG lMode;
    static HWND hDrain=0;
    BOOL bPausedForTransition=FALSE;

    // Don't bother with full-screen for audio-only files
    if (g_bAudioOnly)
        return S_OK;

    if (!pVW)
        return S_OK;

    // If we're currently playing a media file, pause temporarily
    // to prevent audio/video breakup during/after the transition.
    if (g_psCurrent == psRUNNING)
    {
        PauseClip();
        bPausedForTransition = TRUE;
    }

    // Read current state
    JIF(pVW->get_FullScreenMode(&lMode));

    if (lMode == OAFALSE)
    {
        // Save current message drain
        LIF(pVW->get_MessageDrain((OAHWND *) &hDrain));

        // Set message drain to application main window
        LIF(pVW->put_MessageDrain((OAHWND) ghApp));

        // Switch to full-screen mode
        lMode = OATRUE;
        JIF(pVW->put_FullScreenMode(lMode));
    }
    else
    {
        // Switch back to windowed mode
        lMode = OAFALSE;
        JIF(pVW->put_FullScreenMode(lMode));

        // Undo change of message drain
        LIF(pVW->put_MessageDrain((OAHWND) hDrain));

        // Reset video window
        InitVideoWindow();
        LIF(pVW->SetWindowForeground(-1));

        // Reclaim keyboard focus for player application
        UpdateWindow(ghApp);
        SetForegroundWindow(ghApp);
        SetFocus(ghApp);
    }

    // Restore playback state if we previously paused
    if (bPausedForTransition)
    {
        PauseClip();
    }

    return hr;
}


HRESULT HandleGraphEvent(void)
{
    LONG evCode, evParam1, evParam2;
    HRESULT hr=S_OK;

    while(SUCCEEDED(pME->GetEvent(&evCode, &evParam1, &evParam2, 0)))
    {
        // Spin through the events
        hr = pME->FreeEventParams(evCode, evParam1, evParam2);

		RETAILMSG(1, (TEXT("\r\nHandleGraphEvent[0x%x]!\r\n"), hr));

        if(EC_COMPLETE == evCode)
        {
            LONGLONG pos=0;

			RETAILMSG(1, (TEXT("\r\nEC_COMPLETE[0x%x]"), hr));

            // Reset to first frame of movie
            hr = pMS->SetPositions(&pos, AM_SEEKING_AbsolutePositioning ,
                                   NULL, AM_SEEKING_NoPositioning);
            if (FAILED(hr))
            {
                // Some filters (like MIDI) may not implement interfaces
                // for IMediaSeeking to allow seek to the start.  In that
                // case, just stop and restart for the same effect.
                if (FAILED(hr = pMC->Stop()))
                {
                    RETAILMSG(1, (TEXT("\r\n*** Failed(%08lx) to stop media clip!\r\n"), hr));
                    break;
                }

                if (FAILED(hr = pMC->Run()))
                {
                    RETAILMSG(1, (TEXT("\r\n*** Failed(%08lx) to reset media clip!\r\n"), hr));
                    break;
                }
            }
        }
    }

    return hr;
}


void MoveVideoWindow(void)
{
    RECT rect, client;

    GetClientRect(ghApp, &client);
    if(pVW)
    {
        pVW->SetWindowPosition(client.left, client.top, client.right, client.bottom);
    }

    GetWindowRect(ghApp, &rect);
}



LRESULT CALLBACK WndMainProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

    switch(message)
    {

        case WM_PAINT:
            if ((hWnd == ghApp) && (g_bAudioOnly))
                PaintAudioWindow();
            else
                return DefWindowProc(hWnd, message, wParam, lParam);
            break;

        case WM_SIZE:
        case WM_MOVE:
            MoveVideoWindow();
            break;

        case WM_KEYDOWN:

            switch(wParam)
            {
                case 'P':
                    PauseClip();
                    break;

                case 'S':
                    StopClip();
                    break;

                case 'M':
                    ToggleMute();
                    break;

                case 'F':
                    ToggleFullScreen();
                    break;

                case VK_ESCAPE:
                case VK_F12:
                case 'Q':
                case 'X':
                    CloseClip();
                    break;
            }
            break;

        case WM_COMMAND:

            switch(wParam)
            { // Menus

                case ID_FILE_OPENCLIP:
                    // If we have ANY file open, close it and shut down DShow
                    if (g_psCurrent != psINIT)
                        CloseClip();

                    // Open the new clip
                    OpenClip();
                    break;

                case ID_FILE_EXIT:
                    CloseClip();
                    PostQuitMessage(0);
                    break;

                case ID_FILE_PAUSE:
                    PauseClip();
                    break;

                case ID_FILE_STOP:
                    StopClip();
                    break;

                case ID_FILE_CLOSE:
                    CloseClip();
                    break;

                case ID_FILE_MUTE:
                    ToggleMute();
                    break;

                case ID_FILE_FULLSCREEN:
                    ToggleFullScreen();
                    break;

            } // Menus
            break;


        case WM_GRAPHNOTIFY:
            HandleGraphEvent();
            break;

        case WM_CLOSE:
            PostMessage(ghApp, WM_COMMAND, ID_FILE_EXIT, 0);
            break;

        case WM_DESTROY:
            PostQuitMessage(0);
            break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);

    } // Window msgs handling

    return FALSE;

}


int PASCAL WinMain(HINSTANCE hInstC, HINSTANCE hInstP, LPTSTR lpCmdLine, int nCmdShow)
{
    MSG msg;
    WNDCLASS wc;

    // Initialize COM
    if(FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED)))
    {
        RETAILMSG(1, (TEXT("CoInitialize Failed!\r\n")));
        exit(1);
    }

    // Was a filename specified on the command line?
    if(lpCmdLine[0] != L'\0')
        lstrcpy(g_szFileName, lpCmdLine);

    // Set initial media state
    g_psCurrent = psINIT;

    // Register the window class
    ZeroMemory(&wc, sizeof wc);
    wc.lpfnWndProc = WndMainProc;
    ghInst = wc.hInstance = hInstC;
    wc.lpszClassName = CLASSNAME;
    wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wc.hCursor =      LoadCursor(NULL, IDC_ARROW);
    wc.hIcon =        LoadIcon(hInstC, MAKEINTRESOURCE(IDI_INWINDOW));
    if(!RegisterClass(&wc))
    {
        RETAILMSG(1, (TEXT("RegisterClass Failed! Error=0x%x\r\n"), GetLastError()));
        CoUninitialize();
        exit(1);
    }

    ghApp = CreateWindow(CLASSNAME, APPLICATIONNAME,
                    WS_OVERLAPPED | WS_CAPTION,
                    CW_USEDEFAULT, CW_USEDEFAULT,
                    CW_USEDEFAULT, CW_USEDEFAULT,
                    0, 0, ghInst, 0);

    if(ghApp)
    {
        // Add menu bar
        ghCB = CommandBar_Create(hInstC, ghApp, 1);
        if(ghCB)
        {
            CommandBar_InsertMenubar(ghCB, hInstC, IDR_MENU, 0);
            CommandBar_AddAdornments(ghCB, 0, 0);
            CommandBar_DrawMenuBar(ghCB, 0);
        }

        // Open the specified media file or prompt for a title
        PostMessage(ghApp, WM_COMMAND, ID_FILE_OPENCLIP, 0);

        // Main message loop
        while(GetMessage(&msg,NULL,0,0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    else
    {
        RETAILMSG(1, (TEXT("CreateWindow Failed! Error=0x%x\r\n"), GetLastError()));
    }

    // Finished with COM
    CoUninitialize();

    return msg.wParam;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -