📄 blockedcallerlistdialog.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 <windows.h>
#include "InfoApp.hpp"
#include "BlockedCallerListDialog.hpp"
#include "Controls.hpp"
#include "CallRecordDisplayItem.h"
#include "Common.hpp"
BlockedCallerListDialog_t::BlockedCallerListDialog_t ()
{
m_Dialog = NULL;
m_ConfirmUnblockAllMessageBox = NULL;
}
BlockedCallerListDialog_t::~BlockedCallerListDialog_t()
{
if (m_ConfirmUnblockAllMessageBox != NULL)
{
DestroyWindow(m_ConfirmUnblockAllMessageBox);
}
}
/*------------------------------------------------------------------------------
CreateDialogScreen
Creates Blocked caller list dialog screen.
------------------------------------------------------------------------------*/
HRESULT
BlockedCallerListDialog_t::CreateDialogScreen()
{
HRESULT hr = DialogScreen_t::CreateDialogScreen(
PHINFO_BLOCKED_CALL_LIST_SCREEN_ID,
IDMB_BLOCKEDCALLERS,
CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, IDS_TITLE_BLOCKEDCALLERS),
NULL
);
if (FAILED(hr))
{
return hr;
}
//get database and enumeration
CComPtr<IVoIPCallerInfoDB> cpCallerInfoDB;
hr = PhInfoGlobalData_t::pPhInfoApp->GetCallerInfoDB(&cpCallerInfoDB);
if (FAILED(hr) || cpCallerInfoDB == NULL)
{
COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Unable to access caller information DB. hr = 0x%x", hr));
return VOIP_E_NODB;
}
CComPtr<IVoIPCallerInfoDBEnum> cpEnum;
hr = cpCallerInfoDB->get_Enumerator(&cpEnum);
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Unable to access caller information DB enumerator. hr = 0x%x", hr));
return hr;
}
// Fill the call list.
CComPtr<IVoIPCallerInfoRecord> cpRecord;
CVoIPCallRecordDisplayItem* pCallRecordDisplay;
VARIANT_BOOL vBlocked = VARIANT_FALSE;
while (cpEnum->Next(1, &cpRecord, NULL) == S_OK)
{
if (cpRecord != NULL)
{
cpRecord->get_Blocked(&vBlocked);
if (vBlocked == VARIANT_FALSE)
{
continue;
}
pCallRecordDisplay = new CVoIPCallRecordDisplayItem(cpRecord);
if (pCallRecordDisplay == NULL)
{
return E_OUTOFMEMORY;
}
hr = m_Listbox.AddItem (-1, pCallRecordDisplay);
if (FAILED(hr))
{
delete pCallRecordDisplay;
return hr;
}
cpRecord = NULL;
}
}
UpdateMenuBar();
UpdateStatusHeader();
// Select the first item.
SendMessage(m_Listbox, LB_SETCURSEL, 0, 0);
return S_OK;
}
/*------------------------------------------------------------------------------
BlockedCallerListDialog_t::HookProc
Hook proc to handle WM_* messages.
------------------------------------------------------------------------------*/
BOOL
BlockedCallerListDialog_t::HookProc(
HWND hwnd,
UINT Message,
WPARAM wParam,
LPARAM lParam
)
{
switch (Message)
{
case WM_COMMAND:
return OnCommand(wParam);
case WM_NOTIFY:
//
// Always return FALSE, so that the dialog screen does the default processing.
//
OnNotify(wParam, lParam);
return FALSE;
case WM_SCREEN_REFRESH:
return Refresh();
default:
break;
}
return FALSE;
}
/*------------------------------------------------------------------------------
BlockedCallerListDialog_t::OnUnBlockAll
Show a popup window to confirm unblocking all callers.
------------------------------------------------------------------------------*/
HRESULT
BlockedCallerListDialog_t::OnUnBlockAll(
void
)
{
WCHAR Question[MAX_PATH] = L"";
StringCchPrintf(
Question,
_countof(Question),
CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, IDS_FMT_CONFIRMUNBLOCKALL_QUESTION),
m_Listbox.GetCount()
);
PH_MESSAGE_BOX_PARAMETERS Params = {0};
Params.Flags = VDF_TYPE_MODELESS;
Params.Instance = GlobalData_t::s_ModuleInstance;
Params.IconId = IDB_CONFIRMDELETE;
Params.MenuId = IDMB_YESNO;
Params.Owner = m_Dialog;
Params.pText = Question;
Params.pTitle = CommonUtilities_t::LoadString(
GlobalData_t::s_ModuleInstance,
IDS_LABEL_CONFIRMDELETE_TITLE
);
Params.StructSize = sizeof(Params);
if (! PHMessageBox(&Params))
{
ASSERT(FALSE);
return E_FAIL;
}
m_ConfirmUnblockAllMessageBox = Params.result.Dialog;
return S_OK;
}
/*------------------------------------------------------------------------------
BlockedCallerListDialog_t::OnUnBlock
Unblock the selected caller and send a message to refresh the screen.
------------------------------------------------------------------------------*/
HRESULT
BlockedCallerListDialog_t::OnUnBlock(
void
)
{
HRESULT hr = UnblockCallerByIndex(m_Listbox.GetCurSel());
if (FAILED(hr))
{
return hr;
}
//asynchronously refresh the UI
PostMessage(
m_Dialog,
WM_SCREEN_REFRESH,
0, 0
);
return S_OK;
}
/*------------------------------------------------------------------------------
BlockedCallerListDialog_t::UpdateMenuBar
Depending on the number of blocked callers show block and block all buttons.
------------------------------------------------------------------------------*/
HRESULT
BlockedCallerListDialog_t::UpdateMenuBar(
void
)
{
unsigned int ItemCount = m_Listbox.GetCount();
m_MenuBar.ShowMenuButton(
IDC_UNBLOCK_ALL,
ItemCount > 1
);
m_MenuBar.ShowMenuButton(
IDC_UNBLOCK,
ItemCount > 0
);
return S_OK;
}
/*------------------------------------------------------------------------------
BlockedCallerListDialog_t::UpdateStatusHeader
Display the number of blocked callers in the status region.
------------------------------------------------------------------------------*/
HRESULT
BlockedCallerListDialog_t::UpdateStatusHeader(
void
)
{
WCHAR Text[MAX_PATH] = L"";
StringCchPrintf(
Text,
_countof(Text),
CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, IDS_FMT_BLOCKED_CALLERS),
m_Listbox.GetCount()
);
STATUS_HEADER_PARAMETERS_EX Params;
Params.Cookie = 100;
Params.Instance = GlobalData_t::s_ModuleInstance;
Params.ResourceId = 0;
Params.secTimeout = INFINITE;
Params.Priority = shpDefault;
Params.pwszDisplayString = Text;
return (HRESULT)SendMessage(
m_StatusRegion,
WM_STATUSHEADER_ADDSTATUSNOTIFICATION,
sizeof(STATUS_HEADER_PARAMETERS_EX),
(LPARAM)&Params
);
}
/*------------------------------------------------------------------------------
BlockedCallerListDialog_t::OnCommand
Handle WM_COMMAND message.
------------------------------------------------------------------------------*/
BOOL
BlockedCallerListDialog_t::OnCommand(
WPARAM wParam
)
{
switch (wParam)
{
case IDC_UNBLOCK_ALL:
return OnUnBlockAll();
case IDC_UNBLOCK :
return OnUnBlock();
case IDCANCEL:
return SUCCEEDED(PhInfoGlobalData_t::pPhInfoApp->GoBackToPreviousScreen ());
default:
break;
}
return FALSE;
}
/*------------------------------------------------------------------------------
BlockedCallerListDialog_t::OnNotify
Handle WM_NOTIFY message.
------------------------------------------------------------------------------*/
BOOL
BlockedCallerListDialog_t::OnNotify(
WPARAM wParam,
LPARAM lParam
)
{
//we only care about NOTIFY when we are waiting for a delete confirmation
NMHDR* pNmHdr = reinterpret_cast<NMHDR*>(lParam);
if (! pNmHdr)
{
ASSERT(FALSE);
return E_FAIL;
}
if (m_ConfirmUnblockAllMessageBox == NULL)
{
return S_FALSE;
}
//validate the return value...
switch (LOWORD(wParam))
{
case IDC_CONFIRMDELETE_YES:
case IDC_CONFIRMDELETE_NO:
case IDCANCEL:
break;
default:
//unknown, ignore this...
return S_FALSE;
}
//this is a valid dialog - we can dismiss it...
DestroyWindow(m_ConfirmUnblockAllMessageBox);
m_ConfirmUnblockAllMessageBox = NULL;
//if the user didn't say "Yes" we can ignore this event
if (LOWORD(wParam) != IDC_CONFIRMDELETE_YES)
{
return S_OK;
}
HRESULT hr = S_OK;
unsigned int ItemCount = m_Listbox.GetCount();
for (int Index = 0; Index < ItemCount; Index++)
{
hr = UnblockCallerByIndex(Index);
if (FAILED(hr))
{
break;
}
Index--;
ItemCount--;
}
//asynchronously refresh the UI
PostMessage(
m_Dialog,
WM_SCREEN_REFRESH,
0, 0
);
return S_OK;
}
/*------------------------------------------------------------------------------
BlockedCallerListDialog_t::Refresh
Handle Menu bar and status header regions.
------------------------------------------------------------------------------*/
HRESULT
BlockedCallerListDialog_t::Refresh(
void
)
{
UpdateMenuBar();
UpdateStatusHeader();
return S_OK;
}
/*------------------------------------------------------------------------------
BlockedCallerListDialog_t::UnblockCallerByIndex
Unblock the caller specified by the list box index.
Delete it from the caller info DB and the list box.
------------------------------------------------------------------------------*/
HRESULT
BlockedCallerListDialog_t::UnblockCallerByIndex(
unsigned int Index
)
{
CVoIPCallRecordDisplayItem* pItem = static_cast<CVoIPCallRecordDisplayItem*>(m_Listbox.GetItem(Index));
if (!pItem)
{
ASSERT(FALSE);
return E_FAIL;
}
CComPtr<IVoIPCallerInfoRecord> cpRecord = NULL;
HRESULT hr = pItem->GetCallerInfoRecord(&cpRecord);
if (FAILED(hr) || !cpRecord)
{
COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Unable to get caller info record from the display item. hr = 0x%x", hr));
ASSERT(FALSE);
return hr;
}
hr = cpRecord->put_Blocked(VARIANT_FALSE);
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Unable to update the unblock attribute in the caller info record. hr = 0x%x", hr));
return hr;
}
hr = cpRecord->Commit();
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Failed to commit the caller info record update to the DB. hr = 0x%x", hr));
}
SendMessage(
m_Listbox,
LB_DELETESTRING,
(WPARAM)Index,
0
);
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -