📄 playerwindow.cpp
字号:
}
iStrLen++;
_tcscpy(m_szFilter + iStrLen, TEXT("All Files"));
iStrLen += _tcslen(TEXT("All Files"));
iStrLen++;
_tcscpy(m_szFilter + iStrLen, TEXT("*.*"));
iStrLen += _tcslen(TEXT("*.*"));
iStrLen++;
m_szFilter[iStrLen] = TEXT('\0');
#ifdef UNDER_CE
// Create the command bar
m_hWndCB = ::CommandBar_Create(m_hInstance, m_hWnd, 1);
if (NULL != m_hWndCB)
{
HKEY hkResult = NULL;
bool bHasHttp = false;
// Add a menu bar
::CommandBar_InsertMenubar(m_hWndCB, m_hInstance, IDR_MENUBAR, 0);
// Check to see if there is as way to open an http stream, and assume
// it will render the media homepage.
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CLASSES_ROOT, L"http\\Shell\\Open\\Command", 0, 0, &hkResult))
{
bHasHttp = true;
RegCloseKey(hkResult);
}
if (bHasHttp && NULL != g_szHomePage)
{
::CommandBar_AddBitmap(m_hWndCB, m_hInstance, IDB_GOWEB, 1, 16, 16);
TBBUTTON tbb[2];
tbb[0].iBitmap = 0;
tbb[0].idCommand = ID_DEAD_SPACE;
tbb[0].fsState = 0;
tbb[0].fsStyle = TBSTYLE_SEP;
tbb[0].dwData = 0;
tbb[0].iString = 0;
tbb[1].iBitmap = 0;
tbb[1].idCommand = ID_GOWEB;
tbb[1].fsState = TBSTATE_ENABLED;
tbb[1].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
tbb[1].dwData = 0;
tbb[1].iString = (int)TEXT("Web");
::CommandBar_AddButtons(m_hWndCB, 2, tbb);
}
if (g_bSmallScreen)
{
::CommandBar_AddAdornments(m_hWndCB, 0, 0);
}
}
#endif // UNDER_CE
// Set up the menus based on the current state (m_eState)
UpdateMenus();
// Save the window handle
CMPContainer::SetWindow(m_hWnd);
// Create the WMP control
if (FAILED(CMPContainer::CreateControl(CLSID_MediaPlayer)))
{
return false;
}
// Attach this object as an event handler
// Get a connection point container interface
if (SUCCEEDED(m_pMP->QueryInterface(IID_IConnectionPointContainer, reinterpret_cast<LPVOID*>(&pCPC))))
{
// Get a connection point
if (SUCCEEDED(pCPC->FindConnectionPoint(DIID__MediaPlayerEvents, &pCP)))
{
// Register this object as a MediaPlayerEvent handler
CMPEventSink::Connect(pCP);
if (FAILED(pCP->Advise(static_cast<CMPEventSink*>(this), &m_dwCookie)))
{
CMPEventSink::Disconnect();
}
pCP->Release();
}
pCPC->Release();
}
LoadRegState();
return true;
}
///////////////////////////////////////////////////////////////////////////////
// Name: CPlayerWindow::Fini()
// Desc: This function is used to release all interfaces acquired by the
// by the PlayerWindow class, as well as stopping any currently playing
// media clip and closing all windows.
///////////////////////////////////////////////////////////////////////////////
bool CPlayerWindow::Fini()
{
int i;
bool bResult = true;
SaveRegState();
// If there is a properties dialog, close it
if (NULL != m_hWndProp)
{
DestroyWindow(m_hWndProp);
m_hWndProp = NULL;
}
// If there is a statistics dialog, close it
if (NULL != m_hWndStat)
{
DestroyWindow(m_hWndStat);
m_hWndStat = NULL;
}
// If there is a command bar, close it
if (NULL != m_hWndCB)
{
DestroyWindow(m_hWndCB);
m_hWndCB = NULL;
}
// Hide our window (if we have one)
if (NULL != m_hWnd)
{
Show(SW_HIDE);
}
// Shutdown the ActiveX container and the EventSink
CMPEventSink::Disconnect();
CMPContainer::DestroyControl();
// Deallocate the stored filename if needed
if (NULL != m_szFilename)
{
delete[] m_szFilename;
m_szFilename = NULL;
}
for( i = 0; i < MAX_FILEOPEN_HISTORY; i++ )
{
if( m_szFilenameHistory[i] )
{
delete [] m_szFilenameHistory[i];
m_szFilenameHistory[i] = NULL;
}
}
// Deallocate the stored path if needed
if (NULL != m_szPath)
{
delete[] m_szPath;
m_szPath = NULL;
}
// Deallocate the filter string if needed
if (NULL != m_szFilter)
{
delete[] m_szFilter;
m_szFilter = NULL;
}
// Make sure to free up memory if it was allocated
if (NULL != m_stats.szErrorCorrection)
{
delete[] m_stats.szErrorCorrection;
m_stats.szErrorCorrection = NULL;
}
if (NULL != m_stats.szFilename)
{
delete [] m_stats.szFilename;
m_stats.szFilename = NULL;
}
#ifdef CEPLAYER_SKIN
for (i = 0; i < SKIN_SIZE; i++)
{
if (NULL != m_binfo[i].hUp)
DeleteObject(m_binfo[i].hUp);
if (NULL != m_binfo[i].hDown)
DeleteObject(m_binfo[i].hDown);
if (NULL != m_binfo[i].hDisabled)
DeleteObject(m_binfo[i].hDisabled);
}
if (NULL != m_hbmBuffer)
{
DeleteObject(m_hbmBuffer);
}
DeleteCriticalSection( &m_csButtonInfoCritSec );
#endif /* CEPLAYER_SKIN */
return bResult;
}
///////////////////////////////////////////////////////////////////////////////
// Name: CPlayerWindow::Show()
// Desc: This function allows the PlayerWindow to show or hide itself.
///////////////////////////////////////////////////////////////////////////////
void CPlayerWindow::Show(int iShow)
{
// Tell the ActiveX container to tell the WMP control to show itself
CMPContainer::ShowObject();
// Cause our window (command bar and all) to get repainted
::ShowWindow(m_hWnd, iShow);
::UpdateWindow(m_hWnd);
return;
}
///////////////////////////////////////////////////////////////////////////////
// Name: CPlayerWindow::TranslateAccelerator()
// Desc: This function give the MediaPlayer a chance to handle any accelerator
// keys that may have been pressed.
///////////////////////////////////////////////////////////////////////////////
bool CPlayerWindow::TranslateAccelerator(LPMSG pMsg)
{
IOleInPlaceActiveObject *pIPAO = NULL;
IOleControl *pIControl = NULL;
bool bResult = false;
if (m_eState == BAD
&& NULL != pMsg
&& ( L' ' == (int)pMsg->wParam
|| L'.' == (int)pMsg->wParam
|| VK_LEFT == (int)pMsg->wParam
|| VK_RIGHT == (int)pMsg->wParam
|| VK_NEXT == (int)pMsg->wParam
|| VK_PRIOR == (int)pMsg->wParam
|| L'V' == (int)pMsg->wParam
|| L'G' == (int)pMsg->wParam ))
{
return bResult;
}
// First, give the MediaPlayer a chance to catch this message
if (NULL != m_pUnk)
{
if (SUCCEEDED(m_pUnk->QueryInterface(IID_IOleInPlaceActiveObject, reinterpret_cast<LPVOID*>(&pIPAO))))
{
if (SUCCEEDED(pIPAO->TranslateAccelerator(pMsg)))
{
// If the MediaPlayer can accept this accelerator key, get the
// IOleControl interface and give it the message. Otherwise
// no action as a result of the key event will occur.
if (SUCCEEDED(m_pUnk->QueryInterface(IID_IOleControl, reinterpret_cast<LPVOID*>(&pIControl))))
{
if (SUCCEEDED(pIControl->OnMnemonic(pMsg)))
{
bResult = true;
}
pIControl->Release();
}
}
pIPAO->Release();
}
}
return bResult;
}
bool CPlayerWindow::DialogMessage(LPMSG pMsg)
{
bool bResult = false;
if (NULL != m_hWndStat && IsDialogMessage(m_hWndStat, pMsg))
{
bResult = true;
}
if (false == bResult
&& NULL != m_hWndProp && IsDialogMessage(m_hWndProp, pMsg))
{
bResult = true;
}
return bResult;
}
bool CPlayerWindow::SaveRegState()
{
RECT rc;
LONG lVolume = 0;
int i;
HKEY hkResult;
TCHAR szRegKey[REGKEY_SIZE];
VARIANT_BOOL fMuted = FALSE;
DWORD dwTemp = 0;
bool bResult = false;
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
TEXT("SOFTWARE\\Microsoft\\CEPlayer"),
0, 0, &hkResult))
{
if (FALSE != GetWindowRect(m_hWnd, &rc))
{
RegSetValueEx(hkResult, TEXT("XPos"), 0, REG_DWORD,
(BYTE*)&rc.left, sizeof (DWORD));
RegSetValueEx(hkResult, TEXT("YPos"), 0, REG_DWORD,
(BYTE*)&rc.top, sizeof (DWORD));
}
if (NULL != m_szFilename)
{
DWORD dwStrLength;
szRegKey[0] = TEXT('\0');
for (i = 0; i < MAX_FILEOPEN_HISTORY; i++)
{
if (m_szFilenameHistory[i])
{
LoadString(m_hInstance, ID_FILENAME1_REGKEY + i, szRegKey, REGKEY_SIZE);
dwStrLength = MAX_URL_LENGTH;
RegSetValueEx(hkResult, szRegKey, 0, REG_SZ,
(BYTE*)m_szFilenameHistory[i],
(_tcslen(m_szFilenameHistory[i]) + 1) * sizeof (TCHAR));
}
}
}
if (NULL != m_pMP)
{
m_pMP->get_Volume(&lVolume);
lVolume = VolumeLogToLin(lVolume);
m_pMP->get_Mute(&fMuted);
}
dwTemp = (DWORD)fMuted;
RegSetValueEx(hkResult,
TEXT("PlayForever"), 0,
REG_BINARY, (BYTE*)&m_bPlayForever,
sizeof (BOOL));
RegSetValueEx(hkResult,
TEXT("Shuffle"), 0,
REG_BINARY, (BYTE*)&m_bShuffle,
sizeof (BOOL));
RegSetValueEx(hkResult,
TEXT("ZoomLevel"), 0,
REG_DWORD, (BYTE*)&m_dwZoomLevel,
sizeof (DWORD));
RegSetValueEx(hkResult,
TEXT("Muted"), 0,
REG_DWORD, (BYTE*)&dwTemp,
sizeof (DWORD));
RegSetValueEx(hkResult,
TEXT("Volume"), 0,
REG_DWORD, (BYTE*)&lVolume,
sizeof (DWORD));
RegCloseKey(hkResult);
bResult = true;
}
return bResult;
}
bool CPlayerWindow::LoadRegState()
{
HKEY hkResult;
DWORD dwDisp,
dwType,
dwSize,
dwKeyType;
int i;
TCHAR szRegKey[REGKEY_SIZE];
bool bResult = false;
if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE,
TEXT("SOFTWARE\\Microsoft\\CEPlayer"),
0, NULL, 0, 0, NULL, &hkResult, &dwDisp))
{
if (NULL != m_szFilename)
{
delete [] m_szFilename;
m_szFilename = NULL;
}
for (i = 0; i < MAX_FILEOPEN_HISTORY; i++)
{
m_szFilenameHistory[i] = new TCHAR[MAX_URL_LENGTH];
szRegKey[0] = TEXT('\0');
LoadString(m_hInstance, ID_FILENAME1_REGKEY + i, szRegKey, REGKEY_SIZE);
dwSize = MAX_URL_LENGTH;
// Don't try to load a value from the registry if we weren't able to allocate memory
if (NULL == m_szFilenameHistory[i]
|| ERROR_SUCCESS != RegQueryValueEx(hkResult, szRegKey, 0, &dwKeyType,
(BYTE*)m_szFilenameHistory[i], &dwSize)
|| REG_SZ != dwKeyType)
{
delete [] m_szFilenameHistory[i];
m_szFilenameHistory[i] = NULL;
}
}
if (m_szFilenameHistory[0])
{
if (m_szFilename = new TCHAR[_tcslen(m_szFilenameHistory[0]) + 1])
{
_tcscpy(m_szFilename, m_szFilenameHistory[0]);
}
}
if (REG_OPENED_EXISTING_KEY == dwDisp)
{
LONG lVolume = 0;
DWORD dwTemp = 0;
VARIANT_BOOL fMuted = FALSE;
dwSize = sizeof (m_bPlayForever);
RegQueryValueEx(hkResult,
TEXT("PlayForever"), NULL,
&dwType, (BYTE*)&m_bPlayForever,
&dwSize);
dwSize = sizeof (m_bShuffle);
RegQueryValueEx(hkResult,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -