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

📄 ceplayer.cpp

📁 media player 控件源码 用EVC编译可以进行对WINCE下media player控制
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
///////////////////////////////////////////////////////////////////////////////
// File: CEPlayer.cpp
//
// Desc: This file contians the WinMain, WinProc, initialization, and
//       finalization functions for the CEPlayer sample application.
//
///////////////////////////////////////////////////////////////////////////////

#include <windows.h>
#include <tchar.h>

#define _COMCTL32_
#include <commctrl.h>
#undef _COMCTL32_
#include <ole2.h>

#include "PlayerWindow.h"
#include "PropertyDlg.h"
#include "resource.h"

//////
// GUID's for the various interfaces needed by CEPlayer
//
EXTERN_C const CLSID CLSID_MediaPlayer = { 0x22D6F312,
                                           0xB0F6, 0x11D0,
                                          { 0x94, 0xAB, 0x00, 0x80,
                                            0xC7, 0x4C, 0x7E, 0x95 } };
EXTERN_C const IID   IID_IMediaPlayer  = { 0x22D6F311,
                                           0xB0F6, 0x11D0,
                                          { 0x94, 0xAB, 0x00, 0x80,
                                            0xC7, 0x4C, 0x7E, 0x95 } };
EXTERN_C const IID   DIID__MediaPlayerEvents
                                       = { 0x2D3A4C40,
                                           0xE711, 0x11D0,
                                          { 0x94, 0xAB, 0x00, 0x80,
                                            0xC7, 0x4C, 0x7E, 0x95 } };

EXTERN_C const IID   IID_IActiveMovie  = { 0x05589FA2,
                                           0xC356, 0x11CE,
                                          { 0xBF, 0x01, 0x00, 0xAA,
                                            0x00, 0x55, 0x59, 0x5A } };

//////
// Globals
//
TCHAR         *g_szWMPWindowClass  = TEXT("MPContainerWindow");
TCHAR        **g_ppszAudioTypes    = NULL;
TCHAR        **g_ppszVideoTypes    = NULL;
TCHAR        **g_ppszPlaylistTypes = NULL;
TCHAR         *g_szHomePage        = NULL;
DWORD          g_cAudioTypes       = 0;
DWORD          g_cVideoTypes       = 0;
DWORD          g_cPlaylistTypes    = 0;
CPlayerWindow *g_pPlayerWindow     = NULL;
HINSTANCE      g_hInst             = NULL;
HICON          g_hIcon             = NULL;
bool           g_bSmallScreen      = false;
bool           g_bCaptured         = true;  // don't capture until we have a window
bool           g_bInit             = false;
bool           g_bFullscreenToWindowedOnPause = false;

//////
// Prototypes
//
HRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
bool           InitPlayer(HINSTANCE hInstance);
bool           FiniPlayer(HINSTANCE hInstance);
bool           LoadMediaTypes(HINSTANCE hInstance);

///////////////////////////////////////////////////////////////////////////////
// Name: WinProc()
// Desc: This function handles the Window Messages for the main CEPlayer
//       window.
///////////////////////////////////////////////////////////////////////////////
HRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
   PAINTSTRUCT ps;
   HDC hDC;

   switch (msg)
   {
    case WM_GETICON:
		if( ( wParam == ICON_SMALL ) && g_hIcon )
		{
			return (HRESULT)(g_hIcon);
		}
    break;

    case WM_CREATE:
    if (NULL == g_pPlayerWindow)
    {
      g_pPlayerWindow = new CPlayerWindow(hWnd, g_hInst);

      return 0;
    }
    break;

    case WM_ACTIVATE:
      // The constructor doesn't do much work, the Init method is what
      // creates a control container, Event Sink, etc (because it can
      // return a result)
      // The Init method should only be called once, so check a flag first
      if (!g_bInit
          && (NULL == g_pPlayerWindow || false == g_pPlayerWindow->Init()))
      {
          // Must set the init flag because the message box generates a
          // WM_ACTIVATE message.
          g_bInit = true;

         ::MessageBox(hWnd, TEXT("Unable to initialize Player!"), TEXT("Error"), MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_APPLMODAL);

         delete g_pPlayerWindow;
         g_pPlayerWindow = NULL;

         ::PostQuitMessage(0);
      }
      g_bInit = true;
      return 0;

    case WM_KEYUP:
      if (g_pPlayerWindow && (true == g_pPlayerWindow->OnWindowMessage(msg, wParam, lParam)))
      {
         return 0;
      }

      break;

    case WM_COMMAND:
      if (g_pPlayerWindow->OnCommand(LOWORD(wParam), lParam))
      {
         return 0;
      }
      break;

    case WM_COPYDATA:
      if( lParam )
      {
          PCOPYDATASTRUCT lpCDS = (PCOPYDATASTRUCT)lParam;
          if( g_pPlayerWindow )
              g_pPlayerWindow->OnOpen((TCHAR *)(lpCDS->lpData));
      }
      return 0;

    case WM_CLOSE:
      // Tell the player window to shut down (hide itself and stop playback)
      if (NULL != g_pPlayerWindow)
      {
         delete g_pPlayerWindow;
         g_pPlayerWindow = NULL;
      }

      ::PostQuitMessage(0);
      return 0;

    case WM_PAINT:

      if (!wParam)
      {
         hDC = BeginPaint(hWnd, &ps);
      }
      else
      {
         hDC = (HDC)wParam;
      }

      if (NULL != g_pPlayerWindow)
      {
         g_pPlayerWindow->OnPaint(hDC, &(ps.rcPaint));
      }

      if (!wParam)
      {
         EndPaint(hWnd, &ps);
      }
      return 0;

    case WM_SIZE:
      if (NULL != g_pPlayerWindow)
      {
         if (g_bSmallScreen)
         {
             g_pPlayerWindow->OnSizeSmall(LOWORD(lParam), HIWORD(lParam));
         }
         else
         {
             g_pPlayerWindow->OnSize(LOWORD(lParam), HIWORD(lParam));
         }
      }
      return 0;

    case WM_MOUSEMOVE:
      if (NULL != g_pPlayerWindow)
      {
         g_pPlayerWindow->OnMouseMove(LOWORD(lParam), HIWORD(lParam));
      }
      break;

    case WM_LBUTTONDOWN:
      if (NULL != g_pPlayerWindow)
      {
         g_pPlayerWindow->OnMouseDown(LOWORD(lParam), HIWORD(lParam));
      }
      break;
 
    case WM_LBUTTONUP:
      if (NULL != g_pPlayerWindow)
      {
         g_pPlayerWindow->OnMouseUp(LOWORD(lParam), HIWORD(lParam));
      }
      break;

    case WM_TIMER:
      if (NULL != g_pPlayerWindow)
      {
         if (g_pPlayerWindow->OnTimer((UINT)wParam))
         {
             return 0;
         }
      }
      break;

    case WM_MEASUREITEM:
      if (NULL != g_pPlayerWindow && 0 == wParam)
      {
          g_pPlayerWindow->OnMeasureItem((MEASUREITEMSTRUCT*)lParam);
          return 0;
      }
      break;

    case WM_DRAWITEM:
      if (NULL != g_pPlayerWindow && 0 == wParam)
      {
          g_pPlayerWindow->OnDrawItem((DRAWITEMSTRUCT*)lParam);
          return 0;
      }
      break;

    // This message is a user defined window message for the Properties
    // dialog box.  (The message is sent when the dialog closes)
    case PD_CLOSED:
      if (NULL != g_pPlayerWindow)
      {
         g_pPlayerWindow->PropertyDlgClosed();
      }
      return 0;

    // This message is a user defined window message for the Statistics
    // dialog box.  (The message is sent when the dialog closes)
    case SD_CLOSED:
      if (NULL != g_pPlayerWindow)
      {
         g_pPlayerWindow->StatisticsDlgClosed();
      }
      return 0;
   }

   // redirect all other messages to the MediaPlayer control
   if (NULL != g_pPlayerWindow
       && true == g_pPlayerWindow->OnWindowMessage(msg, wParam, lParam))
   {
      return 0;
   }

   return DefWindowProc(hWnd, msg, wParam, lParam);
}


///////////////////////////////////////////////////////////////////////////////
// Name: WinMain()
// Desc: This function is the entry point for the CEPlayer application
///////////////////////////////////////////////////////////////////////////////
#ifdef UNDER_CE
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPTSTR szCmdLine, int iCmdShow)
#else
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR pCmdLine, int iCmdShow)
#endif
{
   int  iXPos, iYPos;
   HWND hWnd;
   HACCEL hAccel;
   MSG  msg;
   HKEY hkResult = NULL;
   DWORD dwDisp, dwType, dwData, dwSize;
   BOOL bOpenMultiple = FALSE;
   BOOL bPlayForever = FALSE;
   DWORD dwZoomLevel = 1; // Default to 100% (0 is 50%, 2 is 200%)

#ifndef UNDER_CE
   //GetCommandLine();
   WCHAR szCmdLine[] = L"\0";
#endif

   srand( GetTickCount() ); // Do this so that shuffle mode of playlist content is actually random...

   LoadMediaTypes(hInstance);

   HDC hdc = ::GetDC(NULL);
   int iXRes = GetDeviceCaps(hdc, HORZRES);
   int iYRes = GetDeviceCaps(hdc, VERTRES);
   ::ReleaseDC(NULL, hdc);

   if (iXRes < 480 || iYRes < 480)
   {
       g_bSmallScreen = true;
   }

   if (iXRes < 200 || iYRes < 120)
   {
      MessageBox(NULL, TEXT("The Media Player cannot function properly on a display this size."), TEXT("ERROR"), MB_OK | MB_ICONEXCLAMATION);

      return 0;
   }

   // Initialize the Player.  If it fails, there's not much point in going on.
   if (false == InitPlayer(hInstance))
   {
      MessageBox(NULL, TEXT("Unable to initialize Player!"), TEXT("Error"), MB_OK | MB_ICONEXCLAMATION);

      FiniPlayer(hInstance);

      return 0;
   }

   g_hInst = hInstance;

   g_hIcon = (HICON)LoadImage( g_hInst, MAKEINTRESOURCE(IDI_APPICON), IMAGE_ICON, 16, 16, 0 );

   // Get the OpenMultiple setting from the registry
   if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE,
                                       TEXT("SOFTWARE\\Microsoft\\CEPlayer"),
                                       0, NULL, 0, 0, NULL, &hkResult, &dwDisp))
   {
      g_szHomePage = new TCHAR [1024];
      dwSize = 1024 * sizeof (TCHAR);

      RegQueryValueEx(hkResult,
                      TEXT("HomePage"),
                      NULL,
                      &dwType,
                      (BYTE*)g_szHomePage,
                      &dwSize);

      if (REG_SZ != dwType || 0 == dwSize)
      {
          delete [] g_szHomePage;
          g_szHomePage = NULL;
      }

      if( REG_OPENED_EXISTING_KEY == dwDisp )
      {
         dwSize = sizeof( bool );
         RegQueryValueEx( hkResult, L"WindowedOnPause", NULL, NULL, (LPBYTE)&g_bFullscreenToWindowedOnPause, &dwSize );
         // Don't overwrite our g_bSmallScreen variable if its already set (due to screen-size dimensions)
         if( !g_bSmallScreen )
            RegQueryValueEx( hkResult, L"AlwaysFullSize", NULL, NULL, (LPBYTE)&g_bSmallScreen, &dwSize );
         RegQueryValueEx( hkResult, L"OpenMultiple", NULL, NULL, (LPBYTE)&bOpenMultiple, &dwSize );
      }
   }

   if( !bOpenMultiple )
   {
       hWnd = FindWindow(g_szWMPWindowClass, NULL);	

⌨️ 快捷键说明

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