📄 shellload.cpp.bak
字号:
#include "PngAnimation.h"
#define MESSAGE_LAUNCH_PROGRAM (WM_APP+1)
#define MESSAGE_LAUNCHER_READY (WM_APP+211)
DWORD dwStart = 0;
DWORD dwCurrent = 0;
HANDLE hThreadEvent1 = NULL;
HANDLE hThreadEvent2 = NULL;
HANDLE hThreadEvent3 = NULL;
HANDLE hThreadEvent4 = NULL;
HANDLE hThreadEvent5 = NULL;
HANDLE hThreadEvent6 = NULL;
TCHAR tszClassName[] = TEXT("ImagingT");
DWORD g_dwMainThreadId;
static int g_indexHDC = 0;
static int g_indexPNG = 1;
static wchar_t pPngFileName[50] = {0};
LPCWSTR lpLauncherFileName = _T("\\SDMMC Card\\YiHeLauncher\\YiHeLauncher.exe");
LPCWSTR lpYiHeLoaderSound = DATA_PATH L"PowerOn\\On.wav";
HWND g_hWnd = NULL;
HINSTANCE g_hInst = NULL;
PCLASS_CPngAnimation pClsPngAnimation = NULL;
LRESULT CALLBACK WndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
BOOL OpenWindow(DWORD dwWidth, DWORD dwHeight, const TCHAR * tszName);
void LoadLauncher(void);
DWORD WINAPI Thread0Proc(PVOID lpParameter);
DWORD WINAPI Thread1Proc(PVOID lpParameter);
DWORD WINAPI Thread2Proc(PVOID lpParameter);
DWORD WINAPI Thread3Proc(PVOID lpParameter);
DWORD WINAPI Thread4Proc(PVOID lpParameter);
DWORD WINAPI Thread5Proc(PVOID lpParameter);
DWORD WINAPI Thread6Proc(PVOID lpParameter);
//DWORD WINAPI Thread7Proc(PVOID lpParameter);
//DWORD WINAPI Thread8Proc(PVOID lpParameter);
//DWORD WINAPI Thread9Proc(PVOID lpParameter);
//DWORD WINAPI Thread10Proc(PVOID lpParameter);
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
BOOL bRet = TRUE;
HANDLE hThread0 = NULL;
HANDLE hThread1 = NULL;
HANDLE hThread2 = NULL;
HANDLE hThread3 = NULL;
HANDLE hThread4 = NULL;
HANDLE hThread5 = NULL;
HANDLE hThread6 = NULL;
// HANDLE hThread7 = NULL;
// HANDLE hThread8 = NULL;
// HANDLE hThread9 = NULL;
// HANDLE hThread10 = NULL;
// HANDLE hThreadEvent0 = NULL;
g_hInst = hInstance;
g_dwMainThreadId = GetCurrentThreadId();
HKEY keyLoaderReg;
BYTE byRegValue[100];
DWORD dwRegLen = 100;
DWORD dwRegType;
// load launcher
// LoadLauncher();
pClsPngAnimation = new CPngAnimation;
OpenWindow(800, 270, _T("Splash"));
// load a wav as splash music
if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_USERS,_T("YIHE_SHELL_LOADER"),0,0,&keyLoaderReg))
{
if(ERROR_SUCCESS == RegQueryValueEx(keyLoaderReg,_T("sound"),NULL,&dwRegType,(LPBYTE)byRegValue,&dwRegLen))
{
lpYiHeLoaderSound = (LPCWSTR)byRegValue;
}
RegCloseKey(keyLoaderReg);
}
if(g_hWnd)
bRet = pClsPngAnimation->PngAnimationInit(g_hWnd);
if(!bRet)
{
pClsPngAnimation->PngAnimationDeinit();
return 0;
}
else
{
// hThread10 = CreateThread(NULL, 0, Thread10Proc, NULL, 0, NULL);
/// hThread9 = CreateThread(NULL, 0, Thread9Proc, NULL, 0, NULL);
// hThread8 = CreateThread(NULL, 0, Thread8Proc, NULL, 0, NULL);
// hThread7 = CreateThread(NULL, 0, Thread7Proc, NULL, 0, NULL);
hThread6 = CreateThread(NULL, 0, Thread6Proc, NULL, CREATE_SUSPENDED, NULL);
hThread5 = CreateThread(NULL, 0, Thread5Proc, NULL, CREATE_SUSPENDED, NULL);
hThread4= CreateThread(NULL, 0, Thread4Proc, NULL, CREATE_SUSPENDED, NULL);
hThread3 = CreateThread(NULL, 0, Thread3Proc, NULL, CREATE_SUSPENDED, NULL);
hThread2 = CreateThread(NULL, 0, Thread2Proc, NULL, CREATE_SUSPENDED, NULL);
hThread1 = CreateThread(NULL, 0, Thread1Proc, NULL, CREATE_SUSPENDED, NULL);
// hThread0 = CreateThread(NULL, 0, Thread0Proc, NULL, 0, NULL);
::SetThreadPriority(hThread1,100);
::SetThreadPriority(hThread2,110);
::SetThreadPriority(hThread3,120);
::SetThreadPriority(hThread4,130);
::SetThreadPriority(hThread5,140);
::SetThreadPriority(hThread6,150);
::ResumeThread(hThread1);
::ResumeThread(hThread2);
::ResumeThread(hThread3);
::ResumeThread(hThread4);
::ResumeThread(hThread5);
::ResumeThread(hThread6);
hThreadEvent1 = ::CreateEvent(NULL,FALSE,FALSE,NULL);
hThreadEvent2 = ::CreateEvent(NULL,FALSE,FALSE,NULL);
hThreadEvent3 = ::CreateEvent(NULL,FALSE,FALSE,NULL);
hThreadEvent4 = ::CreateEvent(NULL,FALSE,FALSE,NULL);
hThreadEvent5 = ::CreateEvent(NULL,FALSE,FALSE,NULL);
hThreadEvent6 = ::CreateEvent(NULL,FALSE,FALSE,NULL);
SetEvent(hThreadEvent6);
MSG msg;
while(1)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT)
{
if(hThread0)
{
CloseHandle(hThread0);
hThread0 = NULL;
}
if(hThread1)
{
CloseHandle(hThread1);
hThread1 = NULL;
}
if(hThread2)
{
CloseHandle(hThread2);
hThread2 = NULL;
}
if(hThread3)
{
CloseHandle(hThread3);
hThread3 = NULL;
}
if(hThread4)
{
CloseHandle(hThread4);
hThread4 = NULL;
}
if(hThread5)
{
CloseHandle(hThread5);
hThread5 = NULL;
}
if(hThread6)
{
CloseHandle(hThread6);
hThread6 = NULL;
}
// if(hThread7)
// {
// CloseHandle(hThread7);
// hThread7 = NULL;
// }
// if(hThread8)
// {
// CloseHandle(hThread8);
// hThread8 = NULL;
// }
// if(hThread9)
// {
// CloseHandle(hThread9);
// hThread9 = NULL;
// }
// if(hThread10)
// {
// CloseHandle(hThread10);
// hThread10 = NULL;
// }
//
if(hThreadEvent1)
{
CloseHandle(hThreadEvent1);
hThreadEvent1 = NULL;
}
if(hThreadEvent2)
{
CloseHandle(hThreadEvent2);
hThreadEvent2 = NULL;
}
if(hThreadEvent3)
{
CloseHandle(hThreadEvent3);
hThreadEvent3 = NULL;
}
if(hThreadEvent4)
{
CloseHandle(hThreadEvent4);
hThreadEvent4 = NULL;
}
if(hThreadEvent5)
{
CloseHandle(hThreadEvent5);
hThreadEvent5 = NULL;
}
if(hThreadEvent6)
{
CloseHandle(hThreadEvent6);
hThreadEvent6 = NULL;
}
pClsPngAnimation->PngAnimationDeinit();
delete pClsPngAnimation;
DestroyWindow(g_hWnd);
UnregisterClass(tszClassName, g_hInst);
return 0;
}
if(msg.message == MESSAGE_LAUNCH_PROGRAM)
{
info(TEXT("Get Message MESSAGE_LAUNCH_PROGRAM"));
Sleep(2000);
::sndPlaySound(NULL,SND_ASYNC);
::PostMessage(g_hWnd,WM_DESTROY,0,0);
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
return 0;
}
BOOL OpenWindow(DWORD dwWidth, DWORD dwHeight, const TCHAR * tszName)
{
WNDCLASS wc;
int x, y, width, height;
wc.style = 0;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = (HINSTANCE) g_hInst;
wc.hIcon = 0;
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = tszClassName;
RegisterClass(&wc);
x = 0;
y = 0;
width = dwWidth;
height =dwHeight;
g_hWnd = CreateWindowEx(
0,
tszClassName,
tszName,
/*WS_OVERLAPPED|WS_CAPTION|WS_BORDER|*/WS_VISIBLE/*|WS_SYSMENU*/,
x,
110,
width,
height,
NULL,
NULL,
(HINSTANCE) g_hInst,
NULL );
if( g_hWnd == NULL )
return FALSE;
ShowWindow( g_hWnd, SW_SHOWNORMAL );
UpdateWindow( g_hWnd );
info(TEXT("Main window created, x = %d, y=%d, width = %d, height = %d"),
x, y, width, height);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps; // used in WM_PAINT
HDC hdc;
RECT rc={0,0,800,480};
HBRUSH hBrush;
static BOOL bFlags = FALSE;
g_hWnd = hWnd;
switch(wMsg)
{
case WM_CREATE:
hdc = ::GetDC(NULL);
hBrush = ::CreateSolidBrush(RGB(0,16,57));
::FillRect(hdc,&rc,hBrush);
::DeleteObject(hBrush);
::DeleteDC(hdc);
SetTimer(hWnd,1,50,NULL);
dwStart = ::GetTickCount();
return 0;
case WM_PAINT:
// simply validate the window
hdc = BeginPaint(hWnd,&ps);
hBrush = ::CreateSolidBrush(RGB(0,16,57));
::FillRect(hdc,&(ps.rcPaint),hBrush);
::DeleteObject(hBrush);
::DeleteDC(hdc);
// end painting
EndPaint(hWnd,&ps);
// return success
return(0);
case WM_TIMER:
pClsPngAnimation->Lock();
bFlags = pClsPngAnimation->GetFlags(g_indexHDC);
pClsPngAnimation->UnLock();
if(bFlags == TRUE)
{
pClsPngAnimation->Lock();
pClsPngAnimation->PngDisplay(g_indexHDC);
pClsPngAnimation->UnLock();
g_indexPNG++;
if(g_indexPNG >= 50)
::PostMessage(g_hWnd, WM_DESTROY,0,0);
g_indexHDC = g_indexHDC+1;
if(g_indexHDC == THEAD_NUM)
g_indexHDC = 0;
}
return 0;
case WM_DESTROY:
dwCurrent = ::GetTickCount();
info(TEXT("Animation Time = %d ms\r\n"),(dwCurrent-dwStart));
info(TEXT("Get Message WM_DESTROY"));
KillTimer(hWnd,1);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, wMsg, wParam, lParam);
}
void info(const TCHAR* tszFormat, ...)
{
va_list va;
TCHAR tszInfo[1024];
va_start(va, tszFormat);
_vstprintf(tszInfo, tszFormat, va);
va_end(va);
OutputDebugString(tszInfo);
}
void LoadLauncher(void)
{
int nTimeOut = 0x5;
WIN32_FIND_DATA CFindData;
HANDLE hRet;
SHELLEXECUTEINFO CStdShell;
HKEY keyLoaderReg;
BYTE byRegValue[100];
DWORD dwRegLen = 100;
DWORD dwRegType;
if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_USERS,_T("YIHE_SHELL_LOADER"),0,0,&keyLoaderReg))
{
if(ERROR_SUCCESS == RegQueryValueEx(keyLoaderReg,_T("shell"),NULL,&dwRegType,(LPBYTE)byRegValue,&dwRegLen))
{
lpLauncherFileName = (LPCWSTR)byRegValue;
}
RegCloseKey(keyLoaderReg);
}
// load launcher program
memset(&CStdShell, 0, sizeof(SHELLEXECUTEINFO));
CStdShell.cbSize = sizeof(SHELLEXECUTEINFO);
CStdShell.fMask = SEE_MASK_FLAG_NO_UI;
CStdShell.nShow = SW_SHOW;
CStdShell.lpVerb = _T("Open");
while(nTimeOut--)
{
hRet = FindFirstFile(lpLauncherFileName, &CFindData);
if(hRet != INVALID_HANDLE_VALUE)
{
CStdShell.lpFile = lpLauncherFileName;
FindClose(hRet);
if(ShellExecuteEx(&CStdShell))
{
Sleep(1000);
// ::sndPlaySound(NULL,SND_ASYNC);
// ::PostMessage(HWND_BROADCAST,MESSAGE_LAUNCHER_READY,0,0);
// ::PostMessage(g_hWnd,WM_DESTROY,0,0);
return;
}
else
{
break;
}
}
Sleep(1000);
}
CStdShell.lpFile = _T("\\Windows\\explorer.exe");
ShellExecuteEx(&CStdShell);
return;
}
DWORD WINAPI Thread0Proc(PVOID lpParameter)
{
static BOOL bFlags = FALSE;
while(1)
{
pClsPngAnimation->Lock();
bFlags = pClsPngAnimation->GetFlags(g_indexHDC);
pClsPngAnimation->UnLock();
if(bFlags == TRUE)
{
pClsPngAnimation->Lock();
pClsPngAnimation->PngDisplay(g_indexHDC);
pClsPngAnimation->UnLock();
g_indexPNG++;
if(g_indexPNG > 50)
break;
g_indexHDC = g_indexHDC+1;
if(g_indexHDC == THEAD_NUM)
g_indexHDC = 0;
}
else
Sleep(20);
}
::PostMessage(g_hWnd, WM_DESTROY,0,0);
::ExitThread(0);
return 0;
}
DWORD WINAPI Thread1Proc(PVOID lpParameter)
{
static int index = 1;
static BOOL bFlags = FALSE;
static unsigned int nIndexHDC;
static DWORD dwStatus;
RECT rc={0,0,800,270};
HBITMAP hOldBitmap;
wchar_t lpFileName[50] = {0};
while(1)
{
dwStatus = WaitForSingleObject(hThreadEvent6, 2000);
if(dwStatus == WAIT_OBJECT_0)
{
pClsPngAnimation->Lock();
bFlags = pClsPngAnimation->GetFlags(0);
pClsPngAnimation->UnLock();
if(bFlags == FALSE)
{
SetEvent(hThreadEvent1);
#if DRAW_METHOD
// pClsPngAnimation->Lock();
pClsPngAnimation->PngDraw(index,0);
// pClsPngAnimation->UnLock();
#else
wsprintf(lpFileName,DATA_PATH L"PowerOn\\On_%04d.png",index);
nIndexHDC = 0;
HRESULT hResult = pClsPngAnimation->m_pImgFactory->CreateImageFromFile(lpFileName, &(pClsPngAnimation->m_pImageBmp[nIndexHDC]));
if((SUCCEEDED(hResult))/* && (SUCCEEDED(pImageBmp->GetImageInfo(&imageInfo)))*/)
{
info(TEXT("Png Draw %s \r\n"),lpFileName);
hOldBitmap = (HBITMAP)SelectObject(pClsPngAnimation->m_hArrayDC[nIndexHDC],pClsPngAnimation->m_hBitmap);
FillRect(pClsPngAnimation->m_hArrayDC[nIndexHDC],&rc,pClsPngAnimation->m_hBrush);
pClsPngAnimation->m_pImageBmp[nIndexHDC]->Draw(pClsPngAnimation->m_hArrayDC[nIndexHDC], &rc,NULL);
::SelectObject(pClsPngAnimation->m_hArrayDC[nIndexHDC],hOldBitmap);
pClsPngAnimation->Lock();
pClsPngAnimation->m_blArrayDC[nIndexHDC] = TRUE;
pClsPngAnimation->UnLock();
}
if(pClsPngAnimation->m_pImageBmp[nIndexHDC])
{
pClsPngAnimation->m_pImageBmp[nIndexHDC]->Release();
pClsPngAnimation->m_pImageBmp[nIndexHDC] = NULL;
}
#endif
index = index+THEAD_NUM;
if(index>50)
break;
}
}
}
::ExitThread(1);
return 0;
}
DWORD WINAPI Thread2Proc(PVOID lpParameter)
{
static int index = 2;
static BOOL bFlags = FALSE;
static unsigned int nIndexHDC;
static DWORD dwStatus;
RECT rc={0,0,800,270};
HBITMAP hOldBitmap;
wchar_t lpFileName[50] = {0};
while(1)
{
dwStatus = WaitForSingleObject(hThreadEvent1, 2000);
if(dwStatus == WAIT_OBJECT_0)
{
pClsPngAnimation->Lock();
bFlags = pClsPngAnimation->GetFlags(1);
pClsPngAnimation->UnLock();
if(bFlags == FALSE)
{
SetEvent(hThreadEvent2);
#if DRAW_METHOD
// pClsPngAnimation->Lock();
pClsPngAnimation->PngDraw(index,1);
// pClsPngAnimation->UnLock();
#else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -