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

📄 main.cpp

📁 一个用于智能手机的多媒体库适合S60 WinCE的跨平台开发库
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* *			GPAC - Multimedia Framework C SDK * *			Copyright (c) Jean Le Feuvre 2000-2005 *					All rights reserved * *  This file is part of GPAC / command-line client * *  GPAC is free software; you can redistribute it and/or modify *  it under the terms of the GNU Lesser General Public License as published by *  the Free Software Foundation; either version 2, or (at your option) *  any later version. *    *  GPAC is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU Lesser General Public License for more details. *    *  You should have received a copy of the GNU Lesser General Public *  License along with this library; see the file COPYING.  If not, write to *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  * *//*includes both terminal and od browser*/#include <gpac/terminal.h>#include <gpac/options.h>/*for initial setup*/#include <gpac/modules/service.h>#include <windows.h>#include <commdlg.h>#include <commctrl.h>#include <aygshell.h>#include "resource.h"#include <gx.h>#define WM_LOADTERM	WM_USER + 1#define STATE_TIMER_ID		20#define STATE_TIMER_DUR		1000Bool gf_file_dialog(HINSTANCE inst, HWND parent, char *url, const char *ext_list, GF_Config *cfg);void set_backlight_state(Bool disable);void refresh_recent_files();void do_layout(Bool notif_size);static HWND g_hwnd = NULL;static HWND g_hwnd_disp = NULL;static HWND g_hwnd_menu1 = NULL;static HWND g_hwnd_menu2 = NULL;static HWND g_hwnd_status = NULL;static HINSTANCE g_hinst = NULL;static Bool is_connected = 0;static Bool navigation_on = 0;static Bool playlist_navigation_on = 1;static u32 Duration;static Bool CanSeek = 0;static u32 Volume=100;static char the_url[GF_MAX_PATH] = "";static Bool NavigateTo = 0;static char the_next_url[GF_MAX_PATH];static GF_Terminal *term;static GF_User user;static u32 disp_w = 0;static u32 disp_h = 0;static u32 screen_w = 0;static u32 screen_h = 0;static u32 menu_h = 0;static u32 caption_h = 0;static Bool backlight_off = 0;static u32 prev_batt_bl, prev_ac_bl;static Bool show_status = 1;static Bool reset_status = 1;static u32 last_state_time = 0;static Bool loop = 0;static Bool full_screen = 0;static Bool use_3D_renderer = 0;static Bool ctrl_mod_down = 0;static Bool view_cpu = 0;static Bool menu_switched = 0;static Bool use_low_fps = 0;static Bool use_svg_prog = 0;void set_status(char *state){	if (show_status && g_hwnd_status) {		TCHAR wstate[1024];		CE_CharToWide(state, wstate);		SendMessage(g_hwnd_status, WM_SETTEXT, 0, (LPARAM) wstate);		last_state_time = GetTickCount();	}}void update_state_info(){	TCHAR wstate[1024];	Double FPS;	u32 time, m, s;	if (!show_status) return;	if (last_state_time) {		if (GetTickCount() > last_state_time + 1000) {			last_state_time = 0;			reset_status = 1;		}		else return;	}	if (!term) return;	if (!is_connected && reset_status) {		SendMessage(g_hwnd_status, WM_SETTEXT, 0, (LPARAM) TEXT("Ready") );		reset_status = 0;		return;	}	FPS = gf_term_get_framerate(term, 0);	time = gf_term_get_time_in_ms(term) / 1000;	m = time/60;	s = time - m*60;	if (view_cpu) {		GF_SystemRTInfo rti;		if (!gf_sys_get_rti(STATE_TIMER_DUR, &rti, 0)) return;		wsprintf(wstate, TEXT("T %02d:%02d : FPS %02.2f : CPU %02d"), m, s, FPS, rti.total_cpu_usage);	} else {		wsprintf(wstate, TEXT("T %02d:%02d : FPS %02.2f"), m, s, FPS);	}	SendMessage(g_hwnd_status, WM_SETTEXT, 0, (LPARAM) wstate);}static u32 prev_pos = 0;void cbk_on_progress(void *_title, u32 done, u32 total){	char szMsg[1024];	u32 pos = (u32) ((u64) done * 100)/total;	if (pos<prev_pos) prev_pos = 0;	if (pos!=prev_pos) {		prev_pos = pos;		sprintf(szMsg, "%s: (%02d/100)", _title ? (char *)_title : "", pos);		set_status(szMsg);	}}void set_full_screen(){	full_screen = !full_screen;	if (full_screen) {		do_layout(0);		gf_term_set_option(term, GF_OPT_FULLSCREEN, full_screen);	} else {		gf_term_set_option(term, GF_OPT_FULLSCREEN, full_screen);		do_layout(1);	}}Bool GPAC_EventProc(void *ptr, GF_Event *evt){	switch (evt->type) {	case GF_EVENT_DURATION:		Duration = (u32) (evt->duration.duration*1000);		CanSeek = evt->duration.can_seek;		break;	case GF_EVENT_MESSAGE:	{		if (!evt->message.message) return 0;		set_status((char *) evt->message.message);	}		break;	case GF_EVENT_PROGRESS:	{		char *szTitle = "";		if (evt->progress.progress_type==0) szTitle = "Buffer ";		else if (evt->progress.progress_type==1) szTitle = "Download ";		else if (evt->progress.progress_type==2) szTitle = "Import ";		cbk_on_progress(szTitle, evt->progress.done, evt->progress.total);	}		break;		case GF_EVENT_SIZE:		break;	case GF_EVENT_SCENE_SIZE:		do_layout(1);		break;	case GF_EVENT_CONNECT:		if (evt->connect.is_connected) {			is_connected = 1;			if (!backlight_off) set_backlight_state(1);			refresh_recent_files();			navigation_on = (gf_term_get_option(term, GF_OPT_NAVIGATION)==GF_NAVIGATE_NONE) ? 0 : 1;		} else {			navigation_on = 0;			is_connected = 0;			Duration = 0;		}		break;	case GF_EVENT_QUIT:		break;	case GF_EVENT_KEYDOWN:		switch (evt->key.key_code) {		case GF_KEY_ENTER:			if (full_screen) set_full_screen();			break;		case GF_KEY_1:			ctrl_mod_down = !ctrl_mod_down;			evt->key.key_code = GF_KEY_CONTROL;			evt->type = ctrl_mod_down ? GF_EVENT_KEYDOWN : GF_EVENT_KEYUP;			gf_term_user_event(term, evt);			break;		}		break;	case GF_EVENT_MOUSEDOUBLECLICK:		set_full_screen();		return 0;	}	return 0;}Bool LoadTerminal(){	/*by default use current dir*/	strcpy(the_url, ".");	g_hwnd_disp = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE , 0, 0, disp_w, disp_h, g_hwnd, NULL, g_hinst, NULL);	user.EventProc = GPAC_EventProc;	/*dummy in this case (global vars) but MUST be non-NULL*/	user.opaque = user.modules;	user.os_window_handler = g_hwnd_disp;	term = gf_term_new(&user);	if (!term) {		gf_modules_del(user.modules);		gf_cfg_del(user.config);		memset(&user, 0, sizeof(GF_User));		return 0;	}	const char *str = gf_cfg_get_key(user.config, "General", "StartupFile");	if (str) {		do_layout(1);		strcpy(the_url, str);		gf_term_connect(term, str);	}	return 1;}void do_layout(Bool notif_size){	u32 w, h;	if (full_screen) {		w = screen_w;		h = screen_h;		::ShowWindow(g_hwnd_status, SW_HIDE);		::ShowWindow(g_hwnd_menu1, SW_HIDE);		::ShowWindow(g_hwnd_menu2, SW_HIDE);		::MoveWindow(g_hwnd, 0, 0, screen_w, screen_h, 1);		::MoveWindow(g_hwnd_disp, 0, 0, screen_w, screen_h, 1);	} else {		::ShowWindow(g_hwnd_menu1, menu_switched ? SW_HIDE : SW_SHOW);		::ShowWindow(g_hwnd_menu2, menu_switched ? SW_SHOW : SW_HIDE);		if (show_status) {			::MoveWindow(g_hwnd, 0, caption_h, disp_w, disp_h, 1);			::ShowWindow(g_hwnd_status, SW_SHOW);			::MoveWindow(g_hwnd_status, 0, 0, disp_w, caption_h-2, 1);			::MoveWindow(g_hwnd_disp, 0, caption_h, disp_w, disp_h - caption_h, 1);			w = disp_w;			h = disp_h - caption_h;		} else {			::ShowWindow(g_hwnd_status, SW_HIDE);			::MoveWindow(g_hwnd, 0, caption_h, disp_w, disp_h, 1);			::MoveWindow(g_hwnd_disp, 0, 0, disp_w, disp_h, 1);			w = disp_w;			h = disp_h;		}	}	if (notif_size && term) gf_term_set_size(term, w, h);}void set_backlight_state(Bool disable) {	HKEY hKey = 0;	DWORD dwSize;	DWORD dwValue;	HANDLE hBL;	if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("ControlPanel\\Backlight"), 0, 0, &hKey ) != ERROR_SUCCESS) return;	if (disable) {		dwSize = 4;		RegQueryValueEx(hKey, _T("BatteryTimeout"), NULL, NULL,(unsigned char*) &prev_batt_bl, &dwSize);		dwSize = 4;		RegQueryValueEx(hKey, _T("ACTimeout"), NULL, NULL, (unsigned char*) &prev_ac_bl,&dwSize);		dwSize = 4;		dwValue = 0xefff ;		RegSetValueEx(hKey, _T("BatteryTimeout"), NULL, REG_DWORD, (unsigned char *)&dwValue, dwSize);		dwSize = 4;		dwValue = 0xefff ;		RegSetValueEx( hKey, _T("ACTimeout"), NULL, REG_DWORD, (unsigned char *)&dwValue, dwSize);		backlight_off = 1;	} else {		if (prev_batt_bl) {			dwSize = 4;			RegSetValueEx(hKey, _T("BatteryTimeout"), NULL, REG_DWORD, (unsigned char *)&prev_batt_bl, dwSize);		}		if (prev_ac_bl) {			dwSize = 4;			RegSetValueEx(hKey, _T("ACTimeout"), NULL, REG_DWORD,(unsigned char *)&prev_ac_bl, dwSize);		}		backlight_off = 0;	}	RegCloseKey(hKey);	hBL = CreateEvent(NULL, FALSE, FALSE, _T("BackLightChangeEvent"));	if (hBL) {		SetEvent(hBL);		CloseHandle(hBL);	}}static Bool do_resume = 0;static Bool prev_backlight_state;void freeze_display(Bool do_freeze){	if (do_freeze) {		prev_backlight_state = backlight_off;		do_resume = 0;		if (0 && is_connected && gf_term_get_option(term, GF_OPT_PLAY_STATE)==GF_STATE_PLAYING) {			do_resume= 1;			gf_term_set_option(term, GF_OPT_PLAY_STATE, GF_STATE_PAUSED);		}		/*freeze display*/		gf_term_set_option(term, GF_OPT_FREEZE_DISPLAY, 1);		set_backlight_state(0);		gf_sleep(100);	} else {		if (prev_backlight_state) set_backlight_state(1);		gf_term_set_option(term, GF_OPT_FREEZE_DISPLAY, 0);		if (do_resume) {			gf_term_set_option(term, GF_OPT_PLAY_STATE, GF_STATE_PLAYING);			set_backlight_state(1);		}		}}void do_open_file(){	gf_cfg_set_key(user.config, "RecentFiles", the_url, NULL);	gf_cfg_insert_key(user.config, "RecentFiles", the_url, "", 0);	u32 count = gf_cfg_get_key_count(user.config, "RecentFiles");	if (count > 10) gf_cfg_set_key(user.config, "RecentFiles", gf_cfg_get_key_name(user.config, "RecentFiles", count-1), NULL);	gf_term_connect(term, the_url);}void refresh_recent_files(){	u32 count = gf_cfg_get_key_count(user.config, "RecentFiles");    HMENU hMenu = (HMENU)SendMessage(g_hwnd_menu1, SHCMBM_GETSUBMENU, 0, ID_MENU_FILE);	/*pos is hardcoded*/	hMenu = GetSubMenu(hMenu, 2);	while (RemoveMenu(hMenu, 0, MF_BYPOSITION)) {}	for (u32 i=0; i<count; i++) {		TCHAR txt[100];		char *name;		const char *sOpt = gf_cfg_get_key_name(user.config, "RecentFiles", i);		name = strrchr(sOpt, '\\');		if (!name) name = strrchr(sOpt, '/');		if (!name) name = (char *) sOpt;		else name += 1;		CE_CharToWide(name, txt);		AppendMenu(hMenu, MF_STRING, IDM_OPEN_FILE1+i, txt);	}}void switch_playlist(Bool play_prev){	char szPLE[20];	u32 idx = 0;	u32 count;	const char *ple = gf_cfg_get_key(user.config, "General", "PLEntry");	if (ple) idx = atoi(ple);		count = gf_cfg_get_key_count(user.config, "Playlist");	if (!count) return;	/*not the first launch*/	if (strlen(the_url)) {		if (!idx && play_prev) return;		if (play_prev) idx--;		else idx++;		if (idx>=count) return;	} else {		if (idx>=count) idx=0;	}	ple = gf_cfg_get_key_name(user.config, "Playlist", idx);	if (!ple) return;	sprintf(szPLE, "%d", idx);	gf_cfg_set_key(user.config, "General", "PLEntry", szPLE);	strcpy(the_url, ple);	do_open_file();}void open_file(HWND hwnd){	Bool res;	char ext_list[4096];	strcpy(ext_list, "");	freeze_display(1);	u32 count = gf_cfg_get_key_count(user.config, "MimeTypes");	for (u32 i=0; i<count; i++) {		char szKeyList[1000], *sKey;		const char *sMime = gf_cfg_get_key_name(user.config, "MimeTypes", i);		const char *opt = gf_cfg_get_key(user.config, "MimeTypes", sMime);		strcpy(szKeyList, opt+1);		sKey = strrchr(szKeyList, '\"');		if (!sKey) continue;		sKey[0] = 0;		strcat(ext_list, szKeyList);		strcat(ext_list, " ");	}	res = gf_file_dialog(g_hinst, hwnd, the_url, ext_list, user.config);	freeze_display(0);	/*let's go*/	if (res) do_open_file();}void load_recent_file(u32 idx){	const char *sOpt = gf_cfg_get_key_name(user.config, "RecentFiles", idx);	if (sOpt) {		strcpy(the_url, sOpt);		do_open_file();	}}BOOL CALLBACK AboutDialogProc(const HWND hWnd, const UINT Msg, const WPARAM wParam, const LPARAM lParam) {	BOOL ret = TRUE;    switch (Msg) {    case WM_INITDIALOG:	{	    TCHAR           psz[80];		ZeroMemory(psz, sizeof(psz));		SHINITDLGINFO sid;		ZeroMemory(&sid, sizeof(sid));		sid.dwMask  = SHIDIM_FLAGS;		sid.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;		sid.hDlg    = hWnd;		SHInitDialog(&sid);		SHMENUBARINFO mbi;		memset(&mbi, 0, sizeof(SHMENUBARINFO));		mbi.cbSize = sizeof(SHMENUBARINFO);		mbi.hwndParent = hWnd;		mbi.nToolBarId = IDR_ABOUT_MENU;		mbi.hInstRes = g_hinst;		mbi.nBmpId = 0;		mbi.cBmpImages = 0;			SHCreateMenuBar(&mbi);	}        break;    case WM_COMMAND:    case WM_CLOSE:		EndDialog(hWnd, 0);		break;	default:		ret = FALSE;	}	return ret;}void view_about(HWND hwnd){	freeze_display(1);//	::ShowWindow(g_hwnd_mb, SW_HIDE);	int iResult = DialogBox(g_hinst, MAKEINTRESOURCE(IDD_APPABOUT), hwnd,(DLGPROC)AboutDialogProc);//	::ShowWindow(g_hwnd_mb, SW_SHOW);	freeze_display(0);}void reload_terminal(){	HCURSOR hcur = SetCursor(LoadCursor(NULL, IDC_WAIT));	gf_term_del(term);	term = gf_term_new(&user);	if (!term) {		MessageBox(NULL, _T("Fatal Error !!"), _T("Couldn't change renderer"), MB_OK);		PostQuitMessage(0);	} else {		const char *str = gf_cfg_get_key(user.config, "Rendering", "RendererName");

⌨️ 快捷键说明

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