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

📄 flashwince.cpp

📁 能够播放Flash4格式的Flash文件
💻 CPP
📖 第 1 页 / 共 2 页
字号:

#include "stdafx.h"
#include "resource.h"
#include "FlashWinCE.h"
#include "version.h"
#include "../global.h"
#include "../stags.h"
#include "../sobject.h"
#include "../memcop.h"
#include "../edittext.h"

#include "../mcontext.h"
#include "util.h"

#include "stdio.h"

// Test defines - for file streaming.
// #define KILOBYTESPERSEC		4			// How many kbytes per sec - set to 0 for fastest
// #define SIMULATE_STREAMING				// When defined, loads files piece by piece on seperate thread,
										// when not defined, loads the entire file from disk

struct ThreadData
{
	HWND		hwnd;
	FILE*		fp;
	void*		notifyData;
	char*		url;
	StreamData	streamData;
};

#define MAX_LOADSTRING 100
#define TIMER_PLAY		1
#define TIMER_CURSOR	2

// Global Variables:
HINSTANCE hInst;								// current instance
TCHAR szTitle[MAX_LOADSTRING];					// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];			// The title bar text


HWND				hwndCB;			// The command bar handle

// Foward declarations of functions included in this code module:
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);


int WINAPI WinMain(	HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPTSTR    lpCmdLine,
					int       nCmdShow)
{
	MSG msg;
	HACCEL hAccelTable;

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMPLEWIN);

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return msg.wParam;
}

ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASS wcex;

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLEWIN);
	wcex.hCursor		= NULL;                                 //LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH) GetStockObject(WHITE_BRUSH); //(HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= 0;                                    //(LPCSTR)IDM_SIMPLEWIN;
	wcex.lpszClassName	= szWindowClass;

	return RegisterClass(&wcex);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable


	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_SIMPLEWIN, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

   hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

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

	static NativePlayerWnd* flashWin = 0;
	static OPENFILENAME ofn;
	static 	SPOINT	contextPoint;

	wchar_t szFileName[_MAX_PATH];
	wchar_t szFileTitle[_MAX_PATH];
	char   filename[_MAX_PATH];

	HDC hdc;
	int wmId, wmEvent;
	PAINTSTRUCT ps;
//	TCHAR szHello[MAX_LOADSTRING];

	switch (message) 
	{
		case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			// Parse the menu selections:
			switch (wmId)
			{
				case IDM_OPEN:
					{
					//	FLASHOUTPUT( "---Test!----\n", CommDlgExtendedError() );

						memset(&ofn, 0, sizeof(ofn)); // initialize structure to 0/NULL

						wcscpy( &szFileName[0], L"*.swf");
						szFileTitle[0] = 0;
						
						wchar_t * szFilter = L"*.swf\0";

						ofn.lpstrFilter = szFilter;
						ofn.lStructSize = sizeof(ofn);
						ofn.lpstrFile = szFileName;
						ofn.nMaxFile = 255;
						ofn.lpstrDefExt = L"swf";
						ofn.lpstrFileTitle = szFileTitle;
						ofn.nMaxFileTitle = 255;
						ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;

						ofn.nFilterIndex = 0;
						ofn.hwndOwner = hWnd;
						ofn.hInstance = 0;

						if ( GetOpenFileName( &ofn ) )
						{
							wcstombs( filename, ofn.lpstrFile, _MAX_PATH );
							flashWin->ControlOpen( filename);//(char *)ofn.lpstrFile );
							flashWin->ControlViewAll();
						}
					//	FLASHOUTPUT( "Return from Open=%d\n", CommDlgExtendedError() );
					}
						
					break;

				case IDM_EXIT:
				   DestroyWindow(hWnd);
				   break;
				case IDM_100:
					flashWin->Control100();
					break;
				case IDM_VIEWALL:
					flashWin->ControlViewAll();
					break;

				default:
				   return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
		case WM_CREATE:
			hwndCB = CommandBar_Create(hInst, hWnd, 1);			
			CommandBar_InsertMenubar(hwndCB, hInst, IDC_SIMPLEWIN, 0);
			CommandBar_AddAdornments(hwndCB, 0, 0);

//			MenuStatus menuStatus;

			flashWin = new NativePlayerWnd();
			flashWin->initialize( hWnd );

//			flashWin->GetMenuState( &menuStatus );
//			flashWin->EnableMenus( menuStatus );

			

//			flashWin->ControlOpen( "speedy.swf" );
//			flashWin->ControlViewAll();

			break;
		case WM_PAINT:
			flashWin->SetDC( BeginPaint(hWnd, &ps) );

			SRECT rect;
			rect.xmin = ps.rcPaint.left;
			rect.ymin = ps.rcPaint.top;
			rect.xmax = ps.rcPaint.right;
			rect.ymax = ps.rcPaint.bottom;
			FLASHOUTPUT( "Repaint Rect (%d,%d)--(%d,%d)\n", rect.xmin, rect.ymin, rect.xmax, rect.ymax );

			flashWin->Repaint( &rect );

			flashWin->SetDC( 0 );
			EndPaint(hWnd, &ps);
			return 0;
		case WM_SIZE:
			flashWin->FreeBuffer();
			break;
//***********************************************************
		case WM_MOUSEMOVE:
			{
				int fwKeys = wParam;        // key flags 
				int xPos = LOWORD(lParam);  // horizontal position of cursor 
				int yPos = HIWORD(lParam);  // vertical position of cursor 

				flashWin->SetDC( GetDC( hWnd ) );			// the mouse sometimes causes a draw
				flashWin->MouseMove( xPos, yPos, fwKeys & MK_LBUTTON );
				ReleaseDC( hWnd, flashWin->GetNWindowDC() );
				flashWin->SetDC( 0 );
			}
			break; 						

		case WM_LBUTTONDOWN:
			{
				int xPos = LOWORD(lParam);  // horizontal position of cursor 
				int yPos = HIWORD(lParam);  // vertical position of cursor 

				SetCapture( hWnd );

				flashWin->SetDC( GetDC( hWnd ) );			// the mouse sometimes causes a draw
				flashWin->MouseDown( xPos, yPos );
				ReleaseDC( hWnd, flashWin->GetNWindowDC() );
				flashWin->SetDC( 0 );
			}
			break; 						
 
		case WM_LBUTTONUP:
			{
				int xPos = LOWORD(lParam);  // horizontal position of cursor 
				int yPos = HIWORD(lParam);  // vertical position of cursor 
				ReleaseCapture();

				flashWin->SetDC( GetDC( hWnd ) );			// the mouse sometimes causes a draw
				flashWin->MouseUp( xPos, yPos );
				ReleaseDC( hWnd, flashWin->GetNWindowDC() );
				flashWin->SetDC( 0 );
			}
			break; 						
//**********************************************************
		case WM_DESTROY:
			CommandBar_Destroy(hwndCB);
			PostQuitMessage(0);
			delete flashWin;
			flashWin = 0;
			break;
		case WM_TIMER:
			flashWin->SetDC( GetDC( hWnd ) );			// the mouse sometimes causes a draw

			wmId = wParam;             // timer identifier 
			if ( wmId == TIMER_PLAY )
				flashWin->PlayTimerFire();
			else if ( wmId == TIMER_CURSOR )
				flashWin->CursorTimerFire();
			else
				FLASHASSERT( 0 );

			ReleaseDC( hWnd, flashWin->GetNWindowDC() );
			flashWin->SetDC( 0 );			// the mouse sometimes causes a draw
			break;

		case WM_PALETTECHANGED:
		    if ( HWND( wParam ) == hWnd )
				break;

		// FALL THROUGH

		case WM_QUERYNEWPALETTE:
			{
				FLASHOUTPUT( "QueryNewPalette\n" );
				HPALETTE hPalIdeal = NativePalette::CreateIdentityPalette( hWnd );
				if ( hPalIdeal ) {
					HDC hDC = GetDC(hWnd);

					// Realize our ideal palette to be sure all the colors are used in the device palette
					HPALETTE hOldPal = SelectPalette(hDC, hPalIdeal, FALSE);
					int result = RealizePalette(hDC);

					// Restore the old palette
					SelectPalette(hDC, hOldPal, TRUE);
// 					RealizePalette(hDC);
					
					ReleaseDC(hWnd, hDC);
					DeleteObject(hPalIdeal);

					if ( result )
					{
						flashWin->FreeBuffer();
					}
				}
			}
			return 0;

		case MSG_STREAM_NEW:
			{
				ThreadData* data = (ThreadData*) wParam;
				flashWin->StreamInNew( &data->streamData, data->url, (void*) lParam );
			}
			break;

		case MSG_STREAM_WRITE:
			{
				ThreadData* data = (ThreadData*) wParam;
				WriteBlock* write = (WriteBlock*) lParam;

				flashWin->StreamInWrite( &data->streamData, write->data, write->size );
				delete ( write );
			}
			break;

		case MSG_STREAM_DESTROY:
			{
				ThreadData* data = (ThreadData*) wParam;

				flashWin->StreamInDestroy( &data->streamData );
				FreeStr( data->url );
				delete ( data );
			}
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}



//***********************************************************************************

NativePlayerWnd::NativePlayerWnd()
{
	currentURL = CreateStr( "" );
	hwnd = 0;
}

NativePlayerWnd::~NativePlayerWnd()
{
	ClearScript();
	delete currentURL;
}

void NativePlayerWnd::initialize( HWND _hwnd )
{
	hwnd = _hwnd;

	cursorArrow		= LoadCursor( NULL, IDC_ARROW );
	cursorHand		= LoadCursor( hInst, MAKEINTRESOURCE(FID_HAND) );
	cursorButton	= LoadCursor( hInst, MAKEINTRESOURCE(FID_BUTTON) );
	cursorBeam		= LoadCursor( NULL, IDC_IBEAM );
}

void NativePlayerWnd::PlayTimerFire()
{
	DoPlay( true );
}

⌨️ 快捷键说明

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