📄 ringtonessettings.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#include "ringTonesSettings.hpp"
#include "SettingsApp.hpp"
#include "resource.h"
#include "ControlDefinitions.h"
#include "Controls.hpp"
#include "VoIPNotify.hpp"
const DWORD RingTonesSettingsDialog_t::sc_StatusHeaderCookie = 0;
const DWORD RingTonesSettingsDialog_t::sc_ErrorTimeout = 3;
RingTonesSettingsDialog_t::RingTonesSettingsDialog_t(HWND Dialog)
{
m_TopWindow = Dialog;
}
RingTonesSettingsDialog_t::~RingTonesSettingsDialog_t()
{
}
HRESULT
RingTonesSettingsDialog_t::CreateDialogScreen(
)
{
//Don't allow entrance to the state if there are no additional ringtones
if (m_RingtoneIterator.GetRingtoneCount() == 0)
{
STATUS_HEADER_PARAMETERS Parameters = {
GlobalData_t::s_ModuleInstance,
IDS_ERROR_NORINGTONES,
shpError,
sc_StatusHeaderCookie,
sc_ErrorTimeout
};
SendMessage(
GetDlgItem(m_TopWindow, IDC_STATUSREGION),
WM_STATUSHEADER_ADDSTATUSNOTIFICATION,
(WPARAM)sizeof(STATUS_HEADER_PARAMETERS),
(LPARAM)&Parameters
);
return E_FAIL;
}
return SettingsDialog_t::CreateDialogScreen(
IDS_RINGTONESSCREEN_HEADER,
IDS_RINGTONES_TITLE,
IDMB_RINGTONESCREEN_BUTTONS,
PHSETTINGS_RINGTONES_SCREEN_ID
);
}
HRESULT
RingTonesSettingsDialog_t::Initialize()
{
HRESULT hr = S_OK;
int iSettingsIndex; // Settings list index
DWORD iSelectedIndex = 0;
WCHAR wszRingtone[MAX_PATH] = L"";
WCHAR wszSelectedRingtone[MAX_PATH] = L"";
ListBox_t ListBox;
ListBox = GetDlgItem (m_DialogScreen, IDC_LISTBOX);
for (iSettingsIndex = 0; iSettingsIndex < m_RingtoneIterator.GetRingtoneCount(); ++iSettingsIndex)
{
IVoIPDisplayItem* pItem = NULL;
ZeroMemory(wszRingtone, sizeof(wszRingtone));
hr = m_RingtoneIterator.GetRingtoneAt(
iSettingsIndex,
wszRingtone,
_countof(wszRingtone)
);
if (FAILED(hr))
{
goto exit;
}
wszRingtone[0] = towupper(wszRingtone[0]);
hr = PHCreateTextDisplayItem(wszRingtone, &pItem);
if (FAILED (hr))
{
goto exit;
}
hr = ListBox.AddItem(-1, pItem);
if (FAILED(hr))
{
delete pItem;
goto exit;
}
}
hr = RegistryGetDWORD(
SN_VOIP_RINGTONESINDEX_ROOT,
SN_VOIP_RINGTONESINDEX_PATH,
SN_VOIP_RINGTONESINDEX_VALUE,
&iSelectedIndex
);
if (HRESULT_CODE(hr) == ERROR_FILE_NOT_FOUND)
{
iSelectedIndex = 0;
hr = S_OK;
}
SendMessage(ListBox, LB_SETCURSEL, iSelectedIndex, 0);
return hr;
exit:
ASSERT (FALSE);
return hr;
}
HRESULT
RingTonesSettingsDialog_t::OnCommand(
WPARAM wParam
)
{
switch (wParam)
{
case IDC_PLAYSOUND:
case IDOK:
return OnSelect(wParam);
case IDCANCEL:
return GetSettingsApp()->GoBackToPreviousScreen();
}
return E_NOTIMPL;
}
HRESULT
RingTonesSettingsDialog_t::OnSelect(
WPARAM wParam
)
{
WCHAR wszRingtonePath[MAX_PATH] = L"",
wszRingtone[200] = L"";
HRESULT hr = S_OK;
int nIndex;
ListBox_t Listbox;
Listbox = GetDlgItem (m_DialogScreen, IDC_LISTBOX);
nIndex = Listbox.GetCurSel();
hr = m_RingtoneIterator.GetRingtoneAt(
nIndex,
wszRingtone,
_countof(wszRingtone)
);
if (FAILED(hr))
{
goto exit;
}
//construct the ringtone path for playing/setting
hr = m_RingtoneIterator.ConstructPath(
wszRingtone,
wszRingtonePath,
_countof(wszRingtonePath)
);
if (FAILED(hr))
{
goto exit;
}
if (LOWORD(wParam) == IDC_PLAYSOUND)
{
hr = (PlaySound(
wszRingtonePath,
NULL,
SND_FILENAME | SND_ASYNC | SND_NODEFAULT
)) ?
S_OK :
HRESULT_FROM_WIN32(GetLastError());
if (FAILED(hr))
{
DEBUGMSG(1, (L"PlaySound Error (0x%08x)\n", hr));
//goto exit;
return hr;
}
}
else
{
ASSERT(LOWORD(wParam) == IDOK);
hr = RegistrySetDWORD(
SN_VOIP_RINGTONESINDEX_ROOT,
SN_VOIP_RINGTONESINDEX_PATH,
SN_VOIP_RINGTONESINDEX_VALUE,
nIndex
);
if (FAILED(hr))
{
ASSERT (FALSE);
}
hr = RegistrySetString(
SN_VOIP_RINGTONESPATH_ROOT,
SN_VOIP_RINGTONESPATH_PATH,
SN_VOIP_RINGTONESPATH_VALUE,
wszRingtonePath
);
if (FAILED(hr))
{
ASSERT (FALSE);
}
return GetSettingsApp()->GoBackToPreviousScreen();
}
return hr;
exit:
ASSERT(FALSE);
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -