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

📄 platform_win32.c

📁 大名鼎鼎的CE下播放软件,TCPPMP的源代码!!!2410下可以流畅的解QVGA的H264,MPEG4等格式.
💻 C
📖 第 1 页 / 共 3 页
字号:
#endif
	MessageBox(NULL,TExp,TFile,MB_OK);
}

void* BrushCreate(rgbval_t Color) { return CreateSolidBrush(Color); }
void BrushDelete(void* Handle) { if (Handle) DeleteObject((HGDIOBJ)Handle); }
void WinFill(void* DC,rect* Rect,rect* Exclude,void* Brush)
{
	RECT r;
	if (Exclude)
		ExcludeClipRect(DC,Exclude->x,Exclude->y,Exclude->x + Exclude->Width,Exclude->y + Exclude->Height);

	r.left = Rect->x;
	r.top = Rect->y;
	r.right = Rect->x + Rect->Width;
	r.bottom = Rect->y + Rect->Height;

	FillRect(DC,&r,(HBRUSH)Brush);
}

void ShowMessage(const tchar_t* Title,const tchar_t* Msg,...)
{
	bool_t Wait = WaitCursor;
	tchar_t s[1024];
	va_list Args;
	va_start(Args,Msg);
	vstprintf_s(s,TSIZEOF(s),Msg,Args);
	va_end(Args);
	if (Wait) WaitEnd();
	MessageBox(NULL,s,Title,MB_OK|MB_SETFOREGROUND|MB_TOPMOST);
	if (Wait) WaitBegin();
}

void DebugMessage(const tchar_t* Msg,...)
{
	va_list Args;
	tchar_t s[1024];

#ifndef NDEBUG
	if (!Debug)	
		Debug = StreamOpen(T("\\debug.txt"),1);
#else
	if (!Debug)
	{
		GetDebugPath(s,TSIZEOF(s),T("log.txt"));
		Debug = StreamOpen(s,1);
	}
#endif

	s[0]=0;

#if 0
//#ifdef NDEBUG
	{
		//SYSTEMTIME t;
		//GetSystemTime(&t);
		//stprintf(s+tcslen(s), T("%02d:%02d:%02d "),t.wHour,t.wMinute,t.wSecond);
		int min,sec;
		int t = GetTickCount();
		min = t / 60000;
		t -= min*60000;
		sec = t / 1000;
		t -= sec*1000;
		stcatprintf_s(s,TSIZEOF(s),T("%02d:%02d.%03d "),min,sec,t);
	}
#endif

#ifndef NDEBUG
//	stprintf_s(s,TSIZEOF(s),T("%04x "),(int)GetCurrentThreadId());
#endif
	va_start(Args,Msg);
	vstprintf_s(s+tcslen(s),TSIZEOF(s)-tcslen(s), Msg, Args);
	va_end(Args);
	tcscat_s(s,TSIZEOF(s),T("\n"));

#ifndef NDEBUG
	OutputDebugString(s);
#endif
	StreamPrintf(Debug,T("%s"),s);
}

typedef struct contextreg
{
	int Ofs;
	const tchar_t* Name;
} contextreg;

#if defined(_M_IX86)
static contextreg Reg[] = 
{
	OFS(CONTEXT,Eax), T("eax"),
	OFS(CONTEXT,Ebx), T("ebx"),
	OFS(CONTEXT,Ecx), T("ecx"),
	OFS(CONTEXT,Edx), T("edx"),
	OFS(CONTEXT,Esi), T("esi"),
	OFS(CONTEXT,Edi), T("edi"),
	OFS(CONTEXT,Ebp), T("ebp"),
	OFS(CONTEXT,Esp), T("esp"),
	OFS(CONTEXT,Eip), T("eip"),
	OFS(CONTEXT,EFlags), T("flags"),

	OFS(CONTEXT,Esp), NULL, 
};
#elif defined(MIPS)
static contextreg Reg[] = 
{
	OFS(CONTEXT,IntZero), T("Zero"),
	OFS(CONTEXT,IntAt), T("At"),
	OFS(CONTEXT,IntV0), T("V0"),
	OFS(CONTEXT,IntV1), T("V1"),
	OFS(CONTEXT,IntA0), T("A0"),
	OFS(CONTEXT,IntA1), T("A1"),
	OFS(CONTEXT,IntA2), T("A2"),
	OFS(CONTEXT,IntA3), T("A3"),
	OFS(CONTEXT,IntT0), T("T0"),
	OFS(CONTEXT,IntT1), T("T1"),
	OFS(CONTEXT,IntT2), T("T2"),
	OFS(CONTEXT,IntT3), T("T3"),
	OFS(CONTEXT,IntT4), T("T4"),
	OFS(CONTEXT,IntT5), T("T5"),
	OFS(CONTEXT,IntT6), T("T6"),
	OFS(CONTEXT,IntT7), T("T7"),
	OFS(CONTEXT,IntS0), T("S0"),
	OFS(CONTEXT,IntS1), T("S1"),
	OFS(CONTEXT,IntS2), T("S2"),
	OFS(CONTEXT,IntS3), T("S3"),
	OFS(CONTEXT,IntS4), T("S4"),
	OFS(CONTEXT,IntS5), T("S5"),
	OFS(CONTEXT,IntS6), T("S6"),
	OFS(CONTEXT,IntS7), T("S7"),
	OFS(CONTEXT,IntT8), T("T8"),
	OFS(CONTEXT,IntT9), T("T9"),
	OFS(CONTEXT,IntK0), T("K0"),
	OFS(CONTEXT,IntK1), T("K1"),
	OFS(CONTEXT,IntGp), T("Gp"),
	OFS(CONTEXT,IntSp), T("Sp"),
	OFS(CONTEXT,IntS8), T("S8"),
	OFS(CONTEXT,IntRa), T("Ra"),
	OFS(CONTEXT,IntLo), T("Lo"),
	OFS(CONTEXT,IntHi), T("Hi"),
	OFS(CONTEXT,IntSp), NULL,
};
#elif defined(ARM)
static contextreg Reg[] = 
{
	OFS(CONTEXT,R0), T("R0"),
	OFS(CONTEXT,R1), T("R1"),
	OFS(CONTEXT,R2), T("R2"),
	OFS(CONTEXT,R3), T("R3"),
	OFS(CONTEXT,R4), T("R4"),
	OFS(CONTEXT,R5), T("R5"),
	OFS(CONTEXT,R6), T("R6"),
	OFS(CONTEXT,R7), T("R7"),
	OFS(CONTEXT,R8), T("R8"),
	OFS(CONTEXT,R9), T("R9"),
	OFS(CONTEXT,R10),T("R10"),
	OFS(CONTEXT,R11),T("R11"),
	OFS(CONTEXT,R12),T("R12"),
	OFS(CONTEXT,Sp), T("Sp"),
	OFS(CONTEXT,Lr), T("Lr"),
	OFS(CONTEXT,Pc), T("Pc"),
	OFS(CONTEXT,Psr),T("Psr"),
	OFS(CONTEXT,Sp), NULL,
};
#elif defined(SH3)
static contextreg Reg[] = 
{
	OFS(CONTEXT,PR), T("PR"),
	OFS(CONTEXT,MACH), T("MACH"),
	OFS(CONTEXT,MACL), T("MACL"),
	OFS(CONTEXT,GBR), T("GBR"),
	OFS(CONTEXT,R0), T("R0"),
	OFS(CONTEXT,R1), T("R1"),
	OFS(CONTEXT,R2), T("R2"),
	OFS(CONTEXT,R3), T("R3"),
	OFS(CONTEXT,R4), T("R4"),
	OFS(CONTEXT,R5), T("R5"),
	OFS(CONTEXT,R6), T("R6"),
	OFS(CONTEXT,R7), T("R7"),
	OFS(CONTEXT,R8), T("R8"),
	OFS(CONTEXT,R9), T("R9"),
	OFS(CONTEXT,R10), T("R10"),
	OFS(CONTEXT,R11), T("R11"),
	OFS(CONTEXT,R12), T("R12"),
	OFS(CONTEXT,R13), T("R13"),
	OFS(CONTEXT,R14), T("R14"),
	OFS(CONTEXT,R15), T("R15"),
	OFS(CONTEXT,R15), NULL,
};
#else
static contextreg Reg[] = { -1, NULL };
#endif

void FindFiles(const tchar_t* Path, const tchar_t* Mask,void(*Process)(const tchar_t*,void*),void* Param)
{
	WIN32_FIND_DATA FindData;
	tchar_t FindPath[MAXPATH];
	HANDLE Find;

	tcscpy_s(FindPath,TSIZEOF(FindPath),Path);
	tcscat_s(FindPath,TSIZEOF(FindPath),Mask);
	Find = FindFirstFile(FindPath,&FindData);

	if (Find != INVALID_HANDLE_VALUE)
	{
		do
		{
			tcscpy_s(FindPath,TSIZEOF(FindPath),Path);
			tcscat_s(FindPath,TSIZEOF(FindPath),FindData.cFileName);
			Process(FindPath,Param);
		}
		while (FindNextFile(Find,&FindData));

		FindClose(Find);
	}
}

void GetModulePath(tchar_t* Path,const tchar_t* Module)
{
	tchar_t* s;
	HANDLE Handle = NULL;
	if (Module)
		Handle = GetModuleHandle(Module);
	GetModuleFileName(Handle,Path,MAXPATH);
	s = tcsrchr(Path,'\\');
	if (s) s[1]=0;
}

void GetDebugPath(tchar_t* Path, int PathLen, const tchar_t* FileName)
{
	stprintf_s(Path,PathLen,T("%s\\%s"),DocumentPath,FileName);
}

void GetSystemPath(tchar_t* Path, int PathLen, const tchar_t* FileName)
{
	stprintf_s(Path,PathLen,T("%s\\%s"),SystemPath,FileName);
}

int64_t GetTimeDate()
{
	SYSTEMTIME t;
	GetSystemTime(&t);
	return (((t.wHour*100)+t.wMinute)*100+t.wSecond)*1000 +
		(int64_t)(((t.wYear*100)+t.wMonth)*100+t.wDay) * 1000000000;
}

bool_t SaveDocument(const tchar_t* Name, const tchar_t* Text,tchar_t* URL,int URLLen)
{
	stream* f;
	stprintf_s(URL,URLLen,T("%s\\%s.txt"),DocumentPath,Name);

	f = StreamOpen(URL,1);
	if (!f)
		return 0;

	StreamText(f,Text,0);
	StreamClose(f);
	return 1;
}

int SafeException(void* p)
{
	EXCEPTION_POINTERS* Data = (EXCEPTION_POINTERS*)p;
	stream* File;
	tchar_t Path[MAXPATH];

	if (Context())
	{
		GetDebugPath(Path,TSIZEOF(Path),T("crash.txt"));
		File = StreamOpen(Path,1);
		if (File)
		{
			void** Stack;
			contextreg* r;
			int No;
			const uint8_t* ContextRecord = (const uint8_t*) Data->ContextRecord;
			EXCEPTION_RECORD* Record = Data->ExceptionRecord;
			tchar_t* Name;
			int DllBase;
			tchar_t DllName[MAXPATH];

			StreamPrintf(File,T("%s %s crash report\n----------------------------\n"),
					Context()->ProgramName,Context()->ProgramVersion);

			switch (Record->ExceptionCode)
			{
			case STATUS_ACCESS_VIOLATION:		Name = T("Access violation"); break;
			case STATUS_BREAKPOINT:				Name = T("Breakpoint"); break;
			case STATUS_DATATYPE_MISALIGNMENT:	Name = T("Datatype misalignment"); break;
			case STATUS_ILLEGAL_INSTRUCTION:	Name = T("Illegal instruction"); break;
			case STATUS_INTEGER_DIVIDE_BY_ZERO: Name = T("Int divide by zero"); break;
			case STATUS_INTEGER_OVERFLOW:		Name = T("Int overflow"); break;
			case STATUS_PRIVILEGED_INSTRUCTION: Name = T("Priv instruction"); break;
			case STATUS_STACK_OVERFLOW:			Name = T("Stack overflow"); break;
			default:							Name = T("Unknown"); break;
			}

			if (!NodeLocatePtr(Record->ExceptionAddress,DllName,TSIZEOF(DllName),&DllBase))
			{
				DllName[0] = 0;
				DllBase = (int)Record->ExceptionAddress;
			}
			StreamPrintf(File,T("%s(%08x) at %08x (%s:%08x)"),Name,Record->ExceptionCode,Record->ExceptionAddress,DllName,DllBase);

			if (Record->ExceptionCode == STATUS_ACCESS_VIOLATION)
			{
				if (Record->ExceptionInformation[0])
					Name = T("Write to");
				else
					Name = T("Read from");
				StreamPrintf(File,T("\n%s %08x"),Name,Record->ExceptionInformation[1]);
				if (NodeLocatePtr((void*)Record->ExceptionInformation[1],DllName,TSIZEOF(DllName),&DllBase))
					StreamPrintf(File,T(" (%s:%08x)"),DllName,DllBase);
			}
			
			// context

			StreamPrintf(File,T("\n\ncpu dump:"));

			for (r=Reg;r->Name;++r)
			{
				void* Ptr = *(void**)(ContextRecord+r->Ofs);

				StreamPrintf(File,T("\n%-5s = %08x"),r->Name,Ptr);

				if (NodeLocatePtr(Ptr,DllName,TSIZEOF(DllName),&DllBase))
					StreamPrintf(File,T(" (%s:%08x)"),DllName,DllBase);
			}

			if (r->Ofs >= 0)
			{
				StreamPrintf(File,T("\n\nstack dump:"));

				Stack = *(void***)(ContextRecord+r->Ofs);
				for (No=0;No<256;++No,++Stack)
				{
					if (!IsBadReadPtr(Stack,sizeof(void*)))
					{
						void* Ptr = *Stack;

						StreamPrintf(File,T("\n%08x %08x"),Stack,Ptr);

						if (NodeLocatePtr(Ptr,DllName,TSIZEOF(DllName),&DllBase))
							StreamPrintf(File,T(" (%s:%08x)"),DllName,DllBase);
					}
					else
						StreamPrintf(File,T("\n%08x ????????"),Stack);
				}
			}

			StreamPrintf(File,T("\n\n"));
			TRY_BEGIN 
			{
				NodeBroadcast(NODE_CRASH,NULL,0);
			}
			TRY_END
			NodeDump(File);
			StreamClose(File);
		}

		MessageBox(NULL,LangStr(PLATFORM_ID,PLATFORM_CRASH_MESSAGE),
			LangStr(PLATFORM_ID,PLATFORM_CRASH_TITLE),MB_OK|MB_SETFOREGROUND|MB_TOPMOST|MB_ICONSTOP);
	}

	Mem_Done(); // use safevirtualfree (if done by OS, it could be buggy on O2 Atom)
	TerminateProcess(GetCurrentProcess(),1);
	return 1;
}

void TryInvalidate(HWND Wnd, RECT* r0)
{
	RECT r;

	if (IsWindowVisible(Wnd))
	{
		GetWindowRect(Wnd,&r);
		if (r0->left < r.right && r0->right > r.left &&
			r0->top < r.bottom && r0->bottom > r.top)
		{
			// window is visible and intersects with r0

			HWND Child;
			POINT o;
			o.x = o.y = 0;
			ClientToScreen(Wnd,&o);

			r.left = r0->left - o.x;
			r.right = r0->right - o.x;
			r.top = r0->top - o.y;
			r.bottom = r0->bottom - o.y;
			InvalidateRect(Wnd,&r,0);

			Child = GetWindow(Wnd,GW_CHILD);
			while (Child && IsWindow(Child))
			{
				TryInvalidate(Child,r0);
				Child = GetWindow(Child,GW_HWNDNEXT);
			}
		}
	}
}

BOOL CALLBACK EnumInvalidate(HWND Wnd, LPARAM lParam)
{
	TryInvalidate(Wnd,(RECT*)lParam);
	return 1;
}

void GlobalInvalidate(const rect* Rect)
{
	RECT r;
	r.left = Rect->x;
	r.top = Rect->y;
	r.right = r.left + Rect->Width;
	r.bottom = r.top + Rect->Height;

#if defined(TARGET_WINCE)
	if (FuncRedrawWindow) // doesn't work for mio558???
		FuncRedrawWindow(NULL,&r,NULL,0x0001|0x0080); //RDW_INVALIDATE|RDW_ALLCHILDREN
	else
		EnumWindows(EnumInvalidate,(LPARAM)&r);
#else
	RedrawWindow(NULL,&r,NULL,RDW_INVALIDATE|RDW_ALLCHILDREN);
#endif
}

void HotKeyToString(tchar_t* Out, size_t OutLen, int HotKey)
{
	int Id = 0;
	
	Out[0] = 0;
	if (HotKey)
	{
		bool_t Keep = (HotKey & HOTKEY_KEEP) != 0;
		if ((HotKey & HOTKEY_MASK) < 0xC1 || (HotKey & HOTKEY_MASK) > 0xCF)
		{
			if (HotKey & HOTKEY_WIN) { tcscat_s(Out,OutLen,LangStr(PLATFORM_ID,PLATFORM_KEY_WIN)); tcscat_s(Out,OutLen,T("+")); }
			if (HotKey & HOTKEY_SHIFT) { tcscat_s(Out,OutLen,LangStr(PLATFORM_ID,PLATFORM_KEY_SHIFT)); tcscat_s(Out,OutLen,T("+")); }
			if (HotKey & HOTKEY_CTRL) { tcscat_s(Out,OutLen,LangStr(PLATFORM_ID,PLATFORM_KEY_CTRL)); tcscat_s(Out,OutLen,T("+")); }
			if (HotKey & HOTKEY_ALT) { tcscat_s(Out,OutLen,LangStr(PLATFORM_ID,PLATFORM_KEY_ALT)); tcscat_s(Out,OutLen,T("+")); }
		}
		HotKey &= HOTKEY_MASK;

		if ((HotKey >= '0' && HotKey <= '9') ||
			(HotKey >= 'A' && HotKey <= 'Z'))
			stcatprintf_s(Out,OutLen,T("%c"),HotKey);
		else
		if (HotKey >= 0x70 && HotKey < 0x80)
			stcatprintf_s(Out,OutLen,T("F%d"),HotKey-0x70+1);
		else
		switch (HotKey)
		{
		case 0x86:
			Id = PLATFORM_KEY_ACTION;
			break;
		case VK_RETURN:
			Id = PLATFORM_KEY_ENTER;
			break;
		case VK_ESCAPE:
			Id = PLATFORM_KEY_ESCAPE;
			break;
		case VK_LEFT:
			Id = PLATFORM_KEY_LEFT;
			break;
		case VK_RIGHT:
			Id = PLATFORM_KEY_RIGHT;
			break;
		case VK_UP:
			Id = PLATFORM_KEY_UP;
			break;
		case VK_DOWN:
			Id = PLATFORM_KEY_DOWN;
			break;
		case VK_SPACE:
			Id = PLATFORM_KEY_SPACE;
			break;
		case 0xC1:
		case 0xC2:
		case 0xC3:
		case 0xC4:
		case 0xC5:
		case 0xC6:
		case 0xC7:
		case 0xC8:
		case 0xC9:
		case 0xCA:
		case 0xCB:
		case 0xCC:
		case 0xCD:
		case 0xCE:
		case 0xCF:
			stcatprintf_s(Out,OutLen,LangStr(PLATFORM_ID,PLATFORM_KEY_APP),HotKey-0xC0);
			break;
		case 0xB0:
			Id = PLATFORM_KEY_NEXT;
			break;
		case 0xB1:
			Id = PLATFORM_KEY_PREV;
			break;
		case 0xB2:
			Id = PLATFORM_KEY_STOP;
			break;
		case 0xB3:
			Id = PLATFORM_KEY_PLAY;
			break;
		default:
			stcatprintf_s(Out,OutLen,T("#%02X"),HotKey);
			break;
		}
		if (Id)
			tcscat_s(Out,OutLen,LangStr(PLATFORM_ID,Id));
		if (Keep) { tcscat_s(Out,OutLen,T("*")); }
	}
}

void WaitDisable(bool_t v)
{
	WaitCursorDisable = v;	
	if (v && WaitCursor)
		WaitEnd();
}

bool_t WaitBegin()
{
	//DEBUG_MSG(DEBUG_SYS,T("WaitBegin"));
	if (WaitCursorDisable)
		return 0;
	SetCursor(LoadCursor (NULL, IDC_WAIT));
	WaitCursor = 1;
	return 1;
}

void WaitEnd()
{
	//DEBUG_MSG(DEBUG_SYS,T("WaitEnd"));
	SetCursor(LoadCursor (NULL, IDC_ARROW));
	WaitCursor = 0;
}

bool_t CheckModule(const tchar_t* Name)
{
	DWORD RegType;
	DWORD RegSize;
	DWORD Disp;
	void* Module;
	tchar_t Path[MAXPATH];
	HKEY Key = NULL;

	if (!Name[0])
		return 0;

	RegSize = sizeof(Path);
	stprintf_s(Path,TSIZEOF(Path),T("SOFTWARE\\%s\\DLLPath"),Context()->ProgramName);
	if (RegCreateKeyEx(HKEY_ROOT, Path, 0, NULL, 0, KEY_READ|KEY_WRITE, NULL, &Key, &Disp) == ERROR_SUCCESS)
	{
		if (RegQueryValueEx(Key, Name, 0, &RegType, (PBYTE)Path, &RegSize) == ERROR_SUCCESS)
		{
			if (RegType==REG_SZ && FileExits(Path))
			{
				RegCloseKey(Key);
				return 1;
			}
			RegDeleteValue(Key,Name);
		}
	}

	Module = LoadLibrary(Name);
	if (Module)
	{
		if (Key)
		{
			GetModuleFileName(Module,Path,MAXPATH);
			RegSetValueEx(Key, Name, 0, REG_SZ, (PBYTE)Path, sizeof(tchar_t)*(tcslen(Path)+1));
			RegCloseKey(Key);
		}
		FreeLibrary(Module);
		return 1;
	}

	if (Key)	
		RegCloseKey(Key);
	return 0;
}

bool_t HaveDPad()
{
	return 1;
}

#endif

⌨️ 快捷键说明

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