home *** CD-ROM | disk | FTP | other *** search
- //==================================================================================================
- // Includes
-
- #include "stdafx.h"
- #include "Demo.h"
- #include <commdlg.h>
- #include <string>
-
- //==================================================================================================
- // FlashPlayerControl
-
- // FlashPlayerControl header
- #include "../../../FlashPlayerControl/include/FlashPlayerControl.h"
-
- // FlashPlayerControl lib
- #pragma comment(lib, "../../../FlashPlayerControl/lib/FlashPlayerControl.lib")
-
- //==================================================================================================
- // Typedefs
-
- // To work with TCHAR strings
- typedef std::basic_string<TCHAR> tstring;
-
- //==================================================================================================
- // Global Variables
-
- // Current instance
- HINSTANCE g_hInstance;
- // FlashPlayerControl window handle
- HWND g_hwndFlashPlayerControl;
-
- //==================================================================================================
- // Forward declarations
-
- // Processes messages for the main window
- LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
-
- // Load resource helper
- void LoadResourceHelper( /* in */ LPCTSTR lpszName,
- /* in */ LPCTSTR lpszType,
- /* out */ LPVOID& lpData,
- /* out */ DWORD& dwSize);
-
- // Message handlers
- LRESULT OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
- LRESULT OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
- LRESULT OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
- LRESULT OnSize(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
-
- // FlashPlayerControl specific message handlers
- LRESULT OnFSCommand(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
- LRESULT OnProgress(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
- LRESULT OnReadyStateChange(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
- LRESULT OnLoadExternalResource(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
-
- //==================================================================================================
- // Entry point
- int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
- {
- // Store instance handle in our global variable
- g_hInstance = hInstance;
-
- //==============================================================================================
- // Main window class registration...BEGIN
-
- WNDCLASSEX wcex = { 0 };
-
- wcex.cbSize = sizeof(WNDCLASSEX);
-
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = &WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = g_hInstance;
- wcex.hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_DEMO));
- wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wcex.lpszMenuName = MAKEINTRESOURCE(IDC_DEMO);
- wcex.lpszClassName = _T("DEMO");
- wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
-
- RegisterClassEx(&wcex);
-
- // Main window class registration...BEGIN
- //==============================================================================================
-
- //==============================================================================================
- // FlashPlayerControl library initialization...BEGIN
-
- #ifdef WITH_EMBEDDED_FLASH_OCX_CODE
-
- // swflash.ocx/flash.ocx embedding...
-
- LPVOID lpFlashOCXCodeData = NULL;
- DWORD dwFlashOCXCodeSize = 0;
-
- LoadResourceHelper(_T("FLASHOCXCODE"), _T("BIN"), lpFlashOCXCodeData, dwFlashOCXCodeSize);
-
- if (!RegisterFlashWindowClassEx(lpFlashOCXCodeData, dwFlashOCXCodeSize))
- {
- MessageBox(NULL, _T("RegisterFlashWindowClass() failed"), _T("Error"), MB_OK | MB_ICONSTOP);
- return FALSE;
- }
-
- #else
-
- if (!RegisterFlashWindowClass())
- {
- MessageBox(NULL, _T("RegisterFlashWindowClass() failed"), _T("Error"), MB_OK | MB_ICONSTOP);
- return FALSE;
- }
-
- #endif // WITH_EMBEDDED_FLASH_OCX_CODE
-
- // FlashPlayerControl library initialization...END
- //==============================================================================================
-
- //==============================================================================================
- // Main window creating...BEGIN
-
- HWND hWnd;
-
- hWnd =
- CreateWindow(_T("DEMO"),
- _T("DEMO"),
- WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
- CW_USEDEFAULT,
- 0,
- CW_USEDEFAULT,
- 0,
- NULL,
- NULL,
- g_hInstance,
- NULL);
-
- if (NULL == hWnd)
- return FALSE;
-
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
-
- // Main window creating...END
- //==============================================================================================
-
- MSG msg = { 0 };
- HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_DEMO));
-
- // Main message loop
- while (GetMessage(&msg, NULL, 0, 0))
- {
- if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
-
- // FlashPlayerControl library deinitialization...BEGIN
- UnregisterFlashWindowClass();
-
- return (int)msg.wParam;
- }
-
- //==================================================================================================
- // Processes messages for the main window
- LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- LRESULT lResult = 0;
- BOOL bHandled = FALSE;
-
- switch (uMsg)
- {
- case WM_COMMAND:
- {
- lResult = OnCommand(hWnd, wParam, lParam, bHandled);
-
- break;
- }
-
- case WM_DESTROY:
- {
- lResult = OnDestroy(hWnd, wParam, lParam, bHandled);
-
- break;
- }
-
- case WM_CREATE:
- {
- lResult = OnCreate(hWnd, wParam, lParam, bHandled);
-
- break;
- }
-
- case WM_SIZE:
- {
- lResult = OnSize(hWnd, wParam, lParam, bHandled);
-
- break;
- }
-
- case WM_NOTIFY:
- {
- NMHDR* pNMHDR = (NMHDR*)lParam;
-
- if (pNMHDR->hwndFrom == g_hwndFlashPlayerControl)
- {
- switch (pNMHDR->code)
- {
- case FPCN_FSCOMMAND:
- {
- lResult = OnFSCommand(hWnd, wParam, lParam, bHandled);
-
- break;
- }
-
- case FPCN_ONPROGRESS:
- {
- lResult = OnProgress(hWnd, wParam, lParam, bHandled);
-
- break;
- }
-
- case FPCN_ONREADYSTATECHANGE:
- {
- lResult = OnReadyStateChange(hWnd, wParam, lParam, bHandled);
-
- break;
- }
-
- case FPCN_LOADEXTERNALRESOURCE:
- {
- lResult = OnLoadExternalResource(hWnd, wParam, lParam, bHandled);
-
- break;
- }
- }
- }
- }
-
- break;
- }
-
- if (!bHandled)
- lResult = DefWindowProc(hWnd, uMsg, wParam, lParam);
-
- return lResult;
- }
- //==================================================================================================
-
- //==================================================================================================
- // Load resource helper
- void LoadResourceHelper( /* in */ LPCTSTR lpszName,
- /* in */ LPCTSTR lpszType,
- /* out */ LPVOID& lpData,
- /* out */ DWORD& dwSize)
- {
- HMODULE hModule = GetModuleHandle(NULL);
- HRSRC hResInfo = FindResource(hModule, lpszName, lpszType);
- HGLOBAL hResData = LoadResource(hModule, hResInfo);
- lpData = LockResource(hResData);
- dwSize = SizeofResource(hModule, hResInfo);
- }
- //==================================================================================================
-
- //==================================================================================================
- LRESULT OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- LRESULT lResult = 0;
-
- int wmId = LOWORD(wParam);
- int wmEvent = HIWORD(wParam);
-
- // Parse the menu selections
- switch (wmId)
- {
- case IDM_EXIT:
- {
- DestroyWindow(hWnd);
- bHandled = TRUE;
- break;
- }
-
- case ID_FILE_OPEN:
- {
- DWORD dwOPENFILENAMESize;
-
- #if (defined(WINVER) && (_WIN32_WINNT >= 0x0500))
- OSVERSIONINFO vi;
- ZeroMemory(&vi, sizeof(OSVERSIONINFO));
- vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- ::GetVersionEx(&vi);
- // if running under NT and version is >= 5
- if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT && vi.dwMajorVersion >= 5)
- dwOPENFILENAMESize = sizeof(OPENFILENAME);
- else
- dwOPENFILENAMESize = OPENFILENAME_SIZE_VERSION_400;
- #else
- dwOPENFILENAMESize = sizeof(OPENFILENAME);
- #endif // defined(WINVER) && (_WIN32_WINNT >= 0x0500)
-
- OPENFILENAME* pOpenFileName = (OPENFILENAME*)new char[dwOPENFILENAMESize];
- ZeroMemory(pOpenFileName, dwOPENFILENAMESize);
-
- TCHAR lpszFilePath[_MAX_PATH] = { 0 };
-
- pOpenFileName->lStructSize = dwOPENFILENAMESize;
- pOpenFileName->hwndOwner = hWnd;
- pOpenFileName->lpstrFilter = _T("Flash movie files (*.swf)\0*.swf\0All files (*.*)\0*.*\0\0");
- pOpenFileName->lpstrFile = lpszFilePath;
- pOpenFileName->nMaxFile = _MAX_PATH + 1;
- pOpenFileName->Flags = OFN_ENABLESIZING;
- pOpenFileName->lpstrDefExt = _T("swf");
-
- if (GetOpenFileName(pOpenFileName))
- {
- SFPCPutMovie SFPCPutMovie;
-
- SFPCPutMovie.lpszBuffer = pOpenFileName->lpstrFile;
-
- ::SendMessage(g_hwndFlashPlayerControl, FPCM_PUT_MOVIE, 0, (LPARAM)&SFPCPutMovie);
- }
-
- delete[] (char*)pOpenFileName;
-
- bHandled = TRUE;
-
- break;
- }
- }
-
- return lResult;
- }
- //==================================================================================================
-
- //==================================================================================================
- LRESULT OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- // Client area
- RECT rc = { 0 };
- GetClientRect(hWnd, &rc);
-
- g_hwndFlashPlayerControl =
- CreateWindow(WC_FLASH,
- NULL,
- WS_CHILD | WS_VISIBLE,
- rc.left,
- rc.top,
- rc.right - rc.left,
- rc.bottom - rc.top,
- hWnd,
- NULL,
- g_hInstance,
- NULL);
-
- // Loading movie from the resource
- LPVOID lpMovieData = NULL;
- DWORD dwMovieSize = 0;
-
- LoadResourceHelper(_T("MOVIE1"), _T("MOVIE"), lpMovieData, dwMovieSize);
-
- SFPCPutMovieFromMemory SFPCPutMovieFromMemory = { 0 };
-
- SFPCPutMovieFromMemory.dwSize = dwMovieSize;
- SFPCPutMovieFromMemory.lpData = lpMovieData;
-
- ::SendMessage(g_hwndFlashPlayerControl, FPCM_PUTMOVIEFROMMEMORY, 0, (LPARAM)&SFPCPutMovieFromMemory);
-
- bHandled = TRUE;
-
- return 0;
- }
- //==================================================================================================
-
- //==================================================================================================
- LRESULT OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- PostQuitMessage(0);
-
- bHandled = TRUE;
-
- return 0;
- }
- //==================================================================================================
-
- //==================================================================================================
- LRESULT OnSize(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- if (NULL != g_hwndFlashPlayerControl)
- {
- RECT rc;
- GetClientRect(hWnd, &rc);
-
- MoveWindow(g_hwndFlashPlayerControl, 0, 0, rc.right, rc.bottom, TRUE);
- }
-
- bHandled = TRUE;
-
- return 0;
- }
- //==================================================================================================
-
- //==================================================================================================
- LRESULT OnFSCommand(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- SFPCFSCommandInfoStruct* pInfo = (SFPCFSCommandInfoStruct*)lParam;
- tstring strText = _T("command: \"");
- strText += pInfo->command;
- strText += _T("\"");
- strText += _T("\nargs: \"");
- strText += pInfo->args;
- strText += _T("\"");
-
- MessageBox(hWnd, strText.c_str(), _T("FSCommand()"), MB_OK | MB_ICONINFORMATION);
-
- bHandled = TRUE;
-
- return 0;
- }
- //==================================================================================================
-
- //==================================================================================================
- LRESULT OnProgress(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- SFPCOnProgressInfoStruct* pInfo = (SFPCOnProgressInfoStruct*)lParam;
-
- TCHAR lpszBuffer[1024];
- _sntprintf(lpszBuffer, sizeof(lpszBuffer) - 1, _T("FPCN_ONPROGRESS, percentDone: %d\n"), pInfo->percentDone);
-
- // MessageBox(hWnd, lpszBuffer, _T("OnProgress()"), MB_OK | MB_ICONINFORMATION);
- OutputDebugString(lpszBuffer);
-
- bHandled = TRUE;
-
- return 0;
- }
- //==================================================================================================
-
- //==================================================================================================
- LRESULT OnReadyStateChange(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- SFPCOnReadyStateChangeInfoStruct* pInfo = (SFPCOnReadyStateChangeInfoStruct*)lParam;
-
- TCHAR lpszBuffer[1024];
- _sntprintf(lpszBuffer, sizeof(lpszBuffer) - 1, _T("FPCN_ONREADYSTATECHANGE, newState: %d\n"), pInfo->newState);
-
- // MessageBox(hWnd, lpszBuffer, _T("OnReadyStateChange()"), MB_OK | MB_ICONINFORMATION);
- OutputDebugString(lpszBuffer);
-
- bHandled = TRUE;
-
- return 0;
- }
- //==================================================================================================
-
- //==================================================================================================
- LRESULT OnLoadExternalResource(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- LPVOID lpResourceData = NULL;
- DWORD dwResourceSize = 0;
-
- SFPCLoadExternalResource* pInfo = (SFPCLoadExternalResource*)lParam;
-
- if (0 == lstrcmpi(pInfo->lpszRelativePath, _T("/images/embedded_image1.jpg")))
- {
- LoadResourceHelper(_T("IMAGE1"), _T("IMAGE"), lpResourceData, dwResourceSize);
-
- ULONG ulWritten;
- pInfo->lpStream->Write(lpResourceData, dwResourceSize, &ulWritten);
- }
- else if (0 == lstrcmpi(pInfo->lpszRelativePath, _T("/images/embedded_image2.jpg")))
- {
- LoadResourceHelper(_T("IMAGE2"), _T("IMAGE"), lpResourceData, dwResourceSize);
-
- ULONG ulWritten;
- pInfo->lpStream->Write(lpResourceData, dwResourceSize, &ulWritten);
- }
- else if (0 == lstrcmpi(pInfo->lpszRelativePath, _T("/images/embedded_image3.jpg")))
- {
- LoadResourceHelper(_T("IMAGE3"), _T("IMAGE"), lpResourceData, dwResourceSize);
-
- ULONG ulWritten;
- pInfo->lpStream->Write(lpResourceData, dwResourceSize, &ulWritten);
- }
- else if (0 == lstrcmpi(pInfo->lpszRelativePath, _T("/images/embedded_image4.jpg")))
- {
- LoadResourceHelper(_T("IMAGE4"), _T("IMAGE"), lpResourceData, dwResourceSize);
-
- ULONG ulWritten;
- pInfo->lpStream->Write(lpResourceData, dwResourceSize, &ulWritten);
- }
- else if (0 == lstrcmpi(pInfo->lpszRelativePath, _T("/images/embedded_image5.jpg")))
- {
- LoadResourceHelper(_T("IMAGE5"), _T("IMAGE"), lpResourceData, dwResourceSize);
-
- ULONG ulWritten;
- pInfo->lpStream->Write(lpResourceData, dwResourceSize, &ulWritten);
- }
- else
- {
- DWORD dwOPENFILENAMESize;
-
- #if (defined(WINVER) && (_WIN32_WINNT >= 0x0500))
- OSVERSIONINFO vi;
- ZeroMemory(&vi, sizeof(OSVERSIONINFO));
- vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- ::GetVersionEx(&vi);
- // if running under NT and version is >= 5
- if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT && vi.dwMajorVersion >= 5)
- dwOPENFILENAMESize = sizeof(OPENFILENAME);
- else
- dwOPENFILENAMESize = OPENFILENAME_SIZE_VERSION_400;
- #else
- dwOPENFILENAMESize = sizeof(OPENFILENAME);
- #endif // defined(WINVER) && (_WIN32_WINNT >= 0x0500)
-
- OPENFILENAME* pOpenFileName = (OPENFILENAME*)new char[dwOPENFILENAMESize];
- ZeroMemory(pOpenFileName, dwOPENFILENAMESize);
-
- TCHAR lpszFilePath[_MAX_PATH] = { 0 };
-
- pOpenFileName->lStructSize = dwOPENFILENAMESize;
- pOpenFileName->hwndOwner = hWnd;
- pOpenFileName->lpstrFilter = _T("JPEG (*.jpg, *.jpeg)\0*.jpg;*.jpeg\0All files (*.*)\0*.*\0\0");
- pOpenFileName->lpstrFile = lpszFilePath;
- pOpenFileName->nMaxFile = _MAX_PATH + 1;
- pOpenFileName->Flags = OFN_ENABLESIZING;
- pOpenFileName->lpstrDefExt = _T("jpg");
-
- if (GetOpenFileName(pOpenFileName))
- {
- HANDLE hFile =
- CreateFile(pOpenFileName->lpstrFile,
- GENERIC_READ,
- FILE_SHARE_READ,
- NULL,
- OPEN_EXISTING,
- 0,
- NULL);
-
- if (INVALID_HANDLE_VALUE != hFile)
- {
- HANDLE hFileMapping =
- CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
-
- lpResourceData =
- MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
- dwResourceSize =
- GetFileSize(hFile, NULL);
-
- ULONG ulWritten;
- pInfo->lpStream->Write(lpResourceData, dwResourceSize, &ulWritten);
-
- UnmapViewOfFile(lpResourceData);
-
- CloseHandle(hFileMapping);
- }
-
- CloseHandle(hFile);
- }
-
- delete[] (char*)pOpenFileName;
- }
-
- bHandled = TRUE;
-
- return 0;
- }
- //==================================================================================================
-