📄 speeddiallistdialog.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 "SpeedDialListDialog.hpp"
#include "InfoApp.hpp"
#include "Common.hpp"
#include "Controls.hpp"
#include "Resource.h"
#include <winuserm.h>
#include "SpeedDialDisplayItem.hpp"
#include "PhoneAPI.hpp"
#define WM_SPEEDDIAL_ASYNC_REFRESH (WM_USER + 1)
/*------------------------------------------------------------------------------
SpeedDialListDialog_t::SpeedDialListDialog_t
Ctor
------------------------------------------------------------------------------*/
SpeedDialListDialog_t::SpeedDialListDialog_t()
{
m_CurrentMenuId = 0;
m_CurrentStatusId = 0;
m_ConfirmDeleteDialog = NULL;
}
/*------------------------------------------------------------------------------
SpeedDialListDialog_t::~SpeedDialListDialog_t
Dtor, cleanup as needed
------------------------------------------------------------------------------*/
SpeedDialListDialog_t::~SpeedDialListDialog_t()
{
if (m_ConfirmDeleteDialog)
{
DestroyWindow(m_ConfirmDeleteDialog);
m_ConfirmDeleteDialog = NULL;
}
}
/*------------------------------------------------------------------------------
SpeedDialListDialog_t::CreateDialogScreen
Function which creates the dialog and inits the necessary UI elements
Parameters:
pInfoApp: The main app which holds the caller info DB
Returns (HRESULT): Indicating success or failure
------------------------------------------------------------------------------*/
HRESULT
SpeedDialListDialog_t::CreateDialogScreen(
InfoApp_t* pInfoApp
)
{
//ensure we have a caller info DB before continuing
HRESULT hr = pInfoApp->GetCallerInfoDB(&m_cpCallerInfoDB);
if (FAILED(hr))
{
return hr;
}
m_CurrentMenuId = 0;
//create the dialog screen
hr = DialogScreen_t::CreateDialogScreen(
PHINFO_SPEEDDIAL_LIST_SCREEN_ID,
m_CurrentMenuId,
CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, IDS_TITLE_SPEEDDIAL),
CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, IDS_STATUS_HELP_SPEEDDIALLIST)
);
if (FAILED(hr))
{
return hr;
}
return S_OK;
}
/*------------------------------------------------------------------------------
SpeedDialListDialog_t::HookProc
HookProc which handles message callbacks
------------------------------------------------------------------------------*/
BOOL
SpeedDialListDialog_t::HookProc(
HWND hwnd,
UINT Message,
WPARAM wParam,
LPARAM lParam
)
{
HRESULT hr = S_OK;
switch (Message)
{
case WM_SCREEN_REFRESH:
case WM_SPEEDDIAL_ASYNC_REFRESH:
//asynchronously refresh the screen
Refresh();
return TRUE;
case WM_INITDIALOG:
//On InitDialog store the member variables and refresh the controls
m_Dialog = hwnd;
hr = Refresh();
if (FAILED(hr))
{
DestroyWindow(hwnd);
}
//don't take focus away from the listbox/child controls
return FALSE;
case WM_COMMAND:
switch(HIWORD(wParam))
{
case EN_UPDATE:
ShowHideBackspaceButton();
hr = DialIfComplete();
break;
case LBN_SELCHANGE:
hr = OnSelectionChange();
break;
case LBN_DBLCLK:
hr = OnItemActivated();
break;
case 0:
//Menu or Button Click
switch (LOWORD(wParam))
{
case IDC_NEW:
hr = OnNew();
break;
case IDC_DELETE:
hr = OnDelete();
break;
case IDCANCEL:
hr = Exit();
break;
case IDC_EDIT:
hr = OnEdit();
break;
case IDC_DIAL:
hr = OnDial();
break;
case IDC_BACKSPACE:
hr = OnBackspace();
break;
default:
return FALSE;
}
break;
}
break;
case WM_NOTIFY:
OnNotify(wParam, lParam);
return FALSE;
default:
return FALSE;
}
return SUCCEEDED(hr);
}
/*------------------------------------------------------------------------------
SpeedDialListDialog_t::Refresh
Refresh the contents of this dialog
------------------------------------------------------------------------------*/
HRESULT
SpeedDialListDialog_t::Refresh()
{
IVoIPDisplayItem* pItem = NULL;
HRESULT hr = S_OK;
CComPtr<IVoIPCallerInfoDBEnum> cpEnum;
//disable redrawing
SendMessage(m_Listbox, WM_SETREDRAW, FALSE, 0);
//delete the old items
SendMessage(m_Listbox, LB_RESETCONTENT, 0, 0);
//create a labeled edit display item for the first item
hr = PHCreateLabeledEditDisplayItem(
CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, IDS_LABEL_DIAL),
WS_BORDER | ES_NUMBER,
2,
&pItem,
-1,
EIM_NUMBERS
);
if (FAILED(hr))
{
ASSERT(FALSE);
goto exit;
}
hr = m_Listbox.AddItem(0, pItem);
if (FAILED(hr))
{
delete pItem;
goto exit;
}
//now add an item for each speed dial entry...
hr = m_cpCallerInfoDB->get_SpeedDialEnumerator(&cpEnum);
if (FAILED(hr))
{
goto exit;
}
while (1)
{
CComPtr<IVoIPCallerInfoRecord> cpRecord;
SpeedDialDisplayItem_t* pSpeedDialItem = NULL;
hr = cpEnum->Next(1, &cpRecord, NULL);
//out of items
if (hr != S_OK)
{
break;
}
pSpeedDialItem = new SpeedDialDisplayItem_t(cpRecord);
if (! pSpeedDialItem)
{
hr = E_OUTOFMEMORY;
goto exit;
}
hr = m_Listbox.AddItem(-1, pSpeedDialItem);
if (FAILED(hr))
{
delete pSpeedDialItem;
goto exit;
}
}
//set the selection to the first item
m_Listbox.SetCurSel(0);
exit:
//reenable redrawing
SendMessage(m_Listbox, WM_SETREDRAW, TRUE, 0);
return hr;
}
/*------------------------------------------------------------------------------
SpeedDialListDialog_t::ShowHideBackspaceButton
Show or hide the backspace button
------------------------------------------------------------------------------*/
HRESULT
SpeedDialListDialog_t::ShowHideBackspaceButton()
{
//Are there enough digits in the 'dial' field to speed dial?
if (m_Listbox.GetCurSel() != 0)
{
return S_FALSE;
}
IVoIPDisplayItem* pItem = m_Listbox.GetItem(0);
if (! pItem)
{
ASSERT(FALSE);
return E_FAIL;
}
WCHAR NumberBuffer[5] = L"";
pItem->GetText(NumberBuffer, _countof(NumberBuffer));
m_MenuBar.ShowMenuButton(
IDC_BACKSPACE,
NumberBuffer[0] != 0
);
return S_OK;
}
HRESULT
SpeedDialListDialog_t::DialIfComplete()
{
//Are there enough digits in the 'dial' field to speed dial?
if (m_Listbox.GetCurSel() != 0)
{
return S_FALSE;
}
IVoIPDisplayItem* pItem = m_Listbox.GetItem(0);
if (! pItem)
{
ASSERT(FALSE);
return E_FAIL;
}
WCHAR NumberBuffer[5] = L"";
pItem->GetText(NumberBuffer, _countof(NumberBuffer));
//do we have enough to dial?
if (wcslen(NumberBuffer) != 2)
{
return S_FALSE;
}
return DialBySpeedDialEntry(_wtol(NumberBuffer));
}
/*------------------------------------------------------------------------------
SpeedDialListDialog_t::OnSelectionChange
Handle the selection changing in the listbox
------------------------------------------------------------------------------*/
HRESULT
SpeedDialListDialog_t::OnSelectionChange()
{
int MenuId = 0;
if (m_Listbox.GetCurSel() == 0)
{
IVoIPDisplayItem* pItem = m_Listbox.GetItem(0);
if (! pItem)
{
ASSERT(FALSE);
return E_FAIL;
}
WCHAR NumberBuffer[5] = L"";
pItem->GetText(NumberBuffer, _countof(NumberBuffer));
//do we have enough to dial?
MenuId = IDMB_SPEEDDIALLIST_BUTTONS;
}
else
{
MenuId = IDMB_SPEEDDIALLIST_ITEM_BUTTONS;
}
//update the menu
if (MenuId != m_CurrentMenuId)
{
m_CurrentMenuId = MenuId;
m_MenuBar.SetMenu(
GlobalData_t::s_ModuleInstance,
m_CurrentMenuId
);
if (MenuId == IDMB_SPEEDDIALLIST_BUTTONS)
{
ShowHideBackspaceButton();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -