📄 propertydlg.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
///////////////////////////////////////////////////////////////////////////////
// File: PropertyDlg.cpp
//
// Desc: This file defines the member functions of the Property Dialog class
// as well as the DialogProc for the dialog.
//
///////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <stdio.h>
#define _COMCTL32_
#include <commctrl.h>
#undef _COMCTL32_
#include <nsplay.h>
#include "PropertyDlg.h"
#include "resource.h"
#include <uuids.h>
#ifndef UNDER_CE
#include <initguid.h>
#endif // !UNDER_CE
#include "qnetwork.h"
#include "aygshell_helper.h"
#include <strsafe.h>
extern bool g_bSmallScreen;
///////////////////////////////////////////////////////////////////////////////
// Name: PropertyDialogProc()
// Desc: This function handles dialog messages for the Property dialog box.
///////////////////////////////////////////////////////////////////////////////
BOOL CALLBACK PropertyDialogProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static CPropertyDlg *pPropertyDlg = NULL;
switch (uMsg)
{
case WM_INITDIALOG:
// Once this dialog is created, create the associated PropertyDlg class.
// There can only be one Property dialog open at a time, hence the need
// for the static variable pPropertyDlg.
pPropertyDlg = new CPropertyDlg;
if (NULL == pPropertyDlg || false == pPropertyDlg->Init(hWndDlg))
{
DestroyWindow(hWndDlg);
}
else if( g_bSmallScreen && g_AygshellHelper.Loaded() )
{
SHINITDLGINFO shidi;
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_SIPDOWN | SHIDIF_DONEBUTTON;
shidi.hDlg = hWndDlg;
g_AygshellHelper.SHInitDialog( &shidi );
}
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDCANCEL:
case IDOK:
case ID_DLG_CLOSE:
DestroyWindow(hWndDlg);
return TRUE;
}
return FALSE;
case WM_NOTIFY:
return pPropertyDlg->HandleNotifyMsg( hWndDlg, uMsg, wParam, lParam );
break;
case WM_CLOSE:
DestroyWindow(hWndDlg);
return FALSE;
case WM_DESTROY:
if (NULL != pPropertyDlg)
{
delete pPropertyDlg;
pPropertyDlg = NULL;
}
return TRUE;
// This message is sent by the parent window to tell the dialog to show
// itself.
case PD_SHOW:
pPropertyDlg->Show(static_cast<int>(wParam));
return TRUE;
// This message is sent by the parent window to get the dialog to update
// its display.
case PD_UPDATE:
if (!lParam)
pPropertyDlg->Update(reinterpret_cast<TCHAR*>(wParam));
else
pPropertyDlg->UpdateAndRender(reinterpret_cast<TCHAR*>(wParam));
return TRUE;
}
return FALSE;
}
CPropertyDlg::CPropertyDlg() : m_hWnd(NULL),
m_hWndParent(NULL),
m_hListView(NULL),
m_hFont(NULL)
{
LOGFONT logfont;
memset( &logfont, 0, sizeof( logfont ) );
logfont.lfWeight = FW_SEMIBOLD;
logfont.lfHeight = -11;
m_hFont = CreateFontIndirect( &logfont );
}
CPropertyDlg::~CPropertyDlg()
{
(void)Fini();
if (m_hFont)
DeleteObject(m_hFont);
}
BOOL CPropertyDlg::HandleNotifyMsg( HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
BOOL fHandled = FALSE;
NMHDR *pnmh = (NMHDR *)lParam;
NMLISTVIEW *pnmlv = (NMLISTVIEW *)lParam;
if( ( NM_CUSTOMDRAW == pnmh->code ) &&
( m_hListView == pnmh->hwndFrom ) )
{
NMLVCUSTOMDRAW *pcd = (NMLVCUSTOMDRAW *)lParam;
if( CDDS_PREPAINT == pcd->nmcd.dwDrawStage )
{
SetWindowLong( hWndDlg, DWL_MSGRESULT, CDRF_NOTIFYITEMDRAW );
fHandled = TRUE;
}
else if( CDDS_ITEMPREPAINT == pcd->nmcd.dwDrawStage )
{
if( 0 == ( pcd->nmcd.dwItemSpec % 2 ) && m_hFont)
{
SelectObject( pcd->nmcd.hdc, m_hFont);
SetWindowLong( hWndDlg, DWL_MSGRESULT, CDRF_NEWFONT );
}
fHandled = TRUE;
}
}
else if( LVN_DELETEALLITEMS == pnmh->code )
{
//
// Suppress LVN_DELETEITEM notifications
//
SetWindowLong( hWndDlg, DWL_MSGRESULT, TRUE );
fHandled = TRUE;
}
return fHandled;
}
///////////////////////////////////////////////////////////////////////////////
// Name: CPropertyDlg::Init()
// Desc: This function initializes the PropertyDlg class. The parameter hWnd
// is a handle to the Property dialog box.
///////////////////////////////////////////////////////////////////////////////
bool CPropertyDlg::Init(HWND hWnd)
{
m_hWnd = hWnd;
m_hWndParent = ::GetParent(m_hWnd);
m_hListView = GetDlgItem( m_hWnd, IDC_PROPERTIES_LIST );
//
// Check to see if the screen is small
//
if (g_bSmallScreen)
{
RECT rcWorkArea;
RECT rcWnd, rcList;
GetWindowRect(m_hWnd, &rcWnd);
GetWindowRect(m_hListView, &rcList);
if (!SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0))
{
HDC hdc = ::GetDC(NULL);
rcWorkArea.left = 0;
rcWorkArea.top = 0;
rcWorkArea.right = GetDeviceCaps(hdc, HORZRES);
rcWorkArea.bottom = GetDeviceCaps(hdc, VERTRES) - GetSystemMetrics(SM_CYMENU);
::ReleaseDC(NULL, hdc);
}
MoveWindow(m_hWnd,
rcWorkArea.left,
rcWorkArea.top,
rcWorkArea.right,
rcWorkArea.bottom,
TRUE);
rcWorkArea.left += rcList.left - rcWnd.left;
rcWorkArea.right -= rcList.left - rcWnd.left;
rcWorkArea.right += rcList.right - rcWnd.right - 2*GetSystemMetrics(SM_CXDLGFRAME);
rcWorkArea.top += rcList.top - rcWnd.top - GetSystemMetrics(SM_CYCAPTION);
rcWorkArea.bottom -= rcList.top - rcWnd.top;
rcWorkArea.bottom += rcList.bottom - rcWnd.bottom;
MoveWindow(m_hListView,
rcWorkArea.left,
rcWorkArea.top,
rcWorkArea.right,
rcWorkArea.bottom,
TRUE);
}
LVCOLUMN column;
int i = 0;
RECT rect;
GetClientRect( m_hListView, &rect );
column.mask = LVCF_FMT | LVCF_WIDTH;
column.fmt = LVCFMT_LEFT;
column.cx = rect.right - rect.left;
column.iSubItem = 0;
column.iOrder = 0;
column.iImage = 0;
int result = ListView_InsertColumn( m_hListView, 0, &column );
ListView_SetExtendedListViewStyle( m_hListView, LVS_EX_GRIDLINES );
return true;
}
///////////////////////////////////////////////////////////////////////////////
// Name: CPropertyDlg::Fini()
// Desc: This function takes care of all the clean-up necessary for the
// PropertyDlg class, including destroying the window and notifying the
// parent window that the dialog has closed.
///////////////////////////////////////////////////////////////////////////////
bool CPropertyDlg::Fini()
{
bool bResult = false;
if (NULL != m_hWndParent)
{
PostMessage(m_hWndParent, PD_CLOSED, NULL, NULL);
m_hWndParent = NULL;
}
return bResult;
}
///////////////////////////////////////////////////////////////////////////////
// Name: CPropertyDlg::Show()
// Desc: This function makes the dialog show/hide itself.
///////////////////////////////////////////////////////////////////////////////
bool CPropertyDlg::Show(int iShowCmd)
{
bool bResult = false;
// Simple error check
if (NULL == m_hWnd)
{
return bResult;
}
if (FALSE == ShowWindow(m_hWnd, iShowCmd))
{
bResult = false;
}
else
{
bResult = true;
}
return bResult;
}
static void Time2String( double dTime, LPTSTR tszTime, DWORD dwcchTime, BOOL fShowMilliSecs, BOOL fShowZeroHour, LPTSTR tszTimeSep, LPTSTR tszDecimalSep )
{
LONG lRemainingSecs; // remaining secons we have to convert
lRemainingSecs = (LONG) dTime; // ignore fractions of secs for a sec :-)
LONG lHours = lRemainingSecs / 3600; // 3600 seconds in the hour
lRemainingSecs = lRemainingSecs % 3600;
LONG lMinutes = lRemainingSecs / 60; // 60 seconds in the minute
lRemainingSecs = lRemainingSecs % 60;
LONG lSeconds = lRemainingSecs;
// take remaining fraction and scale to millisecs
if (fShowMilliSecs) {
LONG lMilliSecs = (LONG) ((dTime - (LONG) dTime) * 1000.0);
if (lHours == 0 && !fShowZeroHour) {
StringCchPrintf( tszTime, dwcchTime, TEXT("%02lu%s%02lu%s%03lu"), lMinutes, tszTimeSep, lSeconds, tszDecimalSep, lMilliSecs );
} else {
StringCchPrintf( tszTime, dwcchTime, TEXT("%02lu%s%02lu%s%02lu%s%03lu"), lHours, tszTimeSep, lMinutes, tszTimeSep, lSeconds, tszDecimalSep, lMilliSecs );
}
} else {
if (lHours == 0 && !fShowZeroHour) {
StringCchPrintf( tszTime, dwcchTime, TEXT("%02lu%s%02lu"), lMinutes, tszTimeSep, lSeconds );
} else {
StringCchPrintf( tszTime, dwcchTime, TEXT("%02lu%s%02lu%s%02lu"), lHours, tszTimeSep, lMinutes, tszTimeSep, lSeconds );
}
}
}
HRESULT CPropertyDlg::VideoInfo( BSTR * videoInfo, IAMNetShowExProps * pnsep )
{
HRESULT hResult = E_FAIL;
*videoInfo = L"";
if (NULL != pnsep)
{
long codecCount = 0;
if (SUCCEEDED(pnsep->get_CodecCount(&codecCount)))
{
for (int i = codecCount; i > 0; i--)
{
BSTR codecDesc;
if (SUCCEEDED(pnsep->GetCodecDescription(i, &codecDesc))
&& !wcsstr(codecDesc, L"Audio"))
{
LPWSTR comma;
if (comma = wcsrchr(codecDesc, L'('))
{
*comma = L'\0';
}
*videoInfo = codecDesc;
hResult = S_OK;
break;
}
}
}
}
return hResult;
}
HRESULT CPropertyDlg::AudioInfo( LPAUDIOINFO * audioInfo,
IBasicAudio * piba,
IAMNetShowExProps * pnsep,
IAMSecureMediaContent * psmc )
{
HRESULT hResult = E_FAIL;
if (NULL == audioInfo)
{
hResult = E_INVALIDARG;
}
else
{
audioInfo->wfmtWaveFormat.nSamplesPerSec = 0;
audioInfo->wfmtWaveFormat.nChannels = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -