📄 gallistdialog.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 "GalListDialog.hpp"
#include "InfoApp.hpp"
#include "Controls.hpp"
#include "Common.hpp"
#include "Resource.h"
#include "SystemTimeUtils.h"
#include "PhoneAPI.hpp"
#include "SettingsApi.hpp"
#include "VoIPNotify.hpp"
GalListDialog_t::GalListDialog_t()
{
m_GalQueryTimerId = 0;
m_ErrorMenuId = 0;
m_RefreshNeeded = true;
m_FilterType = static_cast<GalFilter_e>(PHGetSetting(phsGalFilterType));
if(m_FilterType >= UnknownFilter)
{
ASSERT(FALSE);
COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Unknown filter type passed. filter type = %d", m_FilterType));
m_FilterType = FirstName;
}
}
GalListDialog_t::~GalListDialog_t()
{
//
// Save the filter type.
//
HRESULT hr = PHSetValue(phsGalFilterType, m_FilterType);
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Unable to save the last used filter type in the registry. hr = 0x%x", hr));
}
//
// If timer is not reset then delete it.
//
if (m_GalQueryTimerId != 0)
{
KillTimer(m_Dialog, m_GalQueryTimerId);
m_GalQueryTimerId = 0;
}
if (m_Dialog != NULL)
{
DestroyWindow(m_Dialog);
}
}
BOOL
GalListDialog_t::HookProc(
HWND hwnd,
UINT Message,
WPARAM wParam,
LPARAM lParam
)
{
switch(Message)
{
case WM_TIMER:
return SUCCEEDED(OnTimer(
wParam)
);
case WM_EXCHANGE_QUERY_COMPLETED:
return SUCCEEDED(OnExchangeQueryProgress (
(IExchangeClientRequest*)lParam,
(ExchangeClientRequestStatus)wParam)
);
case WM_COMMAND:
return SUCCEEDED(OnCommand(
wParam)
);
case WM_VKEYTOITEM:
return SUCCEEDED(SetFocusToFirstItem());
case WM_NOTIFY:
return SUCCEEDED(OnNotify(
wParam,
lParam)
);
case WM_SCREEN_REFRESH:
return SUCCEEDED(CreateExchangeRequest());
}
return FALSE;
}
/*------------------------------------------------------------------------------
GalListDialog_t::OnNotify
Handle a notification (WM_NOTIFY) from one of our message boxes.
------------------------------------------------------------------------------*/
HRESULT
GalListDialog_t::OnNotify(
WPARAM wParam,
LPARAM lParam
)
{
if (m_ErrorDialog == NULL)
{
return E_FAIL;
}
//
// We only care about NOTIFY when we are waiting for an input on the popup scrren.
//
NMHDR* pNmHdr = reinterpret_cast<NMHDR*>(lParam);
if (! pNmHdr)
{
ASSERT(FALSE);
return E_FAIL;
}
//
// Destroy the popup window
//
DestroyWindow(m_ErrorDialog);
m_ErrorDialog = NULL;
HRESULT hr;
switch (LOWORD(wParam))
{
case IDC_ERROR_YES:
//
// Show the settings app.
//
hr = ShowSettingsAppOnError ();
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Failed to show settings app. hr = 0x%x", hr));
ASSERT(FALSE);
}
m_RefreshNeeded = true;
break;
case IDC_ERROR_TRYAGAIN:
//
// Retry the request.
//
m_RefreshNeeded = true;
hr = CreateExchangeRequest ();
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Failed to create an exchange request. hr = 0x%x", hr));
ASSERT(FALSE);
}
break;
case IDC_ERROR_NO:
//
// Do nothing.
//
m_RefreshNeeded = false;
break;
}
//
// Always return error, so that DefWindowProc handles this message.
//
return E_FAIL;
}
/*------------------------------------------------------------------------------
GalListDialog_t::ShowSettingsAppOnError
Start PHSettings.exe app and take the user to the appropriate screen.
------------------------------------------------------------------------------*/
HRESULT
GalListDialog_t::ShowSettingsAppOnError (
void
)
{
//
// Select the screen ID to show.
//
WCHAR SettingsScreenName[MAX_PATH] = L"";
switch (m_ErrorMenuId)
{
case IDMB_YESNOTRYAGAIN:
StringCchCopy (
SettingsScreenName,
_countof(SettingsScreenName),
L"EditServerSettings"
);
break;
case IDMB_UPDATEPASSWORD:
StringCchCopy (
SettingsScreenName,
_countof(SettingsScreenName),
L"WindowsLogon"
);
break;
default:
return E_FAIL;
}
//
// Show settings app.
//
PROCESS_INFORMATION Info;
BOOL Result = CreateProcess(
L"PHSettings.exe",
SettingsScreenName,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
NULL,
&Info
);
if (Result == FALSE)
{
HRESULT hr = CommonUtilities_t::GetErrorFromWin32();
COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Failed to create PHSettings process. hr = 0x%x", hr));
return hr;
}
CloseHandle(Info.hThread);
CloseHandle(Info.hProcess);
return S_OK;
}
/*------------------------------------------------------------------------------
GalListDialog_t::OnCommand
Handles WM_COMMAND message.
------------------------------------------------------------------------------*/
HRESULT
GalListDialog_t::OnCommand (
WPARAM wParam
)
{
//
// Handle EN_UPDATE and SEL_CHANGE messages.
//
switch (HIWORD(wParam))
{
case EN_UPDATE:
return OnEditControlUpdate ();
case LBN_SELCHANGE:
return OnListBoxSelectionChange ();
}
//
// Handle button clicks.
//
UINT SearchTypeId;
switch (LOWORD(wParam))
{
case IDOK:
//
// Go back to the previous screen.
//
return PhInfoGlobalData_t::pPhInfoApp->GoBackToPreviousScreen ();
case IDC_FILTER_LASTNAME:
SearchTypeId = IDS_LABEL_LASTNAME;
m_FilterType = LastName;
break;
case IDC_FILTER_FIRSTNAME:
SearchTypeId = IDS_LABEL_FIRSTNAME;
m_FilterType = FirstName;
break;
case IDC_FILTER_ALIAS:
SearchTypeId = IDS_LABEL_ALIAS;
m_FilterType = Alias;
break;
case IDC_DETAILS:
return OnDetails ();
case IDC_DIAL:
return OnDial ();
case IDC_BACKSPACE:
return OnBackspace ();
default:
//
// We do not want to handle this.
//
return E_FAIL;
}
return UpdateSearchInputListBoxTitle (SearchTypeId);
}
/*------------------------------------------------------------------------------
GalListDialog_t::GetSelectedGAL
Get GAL entry associated with the list box item selected by the user.
------------------------------------------------------------------------------*/
HRESULT
GalListDialog_t::GetSelectedGAL(
IExchangeClientGALSearchInformation** ppGAL
)
{
ASSERT (ppGAL);
*ppGAL = NULL;
int SelectedIndex = m_Listbox.GetCurSel();
if (SelectedIndex <= 0)
{
ASSERT(FALSE);
return E_FAIL;
}
IVoIPDisplayItem* pContactRecordDisplay = reinterpret_cast<IVoIPDisplayItem*> (m_Listbox.GetItem(SelectedIndex));
if (pContactRecordDisplay == NULL)
{
return E_POINTER;
}
IVoIPTextDisplayItem* pTextItem = NULL;
pContactRecordDisplay->QueryInterface(IID_IVoIPTextDisplayItem, (void**)&pTextItem);
if (!pTextItem)
{
ASSERT(FALSE);
return E_FAIL;
}
return pTextItem->GetComPtr(reinterpret_cast<IUnknown**>(ppGAL));
}
/*------------------------------------------------------------------------------
GalListDialog_t::OnGALntryDetails
Display GAL details.
------------------------------------------------------------------------------*/
HRESULT
GalListDialog_t::OnDetails (
void
)
{
CComPtr<IExchangeClientGALSearchInformation> cpGAL = NULL;
HRESULT hr = GetSelectedGAL (&cpGAL);
if (FAILED(hr))
{
ASSERT(FALSE);
return hr;
}
//
// When we come back from details screen, we don't want to refresh the GAL list.
//
m_RefreshNeeded = false;
return PhInfoGlobalData_t::pPhInfoApp->CreateDetailsScreen(
InfoApp_t::IdGalContactDetailsDialog,
cpGAL
);
}
/*------------------------------------------------------------------------------
GalListDialog_t::OnExchangeQueryCompleted
This function handles WM_EXCHANGE_QUERY_COMPLETED message it recieved from InfoApp
------------------------------------------------------------------------------*/
HRESULT
GalListDialog_t::OnExchangeQueryProgress(
IExchangeClientRequest* piRequest,
ExchangeClientRequestStatus Status
)
{
//
// Check if this is our request.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -