📄 homescreen.cpp
字号:
}
else
{
if ((m_LastHotKey == HotKeyId) && !IsPressAndHold)
{
return 0;
}
m_LastHotKey = HotKeyId;
}
HRESULT hr;
HWND ForegroundWindow = GetForegroundWindow();
switch (vkHotKey)
{
case HotKeys_t::vkHome:
{
//force the existing lock dialog closed...
if (m_UnlockDialog.IsValid())
{
m_CurrentAuthRequest = LaunchInvalid;
m_UnlockDialog.End();
}
DWORD PhoneAppState = PHGetSetting(phsPhoneAppStatus);
if (PhoneAppState & VOIP_PHONEAPP_ACTIVE_BITMASK)
{
// Bring up the dialer screen when active
if (GetWindowLong(ForegroundWindow, GWL_ID) != PHONEAPP_DIALER_SCREEN_ID)
{
PHSendCommandLine(phaPhoneApp, L"");
}
}
else
{
// Otherwise bring the Home Screen to the foreground.
SetForegroundWindow(m_hwnd);
}
}
break;
case HotKeys_t::vkMenu:
if (IsPressAndHold)
{
PostMessage(ForegroundWindow, WM_HELP, 0, 0);
}
else if (Modifiers & MOD_KEYUP)
{
hr = AuthenticateLaunch(LaunchSettings);
}
else
{
NeedToWaitForPressAndHold = true;
}
break;
case HotKeys_t::vkButton1:
case HotKeys_t::vkButton2:
case HotKeys_t::vkButton3:
case HotKeys_t::vkButton4:
{
HWND MenuButton = GetDlgItem(
ForegroundWindow,
(IDC_BUTTON1 + (vkHotKey - HotKeys_t::vkButton1))
);
if (IsWindowVisible(MenuButton) &&
CommonUtilities_t::ControlTypeMenuButton ==
CommonUtilities_t::GetControlType(MenuButton))
{
PostMessage(MenuButton, WM_LBUTTONDOWN, 0, 0);
PostMessage(MenuButton, WM_LBUTTONUP, 0, 0);
}
}
break;
case HotKeys_t::vkDirectory:
hr = AuthenticateLaunch(LaunchDirectory);
break;
case HotKeys_t::vkSpeedDial:
hr = AuthenticateLaunch(LaunchSpeedDial);
break;
case HotKeys_t::vkVolumeUp:
case HotKeys_t::vkVolumeDown:
if (GetWindowLong(ForegroundWindow, GWL_ID) == PHSETTINGS_VOLUMESETTINGS_SCREEN_ID)
{
UINT vVolumeKey = (vkHotKey == HotKeys_t::vkVolumeUp) ? VK_UP : VK_DOWN;
SendMessage(
ForegroundWindow,
WM_HOTKEY,
0,
MAKELPARAM(0, vVolumeKey)
);
}
else
{
//get current active volume mode
PHVolumeSetting VolumeMode = (PHGetActiveVolume() == RingerVolumeMode) ?
phvsRingerVolume : phvsSpeakerVolume;
//get active volume
int ActiveVolume = static_cast<int>(PHGetVolumeSetting(VolumeMode));
//increase or descrase the volume
ActiveVolume += (vkHotKey == HotKeys_t::vkVolumeUp) ? 1 : -1;
//round up the volume
ActiveVolume = max(min(ActiveVolume, static_cast<int>(c_MaxUIVolume)), 0);
//set the active volume
PHSetVolume(VolumeMode, static_cast<DWORD>(ActiveVolume));
}
break;
case HotKeys_t::vkShutdown:
ProcessMonitor_t::StopMonitoring();
//Terminate the phone app
PostMessage(
PHGetAppWindow(phaPhoneApp, FALSE),
WM_CLOSE,
0,
0
);
//Terminate HomeScreen
PostMessage(NULL, WM_CLOSE, 0, 0);
break;
}
if (m_State & WAITING_FOR_PRESS_AND_HOLD)
{
SetState(WAITING_FOR_PRESS_AND_HOLD, false);
}
if (NeedToWaitForPressAndHold)
{
m_PressAndHoldTimeout = GetTickCount() + sc_PressAndHoldTimeOut;
SetState(WAITING_FOR_PRESS_AND_HOLD, true);
}
return 0;
}
/*------------------------------------------------------------------------------
HomeScreen_t::OnInitDialog
Handle initialization of the Home Screen dialog.
------------------------------------------------------------------------------*/
LRESULT
HomeScreen_t::OnInitDialog(
HWND ControlToReceiveFocus,
void* pParameters
)
{
HRESULT hr;
//initialize the main and sub text
SetHomeScreenText(TextMain);
SetHomeScreenText(TextSub);
RegisterNotifications();
//Read settings from the registry
int Index;
for (Index = 0; Index < _countof(sc_RegistrySettings); Index++)
{
OnRegistrySettingsChange(Index);
}
hr = HotKeys_t::RegisterHotKeys(m_hwnd);
ASSERT(SUCCEEDED(hr));
TransparentTextBox_t TextBox;
for (Index = 0; Index < _countof(sc_MappingTextInfo); Index++)
{
TextBox = GetDlgItem(m_hwnd, sc_MappingTextInfo[Index].m_ControlId);
TextBox.SetFont(PHGetFont(sc_MappingTextInfo[Index].m_FontId));
if (Index == TextMain)
{
ce::auto_hdc hdc = GetDC(m_hwnd);
PaintHelper_t paint;
paint.Attach(hdc);
paint.SetFont(PHGetFont(sc_MappingTextInfo[Index].m_FontId));
TEXTMETRIC TextMetrics;
GetTextMetrics(paint, &TextMetrics);
RECT WindowRect;
GetWindowRect(TextBox, &WindowRect);
MapWindowRect(NULL, m_hwnd, &WindowRect);
m_DividerLinePosition = WindowRect.top + (TextMetrics.tmHeight - (TextMetrics.tmDescent/2));
paint.End();
}
}
{
#ifndef SHIP_BUILD
ce::wstring Buffer;
Buffer.reserve(MAX_PATH);
// Set top info (IP Address + Version)
HFONT InformationTextFont = PHGetFont(phfInformationText);
TextBox = GetDlgItem(m_hwnd, IDC_TEXT_IP_ADDRESS);
TextBox.SetFont(InformationTextFont);
GetMyIPAddress(Buffer.get_buffer(), Buffer.capacity());
hr = TextBox.SetText(Buffer);
ASSERT(SUCCEEDED(hr));
TextBox = GetDlgItem(m_hwnd, IDC_TEXT_CE_VERSION);
TextBox.SetFont(InformationTextFont);
StringCchPrintfW(
Buffer.get_buffer(),
Buffer.capacity(),
L"Windows CE %d.%d.%d",
CE_MAJOR_VER,
CE_MINOR_VER,
CE_BUILD_VER
);
hr = TextBox.SetText(Buffer);
ASSERT(SUCCEEDED(hr));
#endif
}
MenuBar_t MenuBar;
MenuBar = GetDlgItem(m_hwnd, IDC_MENUBAR);
MenuBar.SetMenu(
GlobalData_t::s_ModuleInstance,
IDMB_HOME_SCREEN_LOCK
);
//Cache the original command-button mapping
HMENU MenuHandle;
MenuHandle = MenuBar.GetMenuHandle();
MENUITEMINFO Info;
Info.cbSize = sizeof(MENUITEMINFO);
Info.fMask = MIIM_ID;
for (Index = 0; Index < MenuBar.GetMenuButtonCount(); Index++)
{
if (!GetMenuItemInfo(MenuHandle, Index, TRUE, &Info))
{
ASSERT(0);
continue;
}
switch (Info.wID)
{
case IDM_LOCK:
case IDM_UNLOCK:
m_MenuButtonMapping[ButtonLock] = Index;
break;
case IDM_SETTINGS:
m_MenuButtonMapping[ButtonSettings] = Index;
break;
case IDCANCEL:
m_MenuButtonMapping[ButtonCancel] = Index;
break;
case IDM_MISSED_CALLS:
m_MenuButtonMapping[ButtonMissedCalls] = Index;
break;
}
}
RefreshMenuButtons();
m_MainTimerId = SetTimer(
m_hwnd,
reinterpret_cast<UINT>(&m_MainTimerId),
sc_MainTimerTimeOut,
NULL
);
return FALSE;
}
/*------------------------------------------------------------------------------
HomeScreen_t::OnNotify
Handle notification messages
------------------------------------------------------------------------------*/
LRESULT
HomeScreen_t::OnNotify(
int ControlId,
__in NMHDR* pNotificationHeader
)
{
if (!pNotificationHeader)
{
return 0;
}
switch (ControlId)
{
case IDOK:
if (m_HelpMessageBox == GetParent(pNotificationHeader->hwndFrom))
{
CloseHelpMessage();
}
break;
}
return 0;
}
/*------------------------------------------------------------------------------
HomeScreen_t::OnRegistrySettingsChange
Handle registry change notifications
------------------------------------------------------------------------------*/
LRESULT
HomeScreen_t::OnRegistrySettingsChange(
LPARAM lParam
)
{
HRESULT hr;
DWORD Value = 0;
RegistrySetting_e Setting = static_cast<RegistrySetting_e>(lParam);
bool NeedToUpdateInformationalText = false;
bool NeedToUpdateMainText = false;
bool NeedToUpdateSubText = false;
bool NeedToUpdateMenuButtons = false;
switch (Setting)
{
case RegistrationStatus:
case AutoForwarding:
case DoNotDisturb:
NeedToUpdateMenuButtons = true;
NeedToUpdateInformationalText = true;
goto GetDWORDSetting;
case AutoHandledCall:
NeedToUpdateInformationalText = true;
goto GetDWORDSetting;
case MissedCalls:
case DeviceLocked:
NeedToUpdateMenuButtons = true;
GetDWORDSetting:
RegistryGetDWORD(
sc_RegistrySettings[Setting].m_Key,
sc_RegistrySettings[Setting].m_pSubKey,
sc_RegistrySettings[Setting].m_pValue,
&Value
);
switch (Setting)
{
case RegistrationStatus:
m_RegistrationStatus = Value;
break;
case AutoForwarding:
SetState(AUTOFORWARDING, (Value != 0));
break;
case DoNotDisturb:
SetState(DO_NOT_DISTURB, (Value != 0));
break;
case MissedCalls:
SetState(MISSED_CALLS, (Value != 0));
break;
case DeviceLocked:
SetState(DEVICE_LOCKED, (Value != 0));
break;
case AutoHandledCall:
m_AutoHandledCallState = Value;
if (m_AutoHandledCallState)
{
m_AutoHandledTimerId = SetTimer(
m_hwnd,
reinterpret_cast<UINT>(&m_AutoHandledTimerId),
sc_AutoHandledNotificationTimeOut,
NULL
);
}
break;
}
break;
case AutoForwardingNumber:
case AutoHandledCallerId:
case SIPAccount:
case SIPAccountURI:
case LoginUserName:
{
ce::wstring* pBufferToUse;
switch (Setting)
{
case AutoForwardingNumber:
pBufferToUse = &m_AutoForwardingNumber;
NeedToUpdateInformationalText = true;
break;
case AutoHandledCallerId:
pBufferToUse = &m_AutoHandledCallerId;
NeedToUpdateInformationalText = true;
break;
case SIPAccount:
pBufferToUse = &m_SIPAccount;
NeedToUpdateMainText = true;
break;
case SIPAccountURI:
pBufferToUse = &m_SIPAccountURI;
NeedToUpdateMainText = true;
NeedToUpdateSubText = true;
break;
case LoginUserName:
pBufferToUse = &m_LoginUserName;
NeedToUpdateMainText = true;
break;
default:
ASSERT(0);
return 0;
}
// Be smart about the allocation needed
DWORD RegType;
DWORD SizeInBytes;
DWORD Error;
ce::auto_hkey SubKey;
Error = RegOpenKeyEx(
sc_RegistrySettings[Setting].m_Key,
const_cast<WCHAR*>(sc_RegistrySettings[Setting].m_pSubKey),
0, 0,
&SubKey
);
if (ERROR_SUCCESS != Error)
{
ASSERT(Error == ERROR_FILE_NOT_FOUND);
return 0;
}
Error = RegQueryValueEx(
SubKey,
sc_RegistrySettings[Setting].m_pValue,
NULL,
&RegType,
NULL,
&SizeInBytes
);
if (ERROR_SUCCESS != Error)
{
ASSERT(Error == ERROR_FILE_NOT_FOUND);
return 0;
}
pBufferToUse->reserve(SizeInBytes/sizeof(WCHAR));
pBufferToUse->clear();
hr = RegistryGetString(
sc_RegistrySettings[Setting].m_Key,
sc_RegistrySettings[Setting].m_pSubKey,
sc_RegistrySettings[Setting].m_pValue,
pBufferToUse->get_buffer(),
pBufferToUse->capacity()
);
ASSERT(SUCCEEDED(hr));
break;
}
default:
// We did not expect this notification
ASSERT(Setting < RegistrySettingLast);
return 0;
}
// Invalidate the main text
if (NeedToUpdateMainText)
{
SetHomeScreenText(TextMain);
}
// Invalidate the sub text
if (NeedToUpdateSubText)
{
SetHomeScreenText(TextSub);
}
// Invalidate the informational text
if (NeedToUpdateInformationalText)
{
SetHomeScreenText(TextInformational);
}
if (NeedToUpdateMenuButtons)
{
RefreshMenuButtons();
}
return 0;
}
/*------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -