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

📄 ebflashplayer.c

📁 基于minigui开发的一套图形控件系统
💻 C
📖 第 1 页 / 共 2 页
字号:
				}
				
				TimerUpCome(hWnd, pEBFlashData);
			}
			break;
		case FLP_PLAYFILE:
			if(pEBFlashData && !pEBFlashData->CreateOK)
			{
				//pEBFlashData->CreateOK = 1;
				pAddData = (FLASHPLAYERADDDATA *)(pEBFlashData->data);
				pAddData->url = (char*)wParam;
				pAddData->IsSound = lParam;
				SRZ_PRINT("IsSound(%d),url: %s\n", pAddData->IsSound, pAddData->url);
				ebFlashInit(hWnd, pEBFlashData, pAddData->url, pAddData->IsSound);
			}
			break;
		case FLP_PAUSEFILE:
			if(pEBFlashData && pEBFlashData->CreateOK)
			{
				if(pEBFlashData->IsPause == 0)
				{
					SRZ_PRINT("+pause ? %d\n", pEBFlashData->IsPause);
					cmd = FLASH_STOP;
					pEBFlashData->IsPause = 1;
				}
				else
				{
					SRZ_PRINT("-pause ? %d\n", pEBFlashData->IsPause);
					cmd = FLASH_CONT;
					pEBFlashData->IsPause = 0;
				}
				wakeUp = FlashExec(pEBFlashData->flashHandle, cmd, 0, &wd);
			}
			break;
		case FLP_REWINDFILE:
			if(pEBFlashData && pEBFlashData->CreateOK)
			{
				cmd = FLASH_REWIND;
				wakeUp = FlashExec(pEBFlashData->flashHandle, cmd, 0, &wd);
			}
			break;
		case FLP_STOPFILE:
			if(pEBFlashData && pEBFlashData->CreateOK)
			{
				ebFlashFinish(hWnd,pEBFlashData);
			}
			break;

        case MSG_KEYDOWN:
        	if(pEBFlashData && pEBFlashData->CreateOK)
        	{
				if(wParam == SCANCODE_ENTER)
				{
					cmd = FLASH_EVENT;
					fe.key = FeKeyEnter;
				
					wakeUp = FlashExec(pEBFlashData->flashHandle, cmd, &fe, &wd);
				}
			}
			break;

#if 0
		case MSG_CHAR:
			SRZ_PRINT("char = %c  %d\n", (char)wParam, (int)wParam);
			if(!pEBFlashData)
				break;
				
			switch ((int)wParam)
			{
				case 10: //Enter
					cmd = FLASH_EVENT;
					fe.key = FeKeyEnter;
					break;
			}
			wakeUp = FlashExec(pEBFlashData->flashHandle, cmd, &fe, &wd);
			break;
#endif

		case MSG_LBUTTONDOWN:
			if(pEBFlashData && pEBFlashData->CreateOK)
			{
				fe.type = FeButtonPress;
				FlashExec(pEBFlashData->flashHandle, FLASH_EVENT, &fe, &wd);
			}
		    break;

		case MSG_LBUTTONUP:
			if(pEBFlashData && pEBFlashData->CreateOK)
			{
				fe.type = FeButtonRelease;
				FlashExec(pEBFlashData->flashHandle, FLASH_EVENT, &fe, &wd);
			}
		    break;

		case MSG_MOUSEMOVE:
			if(pEBFlashData && pEBFlashData->CreateOK)
			{
				fe.type = FeMouseMove;
				fe.x = LOWORD (lParam);
				fe.y = HIWORD (lParam);
				FlashExec(pEBFlashData->flashHandle, FLASH_EVENT, &fe, &wd);
			}
		    break;

		case MSG_DESTROY:
			if(pEBFlashData)
			{
				ebFlashFinish(hWnd,pEBFlashData);
				free(pEBFlashData);
			}
			return 0;
		default:
			break;
	}

    return DefaultControlProc(hWnd, message, wParam, lParam);
}

static int readFile(char *filename, char **buffer, int *size, int mode)
{
	FILE          * in;
	unsigned char * buf, *tmpbuff;
	long            org_length, actrual_length;
	unsigned char   fileHdr[8];

	if(mode == SWFReadByFile)
	{
		in = fopen(filename,"r");
		if(in == 0)
		{
			perror(filename);
			return -1;
		}
		if(fread(fileHdr, 1, 8, in) != 8)
		{
			SRZ_PRINT("read file error!\n");
			fclose(in);
			return -1;
		}
		fseek(in, 0, SEEK_END);
		org_length = ftell(in);

		if((fileHdr[0] == 'F') && (fileHdr[1] == 'W') && (fileHdr[2] == 'S'))
		{
			buf = (unsigned char *)malloc(org_length);

			rewind(in);
			fread(buf, org_length, 1, in);
			actrual_length = org_length;
		}
		else if((fileHdr[0] == 'C') && (fileHdr[1] == 'W') && (fileHdr[2] == 'S'))
		{
			z_stream        stream;
			int             z_status;
			unsigned char * outbuff;

			actrual_length = (unsigned int) fileHdr[4] |
							((unsigned int) fileHdr[5] << 8) |
							((unsigned int) fileHdr[6] << 16) |
							((unsigned int) fileHdr[7] << 24);

			tmpbuff = (unsigned char *)malloc(org_length);
			buf = (unsigned char *)malloc(actrual_length);
			fseek(in, 8L, SEEK_SET);
			fread(tmpbuff, org_length - 8, 1, in);

			memcpy(buf, fileHdr, 8);
			outbuff = &buf[8];

			stream.next_in = tmpbuff;
			stream.avail_in = 1;
			stream.zalloc = Z_NULL;
			stream.zfree = Z_NULL;
			stream.next_out = outbuff;
			stream.avail_out = actrual_length - 8;

			inflateInit(&stream);

			while(1)
			{
				z_status = inflate(&stream, Z_SYNC_FLUSH) ;
				if(z_status == Z_STREAM_END)
				{
					break;
				}
				if(z_status != Z_OK)
				{
					SRZ_PRINT("Zlib data error : %s\n", stream.msg);
					free(buf);
					free(tmpbuff);
					fclose(in);
					return -1;
				}
				stream.avail_in = 1;
			}
			inflateEnd(&stream);
			free(tmpbuff);
		}
		else
		{
			SRZ_PRINT("File format(%c%c%c) is not supported!\n", fileHdr[2], fileHdr[1], fileHdr[0]);
			fclose(in);
			return -1;
		}

		fclose(in);

		*size = actrual_length;
		*buffer = (char *)buf;
		return actrual_length;
	}
	else if(mode == SWFReadByBuffer)
	{
		if(*size == 0) return -1;
		memcpy((char *)&fileHdr, *buffer, 8);

		org_length = *size;
		if((fileHdr[0] == 'F') && (fileHdr[1] == 'W') && (fileHdr[2] == 'S'))
		{
			actrual_length = *size;
			return actrual_length;
		}
		else if((fileHdr[0] == 'C') && (fileHdr[1] == 'W') && (fileHdr[2] == 'S'))
		{
			z_stream        stream;
			int             z_status;
			unsigned char * outbuff;

			actrual_length = (unsigned int) fileHdr[4] |
							((unsigned int) fileHdr[5] << 8) |
							((unsigned int) fileHdr[6] << 16) |
							((unsigned int) fileHdr[7] << 24);

			tmpbuff = (unsigned char *)malloc(org_length);
			buf = (unsigned char *)malloc(actrual_length);

			memcpy(tmpbuff, *buffer + 8, org_length - 8);
			free(*buffer);

			memcpy(buf, fileHdr, 8);
			outbuff = &buf[8];

			stream.next_in = tmpbuff;
			stream.avail_in = 1;
			stream.zalloc = Z_NULL;
			stream.zfree = Z_NULL;
			stream.next_out = outbuff;
			stream.avail_out = actrual_length - 8;

			inflateInit(&stream);

			while(1)
			{
				z_status = inflate(&stream, Z_SYNC_FLUSH) ;
				if(z_status == Z_STREAM_END)
				{
					break;
				}
				if(z_status != Z_OK)
				{
					SRZ_PRINT("Zlib data error : %s\n", stream.msg);
					free(buf);
					free(tmpbuff);
					fclose(in);
					return -1;
				}
				stream.avail_in = 1;
			}
			inflateEnd(&stream);
			free(tmpbuff);
		}
		else
		{
			SRZ_PRINT("File format(%c%c%c) is not supported!\n", fileHdr[2], fileHdr[1], fileHdr[0]);
			return -1;
		}

		*size = actrual_length;
		*buffer = (char *)buf;
		return actrual_length;
	}
}

static long FlashGraphicInitMg(FlashHandle fh, HWND hWnd)
{
	HDC         hdc;
	BITMAP *    bmp;
	RECT        rc;
	int pitch;

	hdc = GetClientDC(hWnd);
	bmp = (BITMAP*)malloc(sizeof(BITMAP));
	memset(bmp, 0, sizeof(bmp));
	bmp->bmBits = NULL;
	GetClientRect(hWnd, &rc);
	GetBitmapFromDC (hdc,  rc.left,  rc.top,  rc.right-rc.left,  rc.bottom-rc.top, bmp);
	//xc->fd.pixels = LockDC(HDC_SCREEN,NULL,&(xc->fd.width),&(xc->fd.height),&bmp->bmPitch);
	
	//bmp->bmBits = xc->fd.pixels ;
	xc->fd.pixels = (char*)bmp->bmBits;
    	xc->fd.width = bmp->bmWidth;
	xc->fd.height = bmp->bmHeight;
	
	/*bmp->bmType = BMP_TYPE_NORMAL;
	bmp->bmBytesPerPixel = 4;
	bmp->bmAlphaPixelFormat = NULL;
	bmp->bmWidth = xc->fd.width;
	bmp->bmHeight = xc->fd.height;*/
	
	xc->fd.bpl = bmp->bmPitch;
	xc->fd.depth = bmp->bmBitsPerPixel;
	xc->hwnd = hWnd;
	xc->bmp = bmp;
	//UnlockDC(HDC_SCREEN);
	ReleaseDC(hdc);
	return FlashGraphicInit(fh, &xc->fd);
}

static void showUrl(char *url, char *target, void *client_data)
{
	SRZ_PRINT("GetURL : %s\n", url);
}

static void getSwf(char *url, int level, void *client_data)
{
	FlashHandle   fHandle;
	char        * buffer, * p;
	int           size;
	int           mode;
	int           result;

	fHandle = (FlashHandle) client_data;
	SRZ_PRINT("LoadMovie: %s @ %d\n", url, level);


	p = strstr(url, "http://");
	if((p != NULL) && (p == url))
	{
		buffer = NULL;
		size = 0;
		result = DownloadHttpFile(url, HTTP_METHOD_GET|HTTP_METHOD_WHOLE, &buffer, &size, NULL);
		if(result != HTTP_NO_ERROR || !buffer)
		{
			SRZ_PRINT("download file error!\n"); // to show error msg
			return;
		}
		mode = SWFReadByBuffer;
	}
	else
	{
		mode = SWFReadByFile;
	}

	if(readFile(url, &buffer, &size, mode) > 0)
	{
		FlashParse(fHandle, level, buffer, size);
	}
}


static int TimerUpCome(HWND hWnd, PFLASHPLAYERDATA2 pEBFlashplayerData2)
{
	struct timeval       wd;
	long                 cmd;
	long                 wakeUp = 0;
	int                  i;
	
	//SRZ_PRINT("\nTimerUpCome>>>timer_counter=%d,skip=%d",pEBFlashplayerData2->timer_counter,pEBFlashplayerData2->skip);
	while(pEBFlashplayerData2->timer_counter > 0)
	{
		if(pEBFlashplayerData2->CreateOK)
		{
			while(pEBFlashplayerData2->skip > 0)
			{
				cmd = FLASH_STEP;
				wakeUp = FlashExec(pEBFlashplayerData2->flashHandle, cmd, 0, &wd);
				pEBFlashplayerData2->skip--;
			}

			if(wakeUp)
			{
				cmd = FLASH_WAKEUP;
				wakeUp = FlashExec(pEBFlashplayerData2->flashHandle, cmd, 0, &wd);
				if(xc->fd.flash_refresh)
				{
					FlashCopyMg();
					xc->fd.flash_refresh = 0;
				}
			}

		}
		pEBFlashplayerData2->skip = pEBFlashplayerData2->timer_counter - 1;
		pEBFlashplayerData2->timer_counter = 0;

	}
	return 0;
}

⌨️ 快捷键说明

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