home *** CD-ROM | disk | FTP | other *** search
- //==========================================================================;
- //
- // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
- // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
- // PURPOSE.
- //
- // Copyright (c) 1992 - 1996 Microsoft Corporation. All Rights Reserved.
- //
- //--------------------------------------------------------------------------;
-
- /* Player, Quartz multimedia sample
- */
-
- #include "stdwin.h"
- #include "cplay.h"
- #include "about.h"
- #include "file.h"
- #include "media.h"
- #include "toolbar.h"
-
- #include "resource.h"
-
- #define UNTITLED_STRING " - Untitled"
- #define nMaxResourceStrSize 128
-
- AppVars appVars;
-
- void PlayerMessageBox( UINT nResource ){
- /* Load and display an error message */
- char szStr[ nMaxResourceStrSize ];
-
- LoadString( appVars.hInstance, nResource, szStr, nMaxResourceStrSize );
- MessageBox( appVars.hwndMainFrame, szStr, appVars.szAppName,
- MB_APPLMODAL | MB_OK | MB_ICONEXCLAMATION );
- }
-
- /**************************************************************************/
- long ProcessCommand( HWND hwnd, UINT wParam, LONG lParam ){
- /* Process a WM_COMMAND message to the main window */
-
- switch( wParam ){
- case ID_FILE_EXIT:
- PostQuitMessage( 0 );
- break;
-
- case ID_HELP_ABOUT:
- DoAboutDialog( appVars.hInstance,hwnd );
- break;
-
- case ID_FILE_OPEN:
- OpenMediaFile( hwnd, NULL );
- break;
-
- case ID_MEDIA_PLAY:
- OnMediaPlay( );
- break;
-
- case ID_MEDIA_PAUSE:
- OnMediaPause( );
- break;
-
- case ID_MEDIA_STOP:
- OnMediaStop( );
- break;
-
- default:
- return DefWindowProc( hwnd, WM_COMMAND, wParam, lParam );
-
- }
-
- return 0;
-
- }
-
- void OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
- { /* Sets the minimum size of the main window and the maximum height */
- RECT rectRequired;
- SIZE sizeToolbar;
-
- // Our client area is going to be the toolbar, so find our its size
- CalcRequiredSize( &sizeToolbar );
-
- rectRequired.left = rectRequired.top = 0;
- rectRequired.right = sizeToolbar.cx;
- rectRequired.bottom = sizeToolbar.cy;
-
- // Take into account the menu, caption and thick frame
- AdjustWindowRect( &rectRequired, WS_CAPTION|WS_THICKFRAME, TRUE );
-
- // Set the min/max sizes
- lpMMI->ptMinTrackSize.x = rectRequired.right - rectRequired.left;
- lpMMI->ptMinTrackSize.y = lpMMI->ptMaxTrackSize.y =
- rectRequired.bottom - rectRequired.top;
- }
-
- long FAR PASCAL MainFrameProc( HWND hwnd, UINT message, UINT wParam, LONG lParam){
- /* Handles the message sent to the main window */
-
- switch( message ){
- case WM_DESTROY:
- PostQuitMessage( 0 );
- break;
-
- case WM_GETMINMAXINFO:
- OnGetMinMaxInfo( (MINMAXINFO FAR *) lParam );
- break;
-
- case WM_DRAWITEM:
- DrawButton( appVars.hInstance, (DRAWITEMSTRUCT FAR *) lParam );
- break;
-
- case WM_INITMENUPOPUP:
- if( lParam == 1 ){ // Media popup menu
- EnableMenuItem( (HMENU) wParam, ID_MEDIA_PLAY, CanPlay() ? MF_ENABLED : MF_GRAYED );
- EnableMenuItem( (HMENU) wParam, ID_MEDIA_PAUSE, CanPause() ? MF_ENABLED : MF_GRAYED );
- EnableMenuItem( (HMENU) wParam, ID_MEDIA_STOP, CanStop() ? MF_ENABLED : MF_GRAYED );
- } else
- return DefWindowProc( hwnd, message, wParam, lParam );
- break;
-
- case WM_COMMAND:
- return ProcessCommand( hwnd, wParam, lParam );
-
-
- default:
- return DefWindowProc( hwnd, message, wParam, lParam );
- }
-
- return 0;
- }
-
- /**************************************************************************/
- BOOL InitApplication( void ){
- strcpy( appVars.szAppName, APP_NAME );
-
- // Filter interface initialize?
- if( SUCCEEDED( CoInitialize( NULL ) ) )
- return TRUE;
-
- return FALSE;
- }
-
- void UnInitApplication( void ){
- CoUninitialize( );
- }
-
- BOOL InitInstance( HANDLE hInstance, HANDLE hPrevInstance ){
- // Set the specific instance data and register our main window class
- // if it has not been registered already
- appVars.hInstance = hInstance;
-
- if(!hPrevInstance){
- WNDCLASS wndClass;
-
- wndClass.style = CS_HREDRAW | CS_VREDRAW;
- wndClass.lpfnWndProc = MainFrameProc;
- wndClass.cbClsExtra = 0;
- wndClass.cbWndExtra = 0;
- wndClass.hInstance = appVars.hInstance;
- wndClass.hIcon = LoadIcon( appVars.hInstance, MAKEINTRESOURCE( IDR_MAINFRAME ));
- wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
- wndClass.hbrBackground = GetStockObject( LTGRAY_BRUSH );
- wndClass.lpszMenuName = MAKEINTRESOURCE( IDR_MAINFRAME );
- wndClass.lpszClassName = appVars.szAppName;
-
- RegisterClass( &wndClass );
- }
-
- return TRUE;
- }
-
- BOOL InitMainFrame( int nCmdShow ){
- // Create out main window
- char szTitle[ 30 ];
-
- strcpy( szTitle, APP_NAME );
- strcat( szTitle, UNTITLED_STRING );
-
- appVars.hwndMainFrame = CreateWindow( appVars.szAppName,
- szTitle,
- WS_OVERLAPPEDWINDOW &~ WS_MAXIMIZEBOX,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- 0,
- 65,
- NULL,
- NULL,
- appVars.hInstance,
- NULL
- );
-
- ShowWindow( appVars.hwndMainFrame, nCmdShow );
- UpdateWindow( appVars.hwndMainFrame );
-
- return TRUE;
- }
-
- /************************************************************************/
- UINT DoMainLoop( void ){
- // main message loop
- MSG msg;
- HANDLE ahObjects[1]; // handles that need to be waited on
- const int cObjects = 1; // no of objects that we are waiting on
-
- // message loop lasts until we get a WM_QUIT message
- // upon which we shall return from the function
- while (TRUE) {
- if( (ahObjects[ 0 ] = GetGraphEventHandle()) == NULL )
- WaitMessage();
- else{
- // wait for any message sent or posted to this queue
- // or for a graph notification
- DWORD result;
-
- result = MsgWaitForMultipleObjects( cObjects
- , ahObjects
- , FALSE
- , INFINITE
- , QS_ALLINPUT
- );
- if( result != (WAIT_OBJECT_0 + cObjects) ){
-
- if( result == WAIT_OBJECT_0 )
- OnGraphNotify();
-
- continue;
- }
- }
-
- // When here, we either have a message or no event handle
- // has been created yet.
-
- // read all of the messages in this next loop
- // removing each message as we read it
- while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
-
- if (msg.message == WM_QUIT)
- return msg.wParam;
-
- TranslateMessage(&msg);
- DispatchMessage(&msg);
-
- }
-
- } // end of the always while-loop
-
- } // DoMainLoop
-
-
- /************************************************************************/
- int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpszCmdParam, int nCmdShow ){
- UINT nReturn;
-
- if ( ! InitApplication( ) )
- return 0;
-
- if( InitInstance( hInstance, hPrevInstance )
- && InitMainFrame( nCmdShow )
- && InitToolbar( hInstance, appVars.hwndMainFrame )
- && InitMedia( )
- && InitFileOpenDialog( appVars.hwndMainFrame )
- ){
- if( lpszCmdParam[0] != '\0' )
- OpenMediaFile( appVars.hwndMainFrame, lpszCmdParam );
-
- // else..
- nReturn = DoMainLoop();
-
- // Stop the graph if we can
- if( CanStop() )
- OnMediaStop();
-
- // release the filter graph
- DeleteContents();
- }
-
- UnInitApplication();
-
- return nReturn;
- }
-
-