📄 speeddiallistdialog.cpp
字号:
return S_OK;
}
/*------------------------------------------------------------------------------
SpeedDialListDialog_t::OnDelete
If the user wants to delete an item show the "confirm delete" question box
------------------------------------------------------------------------------*/
HRESULT
SpeedDialListDialog_t::OnDelete()
{
if (m_ConfirmDeleteDialog)
{
ASSERT(FALSE);
return E_FAIL;
}
//ask the user if they really want to delete this entry...
int SelectedIndex = m_Listbox.GetCurSel();
if (SelectedIndex == 0)
{
ASSERT(FALSE);
return E_FAIL;
}
//get the selected item
SpeedDialDisplayItem_t* pItem = static_cast<SpeedDialDisplayItem_t*>(m_Listbox.GetItem(SelectedIndex));
if (! pItem)
{
ASSERT(FALSE);
return E_FAIL;
}
WCHAR Name[100] = L"";
WCHAR Question[MAX_PATH] = L"";
//get the name from the item
pItem->GetSubItemText(
SpeedDialDisplayItem_t::TextName,
Name,
_countof(Name)
);
//format the name into the question
StringCchPrintf(
Question,
_countof(Question),
CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, IDS_LABEL_CONFIRMDELETE_QUESTION),
Name
);
//Pop up the message box
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;
}
//save the result HWND for us to destroy later
m_ConfirmDeleteDialog = Params.result.Dialog;
return S_OK;
}
/*------------------------------------------------------------------------------
SpeedDialListDialog_t::OnNotify
Handle the asynchronous NOTIFY about our 'confirm delete' message box
Parameters:
wParam:
lParam:
Returns (HRESULT):
------------------------------------------------------------------------------*/
HRESULT
SpeedDialListDialog_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_ConfirmDeleteDialog == 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_ConfirmDeleteDialog);
m_ConfirmDeleteDialog = NULL;
//if the user didn't say "Yes" we can ignore this event
if (LOWORD(wParam) != IDC_CONFIRMDELETE_YES)
{
return S_OK;
}
//the user said "Yes" - we need to delete the record
int SelectedItem = m_Listbox.GetCurSel();
SpeedDialDisplayItem_t* pItem = static_cast<SpeedDialDisplayItem_t*>(m_Listbox.GetItem(SelectedItem));
if (! pItem || SelectedItem == 0)
{
ASSERT(FALSE);
return E_FAIL;
}
CComPtr<IVoIPCallerInfoRecord> cpRecord = NULL;
pItem->GetRecord(&cpRecord);
if (! cpRecord)
{
ASSERT(FALSE);
return E_FAIL;
}
cpRecord->DeleteFromDB();
//asynchronously refresh the UI
PostMessage(m_Dialog, WM_SPEEDDIAL_ASYNC_REFRESH, 0, 0);
return S_OK;
}
/*------------------------------------------------------------------------------
SpeedDialListDialog_t::OnItemActivated
Handle the user activating (clicking on) a specific item
------------------------------------------------------------------------------*/
HRESULT
SpeedDialListDialog_t::OnItemActivated()
{
//if this is not the edit item then the user wants to dial a specific entry...
int SelectedItem = m_Listbox.GetCurSel();
if (SelectedItem != 0)
{
return OnDial();
}
return S_OK;
}
/*------------------------------------------------------------------------------
SpeedDialListDialog_t::OnDial
Handle a dial request from the user
Returns (HRESULT):
------------------------------------------------------------------------------*/
HRESULT
SpeedDialListDialog_t::OnDial()
{
//we're either dialing the current selection or for the number in the edit box
int SelectedItem = m_Listbox.GetCurSel();
IVoIPDisplayItem* pItem = m_Listbox.GetItem(SelectedItem);
if (! pItem)
{
return E_FAIL;
}
//is the first item the selected item? if so...
if (SelectedItem == 0)
{
//dial by speed dial entry!
WCHAR Number[5] = L"";
pItem->GetText(Number, _countof(Number));
if (! Number[0])
{
ASSERT(FALSE);
return E_FAIL;
}
return DialBySpeedDialEntry(_wtol(Number));
}
//otherwise dial for this specific item
SpeedDialDisplayItem_t* pSDItem = static_cast<SpeedDialDisplayItem_t*>(pItem);
//get the record with the number to dial
CComPtr<IVoIPCallerInfoRecord> cpRecord;
HRESULT hr = pSDItem->GetRecord(&cpRecord);
if (FAILED(hr))
{
ASSERT(FALSE);
return hr;
}
return DialRecord(cpRecord);
}
/*------------------------------------------------------------------------------
SpeedDialListDialog_t::DialBySpeedDialEntry
Find the info corresponding to the speed dial entry the user wants to dial.
Start a call with this number
------------------------------------------------------------------------------*/
HRESULT
SpeedDialListDialog_t::DialBySpeedDialEntry(
LONG Entry
)
{
CComPtr<IVoIPCallerInfoRecord> cpRecord;
//look up the info record
HRESULT hr = m_cpCallerInfoDB->FindCallerInfoBySpeedDialEntry(
Entry,
&cpRecord
);
if (SUCCEEDED(hr) && cpRecord)
{
return DialRecord(cpRecord);
}
//failed to find a record - add an error message in the status region and continue...
STATUS_HEADER_PARAMETERS StatusHeaderParameter = {0};
StatusHeaderParameter.Instance = GlobalData_t::s_ModuleInstance;
StatusHeaderParameter.Priority = shpError;
StatusHeaderParameter.ResourceId = IDS_ERROR_SPEEDDIAL_INVALID;
StatusHeaderParameter.secTimeout = 3;
SendMessage(
m_StatusRegion,
WM_STATUSHEADER_ADDSTATUSNOTIFICATION,
sizeof(StatusHeaderParameter),
(LPARAM)&StatusHeaderParameter
);
//also reset the text in the first item
IVoIPDisplayItem* pItem = m_Listbox.GetItem(0);
if (pItem)
{
pItem->SetText(L"");
ShowHideBackspaceButton();
}
//update the buttons
OnSelectionChange();
return S_OK;
}
/*------------------------------------------------------------------------------
SpeedDialListDialog_t::DialRecord
Place a call in the phone app with the number specified in the
caller info record we retrived.
------------------------------------------------------------------------------*/
HRESULT
SpeedDialListDialog_t::DialRecord(
IVoIPCallerInfoRecord* pRecord
)
{
PH_MAKEPHONECALL_PARAMETERS Parameters = {0};
Parameters.StructSize = sizeof(Parameters);
ce::auto_bstr URI = NULL;
if (! pRecord)
{
ASSERT(FALSE);
return E_FAIL;
}
//
// Get the Phone number.
//
HRESULT hr = pRecord->get_URI(
&URI
);
if (FAILED(hr))
{
return hr;
}
if (URI == NULL || URI[0] == 0)
{
return E_FAIL;
}
StringCchCopy(
Parameters.DestAddress,
_countof(Parameters.DestAddress),
URI
);
//
// Get the name, ignore errors.
//
ce::auto_bstr Name = NULL;
hr = pRecord->get_FriendlyName(
&Name
);
if (SUCCEEDED(hr) && Name != NULL && Name[0] != 0)
{
StringCchCopy(
Parameters.CalledParty,
_countof(Parameters.CalledParty),
Name
);
}
return PHMakePhoneCall(&Parameters);
}
/*------------------------------------------------------------------------------
SpeedDialListDialog_t::OnNew
TEMPORARY - Create a new random record for filling up the UI...
------------------------------------------------------------------------------*/
HRESULT
SpeedDialListDialog_t::OnNew()
{
PhInfoGlobalData_t::pPhInfoApp->CreateSpeedDialEditScreen(NULL);
return S_OK;
}
/*------------------------------------------------------------------------------
SpeedDialListDialog_t::OnEdit
Open a specific entry for editing
------------------------------------------------------------------------------*/
HRESULT
SpeedDialListDialog_t::OnEdit()
{
int Selected = m_Listbox.GetCurSel();
if (Selected <= 0)
{
ASSERT(FALSE);
return E_FAIL;
}
SpeedDialDisplayItem_t* pSpeedDialItem = static_cast<SpeedDialDisplayItem_t*>(m_Listbox.GetItem(Selected));
CComPtr<IVoIPCallerInfoRecord> cpRecord;
pSpeedDialItem->GetRecord(&cpRecord);
if (cpRecord)
{
PhInfoGlobalData_t::pPhInfoApp->CreateSpeedDialEditScreen(cpRecord);
}
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -