📄 homescreen.cpp
字号:
HomeScreen_t::OnTimer
Updates the Time text if necessary (delta is 1 minute)
------------------------------------------------------------------------------*/
LRESULT
HomeScreen_t::OnTimer(
UINT TimerId,
TIMERPROC* pTimerProc
)
{
LRESULT Result = 0;
if (TimerId == reinterpret_cast<UINT>(&m_MainTimerId))
{
SYSTEMTIME Time;
GetLocalTime(&Time);
if (HasTimeChanged(&Time))
{
memcpy(
&m_LastUpdated.wHour,
&Time.wHour,
reinterpret_cast<BYTE*>(&m_LastUpdated + 1) - reinterpret_cast<BYTE*>(&m_LastUpdated.wHour)
);
SetHomeScreenText(TextTime);
}
if (HasDateChanged(&Time))
{
memcpy(
&m_LastUpdated,
&Time,
reinterpret_cast<BYTE*>(&m_LastUpdated.wHour) - reinterpret_cast<BYTE*>(&m_LastUpdated)
);
SetHomeScreenText(TextDate);
}
}
else if (TimerId == reinterpret_cast<UINT>(&m_AutoHandledTimerId))
{
KillTimer(m_hwnd, m_AutoHandledTimerId);
m_AutoHandledTimerId = 0;
// Reset auto-handled notification
m_AutoHandledCallState = 0;
SetHomeScreenText(TextInformational);
}
else
{
ASSERT(0);
Result = 1;
}
return Result;
}
/*------------------------------------------------------------------------------
HomeScreen_t::OnHibernate
Release some cached resouces when we get WM_HIBERNATE message
------------------------------------------------------------------------------*/
LRESULT
HomeScreen_t::OnHibernate(
void
)
{
GlobalData_t::s_GDICacheObject.Reset();
return 0;
}
/*------------------------------------------------------------------------------
HomeScreen_t::RegisterNotifications
Registers for registry change notifications (sc_RegistrySettings)
------------------------------------------------------------------------------*/
void
HomeScreen_t::RegisterNotifications(
void
)
{
int Index;
for (Index = 0; Index < _countof(m_Notifications); Index++)
{
HRESULT hr = RegistryNotifyWindow(
sc_RegistrySettings[Index].m_Key,
sc_RegistrySettings[Index].m_pSubKey,
sc_RegistrySettings[Index].m_pValue,
m_hwnd,
WM_HOMESCREEN_REGISTRYCHANGE,
Index,
NULL,
&m_Notifications[Index]
);
ASSERT(SUCCEEDED(hr));
}
return;
}
/*------------------------------------------------------------------------------
HomeScreen_t::SetState
Updates the current state (enables / disables a flag bit).
------------------------------------------------------------------------------*/
//inline
void
HomeScreen_t::SetState(
DWORD Flag,
bool Set
)
{
if (Set)
{
m_State |= Flag;
}
else
{
m_State &= ~Flag;
}
return;
}
/*------------------------------------------------------------------------------
HomeScreen_t::UnRegisterNotifications
Unregisters registry change notifications.
------------------------------------------------------------------------------*/
void
HomeScreen_t::UnRegisterNotifications(
void
)
{
int Index;
for (Index = 0; Index < _countof(m_Notifications); Index++)
{
if (m_Notifications[Index])
{
RegistryCloseNotification(m_Notifications[Index]);
m_Notifications[Index] = NULL;
}
}
return;
}
/*------------------------------------------------------------------------------
HomeScreen_t::SetHomeScreenText
Sets the specified text in the Home Screen
------------------------------------------------------------------------------*/
HRESULT
HomeScreen_t::SetHomeScreenText(
TextId_e Id
)
{
typedef void (HomeScreen_t::*pfnGetText)(ce::wstring&);
PREFAST_SUPPRESS(5434, "Pointers to GetText functions (there is no intended call to members)");
const pfnGetText c_GetSubItemText[] =
{
HomeScreen_t::GetMainText,
HomeScreen_t::GetSubText,
HomeScreen_t::GetDateText,
HomeScreen_t::GetTimeText,
HomeScreen_t::GetAutoHandledCallText,
HomeScreen_t::GetStatusText,
};
HRESULT hr;
ce::wstring Buffer;
TransparentTextBox_t TextBox;
Buffer.reserve(MAX_PATH);
switch (Id)
{
case TextMain:
case TextSub:
case TextDate:
case TextTime:
TextBox = GetDlgItem(m_hwnd, sc_MappingTextInfo[Id].m_ControlId);
(this->*(c_GetSubItemText[Id]))(Buffer);
hr = TextBox.SetText(Buffer);
ASSERT(SUCCEEDED(hr));
break;
case TextInformational:
//we always want the "informational" text at the bottom of the screen
//either error/status of registration OR auto-handled call text.
//If both of these strings are present, we want to draw first the
//auto-handled call then then status string text
TextBox = GetDlgItem(m_hwnd, sc_MappingTextInfo[Id].m_ControlId);
GetStatusText(Buffer);
if (Buffer.length())
{
hr = TextBox.SetText(Buffer);
ASSERT(SUCCEEDED(hr));
Id = TextInformational2;
}
//Auto-handled text (e.g. "Call from 12345 was forwarded/blocked etc")
TextBox = GetDlgItem(m_hwnd, sc_MappingTextInfo[Id].m_ControlId);
GetAutoHandledCallText(Buffer);
hr = TextBox.SetText(Buffer);
ASSERT(SUCCEEDED(hr));
if (Id == TextInformational1)
{
TextBox = GetDlgItem(m_hwnd, sc_MappingTextInfo[TextInformational2].m_ControlId);
hr = TextBox.SetText(L"");
ASSERT(SUCCEEDED(hr));
}
break;
default:
ASSERT(0);
hr = E_INVALIDARG;
break;
}
return hr;
}
/*------------------------------------------------------------------------------
HomeScreen_t::AuthenticateLaunch
Try to launch a request on behalf of the user. If the device is locked,
show the user the "unlock" screen.
------------------------------------------------------------------------------*/
HRESULT
HomeScreen_t::AuthenticateLaunch(
AuthLaunchRequest_e Request
)
{
CloseHelpMessage();
//is the device locked?
if (PHGetSetting(phsDeviceLocked))
{
//device is locked - remember what we are going to unlock...
m_CurrentAuthRequest = Request;
//start the unlock dialog if we are not running...
if (! m_UnlockDialog.IsValid())
{
return m_UnlockDialog.Start(
WM_HOMESCREEN_UNLOCKREQUESTCOMPLETE,
m_hwnd
);
}
else
{
SetForegroundWindow(m_UnlockDialog);
//already a window - take ownership!
return m_UnlockDialog.SetNotificationParameters(
WM_HOMESCREEN_UNLOCKREQUESTCOMPLETE,
m_hwnd
);
}
return S_OK;
}
//device is unlocked! - run the request
return OnRequestAuthenticated(Request);
}
LRESULT
HomeScreen_t::OnAuthenticateUser(
UINT NotificationMessage,
HWND NotificationWindow
)
{
if (! NotificationMessage || ! IsWindow(NotificationWindow))
{
return NULL;
}
//reset our internal state
m_CurrentAuthRequest = LaunchInvalid;
//update the notification parameters if the window is already running
if (m_UnlockDialog.IsValid())
{
HRESULT hr = m_UnlockDialog.SetNotificationParameters(
NotificationMessage,
NotificationWindow
);
if (SUCCEEDED(hr))
{
SetForegroundWindow(m_UnlockDialog);
}
return hr;
}
//Start a new request for the caller
return m_UnlockDialog.Start(
NotificationMessage,
NotificationWindow
);
}
/*------------------------------------------------------------------------------
HomeScreen_t::OnRequestAuthenticated
Launch the correct app now that we are sure the user
is authenticated
------------------------------------------------------------------------------*/
HRESULT
HomeScreen_t::OnRequestAuthenticated(
AuthLaunchRequest_e Request
)
{
switch (Request)
{
case LaunchHomescreen:
SetForegroundWindow(m_hwnd);
return S_OK;
case LaunchSettings:
return PHSendCommandLine(
phaSettingsApp,
L""
);
case LaunchDirectory:
return PHSendCommandLine(
phaContactsApp,
L""
);
case LaunchMissedCalls:
return PHSendCommandLine(
phaContactsApp,
L"missed"
);
case LaunchSpeedDial:
return PHSendCommandLine(
phaContactsApp,
L"speeddial"
);
case LaunchCancelSetting:
if (PHGetSetting(phsDoNotDisturb))
{
PHSetValue(phsDoNotDisturb, 0);
}
if (PHGetSetting(phsCallForwarding))
{
PHSetValue(phsCallForwarding, 0);
}
return S_OK;
case LaunchInvalid:
default:
ASSERT(FALSE);
return E_INVALIDARG;
}
return S_OK;
}
/*------------------------------------------------------------------------------
HomeScreen_t::LockDevice
Lock the device for the user. If the user doesn't have a PIN set,
go to the SetPIN screen in settings
------------------------------------------------------------------------------*/
HRESULT
HomeScreen_t::LockDevice(
void
)
{
WCHAR CurrentPIN[10] = L"";
HRESULT hr = PHReadPIN(
CurrentPIN,
_countof(CurrentPIN)
);
if (SUCCEEDED(hr) && CurrentPIN[0])
{
hr = PHSetValue(phsDeviceLocked, 1);
RefreshMenuButtons();
return hr;
}
PHSetValue(phsLockPhoneAfterUpdatingPIN, 1);
return PHSendCommandLine(
phaSettingsApp,
L"SetPin"
);
}
/*------------------------------------------------------------------------------
HomeScreen_t::NotifyUnlockRequestComplete
Handles notification from the unlock dialog that
the unlock request is complete.
------------------------------------------------------------------------------*/
void
HomeScreen_t::OnUnlockRequestComplete(
AuthenticationResult_e Result
)
{
if (Result == AuthSucceeded)
{
OnRequestAuthenticated(m_CurrentAuthRequest);
}
//reset our auth status
m_CurrentAuthRequest = LaunchInvalid;
return;
}
#include "IpHlpApi.h"
/*------------------------------------------------------------------------------
GetMyIPAddress
Helper API to obtain the IP Address.
------------------------------------------------------------------------------*/
HRESULT
GetMyIPAddress(
WCHAR* pBuffer,
int cchBuffer
)
{
IP_ADAPTER_INFO* pInfo = NULL;
ULONG len = 0;
HRESULT hr = S_OK;
IP_ADDR_STRING* paddrString = NULL;
CHAR myaddr[4*4] = "";
GetAdaptersInfo(pInfo, &len);
if (len == 0)
{
ASSERT(FALSE);
hr = CommonUtilities_t::GetErrorFromWin32();
goto exit;
}
pInfo = (IP_ADAPTER_INFO*)TrackAlloc(len);
if (! pInfo)
{
hr = E_OUTOFMEMORY;
goto exit;
}
if (GetAdaptersInfo(pInfo, &len) != NO_ERROR)
{
hr = E_FAIL;
goto exit;
}
paddrString = pInfo->CurrentIpAddress;
if (! paddrString)
{
hr = E_FAIL;
goto exit;
}
StringCchCopyA(myaddr, _countof(myaddr), paddrString->IpAddress.String);
if (
! MultiByteToWideChar(
CP_ACP,
0,
myaddr,
-1,
pBuffer,
cchBuffer
)
)
{
hr = CommonUtilities_t::GetErrorFromWin32();
goto exit;
}
exit:
if (pInfo)
{
TrackFree(pInfo);
}
if (FAILED(hr))
{
StringCchCopyW(pBuffer, cchBuffer, L"0.0.0.0");
hr = S_FALSE;
}
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -