📄 ceplayer.cpp
字号:
if (hWnd)
{
//If it is already running, then focus on the window
SetForegroundWindow ((HWND) (((DWORD)hWnd) | 0x01));
if( *szCmdLine )
{
COPYDATASTRUCT cds = { 1, 2*(wcslen( szCmdLine ) + 1), szCmdLine };
SendMessage( hWnd, WM_COPYDATA, NULL, (LPARAM)&cds );
}
RegCloseKey( hkResult );
return 0;
}
}
// Initialize the window position to be the upper left corner of the screen
iXPos = 0;
iYPos = 0;
// Get the last position from the registry
if( hkResult )
{
if (REG_OPENED_EXISTING_KEY == dwDisp)
{
dwSize = sizeof (DWORD);
if (ERROR_SUCCESS == RegQueryValueEx(hkResult,
TEXT("YPos"), NULL,
&dwType, (BYTE*)&dwData,
&dwSize))
{
if (REG_DWORD == dwType)
{
iYPos = (int)dwData;
}
}
dwSize = sizeof (DWORD);
if (ERROR_SUCCESS == RegQueryValueEx(hkResult,
TEXT("XPos"), NULL,
&dwType, (BYTE*)&dwData,
&dwSize))
{
if (REG_DWORD == dwType)
{
iXPos = (int)dwData;
}
}
}
RegCloseKey( hkResult );
}
// Load the accelerator table
hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE (ID_ACCEL));
// create a window for the player
DWORD dwExStyle, dwStyle;
int iWidth, iHeight;
if (g_bSmallScreen)
{
RECT rcWorkArea;
dwExStyle = 0;
dwStyle = WS_VISIBLE;
if (SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0))
{
iWidth = rcWorkArea.right - rcWorkArea.left;
iHeight = rcWorkArea.bottom - rcWorkArea.top;
}
else
{
hdc = ::GetDC(NULL);
iWidth = GetDeviceCaps(hdc, HORZRES);
iHeight = GetDeviceCaps(hdc, VERTRES) - GetSystemMetrics(SM_CYMENU);
::ReleaseDC(NULL, hdc);
}
}
else
{
dwExStyle = WS_EX_WINDOWEDGE;
dwStyle = WS_CAPTION | WS_SIZEBOX | WS_SYSMENU; //| WS_VISIBLE;
iWidth = CW_USEDEFAULT;
iHeight = CW_USEDEFAULT;
}
hWnd = CreateWindowEx(dwExStyle,
g_szWMPWindowClass,
TEXT("Media Player"),
dwStyle,
iXPos,
iYPos,
iWidth,
iHeight,
NULL,
NULL,
hInstance,
NULL);
if (NULL != g_pPlayerWindow)
{
g_pPlayerWindow->Show(iCmdShow);
}
// If we have a command line, open it immediately
if (NULL != g_pPlayerWindow
&& 0 < _tcslen(szCmdLine))
{
g_pPlayerWindow->OnOpen(szCmdLine);
}
// Event loop... wait for a close
while (GetMessage(&msg, NULL, 0, 0))
{
//
// First give any modeless dialogs a chance at the message...
//
if (NULL == g_pPlayerWindow || !g_pPlayerWindow->DialogMessage(&msg))
{
// Translate accelerators
// Okay, this is a bit nasty, but the general idea is to first get any
// app specific accelerator keys. If there aren't any, try to get any
// control specific acclerators. If there aren't any there, just
// process the message
if (!TranslateAccelerator (hWnd, hAccel, &msg)
&& (NULL == g_pPlayerWindow
|| !g_pPlayerWindow->TranslateAccelerator(&msg)))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
// Perform shutdown on the player
FiniPlayer(hInstance);
DestroyWindow(hWnd);
return msg.wParam;
}
///////////////////////////////////////////////////////////////////////////////
// Name: InitPlayer()
// Desc: InitPlayer is used to initialize COM, OLE, and the window class for
// the CEPlayer application
///////////////////////////////////////////////////////////////////////////////
bool InitPlayer(HINSTANCE hInstance)
{
INITCOMMONCONTROLSEX iccEx;
WNDCLASS wc;
bool bResult = true;
// Initialize COM/OLE (Under CE, it's done via CoInitializeEx)
#ifndef UNDER_CE
if (FAILED(CoInitialize(NULL)))
#else
if (FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED)))
#endif // !UNDER_CE
{
bResult = false;
}
// Initialize the common control DLL
memset(&iccEx, 0, sizeof (iccEx));
iccEx.dwSize = sizeof (iccEx);
iccEx.dwICC = ICC_BAR_CLASSES | ICC_UPDOWN_CLASS | ICC_COOL_CLASSES | ICC_LISTVIEW_CLASSES;
if (FALSE == InitCommonControlsEx(&iccEx))
{
bResult = false;
}
// create and register a new window class
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL; //LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPICON)); This doesn't work properly. Use LoadImage into g_hImage instead.
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = reinterpret_cast<HBRUSH>(GetStockObject(BLACK_BRUSH));
#ifndef UNDER_CE
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENUBAR),
#else
wc.lpszMenuName = NULL;
#endif // !UNDER_CE
wc.lpszClassName = g_szWMPWindowClass;
RegisterClass(&wc);
return bResult;
}
///////////////////////////////////////////////////////////////////////////////
// Name: FiniPlayer()
// Desc: This function is used to shutdown the main window, and COM
///////////////////////////////////////////////////////////////////////////////
bool FiniPlayer(HINSTANCE hInstance)
{
bool bResult = true;
if (NULL != g_pPlayerWindow)
{
delete g_pPlayerWindow;
g_pPlayerWindow = NULL;
}
UnregisterClass(g_szWMPWindowClass, hInstance);
CoUninitialize();
DestroyIcon( g_hIcon );
return bResult;
}
///////////////////////////////////////////////////////////////////////////////
// Name: LoadMediaTypes()
// Desc: This function queries the registry for the various media types.
///////////////////////////////////////////////////////////////////////////////
bool LoadMediaTypes(HINSTANCE hInstance)
{
DWORD dwIndex = 0;
DWORD dwType, i;
DWORD cbName = MAX_PATH;
DWORD cbData = MAX_PATH;
DWORD cAudioTypes = 0;
DWORD cVideoTypes = 0;
DWORD cPlaylistTypes = 0;
TCHAR szName[MAX_PATH];
TCHAR szData[MAX_PATH];
TCHAR **ppszBuffer = NULL;
TCHAR **ppszTemp = NULL;
HKEY hKey;
bool bResult = false;
while (ERROR_SUCCESS == RegEnumKeyEx(HKEY_CLASSES_ROOT,
dwIndex,
szName,
&cbName,
NULL,
szData,
&cbData,
NULL))
{
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CLASSES_ROOT,
szName,
0, 0,
&hKey))
{
cbData = MAX_PATH;
if (ERROR_SUCCESS == RegQueryValueEx(hKey,
NULL,
NULL,
&dwType,
(BYTE*)szData,
&cbData)
&& REG_SZ == dwType)
{
if (cbData > _tcslen(TEXT("audiofile"))
&& 0 == _tcscmp(szData, TEXT("audiofile")))
{
cAudioTypes++;
ppszBuffer = new TCHAR * [cAudioTypes];
if (NULL != ppszBuffer)
{
for (i = 0; i < g_cAudioTypes; i++)
{
ppszBuffer[i] = g_ppszAudioTypes[i];
}
ppszBuffer[i] = new TCHAR [_tcslen(szName) + 1];
if (NULL != ppszBuffer[i])
{
_tcscpy(ppszBuffer[i], szName);
g_cAudioTypes++;
ppszTemp = g_ppszAudioTypes;
g_ppszAudioTypes = ppszBuffer;
ppszBuffer = ppszTemp;
}
delete [] ppszBuffer;
}
}
else if (cbData > _tcslen(TEXT("videofile"))
&& 0 == _tcscmp(szData, TEXT("videofile")))
{
cVideoTypes++;
ppszBuffer = new TCHAR * [cVideoTypes];
if (NULL != ppszBuffer)
{
for (i = 0; i < g_cVideoTypes; i++)
{
ppszBuffer[i] = g_ppszVideoTypes[i];
}
ppszBuffer[i] = new TCHAR [_tcslen(szName) + 1];
if (NULL != ppszBuffer[i])
{
_tcscpy(ppszBuffer[i], szName);
g_cVideoTypes++;
ppszTemp = g_ppszVideoTypes;
g_ppszVideoTypes = ppszBuffer;
ppszBuffer = ppszTemp;
}
delete [] ppszBuffer;
}
}
else if (cbData > _tcslen(TEXT("playlist"))
&& 0 == _tcscmp(szData, TEXT("playlist")))
{
cPlaylistTypes++;
ppszBuffer = new TCHAR * [cPlaylistTypes];
if (NULL != ppszBuffer)
{
for (i = 0; i < g_cPlaylistTypes; i++)
{
ppszBuffer[i] = g_ppszPlaylistTypes[i];
}
ppszBuffer[i] = new TCHAR [_tcslen(szName) + 1];
if (NULL != ppszBuffer[i])
{
_tcscpy(ppszBuffer[i], szName);
g_cPlaylistTypes++;
ppszTemp = g_ppszPlaylistTypes;
g_ppszPlaylistTypes = ppszBuffer;
ppszBuffer = ppszTemp;
}
delete [] ppszBuffer;
}
}
}
RegCloseKey(hKey);
}
// Try the next key.
dwIndex++;
cbName = MAX_PATH;
cbData = MAX_PATH;
szName[0] = TEXT('\0');
szData[0] = TEXT('\0');
}
return bResult;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -