📄 enterpin.cpp
字号:
}
hr = PHReadPIN(
m_CurrentPin.get_buffer(),
m_CurrentPin.capacity()
);
if (FAILED(hr))
{
ASSERT(FALSE);
return hr;
}
if (m_CurrentPin.length() != m_EditControls.size())
{
ASSERT(! L"Current Pin is not available or not the right length - failing creation");
return E_FAIL;
}
//set up our menu bar
m_MenuBar = GetDlgItem(m_hwnd, IDC_MENUBAR);
m_MenuBar.SetMenu(GlobalData_t::s_ModuleInstance, IDMB_ENTERPIN_MENU);
//hide the backspace button
m_MenuBar.ShowMenuButton(IDM_BACKSPACE, FALSE);
//give focus to the first control
SetFocus(m_EditControls[0]);
return S_OK;
}
/*------------------------------------------------------------------------------
EnterPinDialog_t::OnSetNotificationParameters
Set the notification parameters for this window and notify the
old owner that its request was cancelled
------------------------------------------------------------------------------*/
HRESULT
EnterPinDialog_t::OnSetNotificationParameters(
UINT NotificationMessage,
HWND NotificationWindow
)
{
if (! IsWindow(NotificationWindow))
{
return E_HANDLE;
}
//if our existing window is there, notify them that
//we aren't tracking them anymore...
if (IsWindow(m_NotificationWindow) && m_NotificationWindow != NotificationWindow)
{
SendMessage(
m_NotificationWindow,
m_NotificationMessage,
AuthCanceled,
0
);
}
m_NotificationWindow = NotificationWindow;
m_NotificationMessage = NotificationMessage;
return S_OK;
}
/*------------------------------------------------------------------------------
EnterPinDialog_t::OnCancelAuthRequest
Cancel the current auth request for the request owner
------------------------------------------------------------------------------*/
LRESULT
EnterPinDialog_t::OnCancelAuthRequest(
HWND hwnd
)
{
if (m_NotificationWindow != hwnd)
{
return E_FAIL;
}
m_NotificationWindow = NULL;
OnDone(AuthCanceled);
return S_OK;
}
/*------------------------------------------------------------------------------
EnterPinDialog_t::OnCommand
Process WM_COMMAND messages
------------------------------------------------------------------------------*/
LRESULT
EnterPinDialog_t::OnCommand(
WORD CommandId,
WORD NotifyCode,
HWND Control
)
{
switch (NotifyCode)
{
case EN_CHANGE:
case EN_SETFOCUS:
OnEditUpdate();
break;
}
switch (CommandId)
{
case IDCANCEL:
OnDone(AuthCanceled);
return 0;
case IDM_BACKSPACE:
OnBackspace();
return 0;
default:
return 0;
}
}
/*------------------------------------------------------------------------------
EnterPinDialog_t::OnEditUpdate
Handle our edit control updating
------------------------------------------------------------------------------*/
void
EnterPinDialog_t::OnEditUpdate()
{
//check which control should have focus...
WCHAR Text[2] = L"";
ce::wstring TypedValue;
int Index;
//give focus to the correct control (first in the series without focus)
for (Index = 0; Index < m_EditControls.size(); Index++)
{
HWND Edit = m_EditControls[Index];
GetWindowText(Edit, Text, _countof(Text));
if (! Text[0])
{
if (Edit != GetFocus())
{
SetFocus(Edit);
m_MenuBar.ShowMenuButton(IDM_BACKSPACE, Index != 0);
}
return;
}
//save the value
if (! TypedValue.append(Text[0]))
{
//OOM!
return;
}
}
//check that the pins match
if (wcscmp(m_CurrentPin, TypedValue) == 0)
{
OnDone(AuthSucceeded);
return;
}
//Wrong! reset the typed value
for (Index = 0; Index < m_EditControls.size(); Index++)
{
SetWindowText(m_EditControls[Index], L"");
}
//hide the backspace button
m_MenuBar.ShowMenuButton(IDM_BACKSPACE, FALSE);
//show the error message...
ShowMessageBox(IDS_TITLE_ERROR, IDS_ERROR_WRONGPIN);
return;
}
/*------------------------------------------------------------------------------
EnterPinDialog_t::OnBackspace
Handle the backspace request from the user
------------------------------------------------------------------------------*/
void
EnterPinDialog_t::OnBackspace()
{
LONG CurrentId = GetWindowID(GetFocus());
int Index = CurrentId - IDC_PINEDIT1;
if (Index < 0 || Index >= m_EditControls.size())
{
//focus isn't a valid edit control...reset it
OnEditUpdate();
return;
}
BOOL ShowBackspaceButton;
if (Index == 0)
{
//clear this control
SetWindowText(m_EditControls[Index], L"");
ShowBackspaceButton = FALSE;
}
else
{
//clear the previous control and set text
SetWindowText(m_EditControls[Index - 1], L"");
SetFocus(m_EditControls[Index - 1]);
ShowBackspaceButton = ((Index - 1) > 0);
}
m_MenuBar.ShowMenuButton(IDM_BACKSPACE, ShowBackspaceButton);
return;
}
/*------------------------------------------------------------------------------
EnterPinDialog_t::ShowMessageBox
Show an error or help message box
------------------------------------------------------------------------------*/
void
EnterPinDialog_t::ShowMessageBox(
UINT TitleId,
UINT MessageId
)
{
CloseMessageBox();
PH_MESSAGE_BOX_PARAMETERS Params = {0};
Params.StructSize = sizeof(Params);
Params.Flags = VDF_TYPE_MODELESS;
Params.Owner = m_hwnd;
Params.Instance = GlobalData_t::s_ModuleInstance;
Params.pTitle = MAKEINTRESOURCE(TitleId);
Params.pText = MAKEINTRESOURCE(MessageId);
Params.IconId = IDB_MESSAGEBOX;
Params.MenuId = IDMB_OK;
if (! PHMessageBox(&Params))
{
ASSERT(FALSE);
return;
}
m_MessageBox = Params.result.Dialog;
return;
}
/*------------------------------------------------------------------------------
EnterPinDialog_t::CloseMessageBox
Close the currently active message box
------------------------------------------------------------------------------*/
void
EnterPinDialog_t::CloseMessageBox()
{
if (m_MessageBox)
{
DestroyWindow(m_MessageBox);
m_MessageBox = NULL;
}
}
/*------------------------------------------------------------------------------
EnterPinDialog_t::OnDone
Exit out of this screen and notify the homescreen
------------------------------------------------------------------------------*/
void
EnterPinDialog_t::OnDone(
AuthenticationResult_e Result
)
{
if (m_NotifiedOwner)
{
return;
}
m_NotifiedOwner = true;
if (Result == AuthSucceeded)
{
PHSetValue(phsDeviceLocked, 0);
}
if (IsWindow(m_NotificationWindow))
{
SendMessage(
m_NotificationWindow,
m_NotificationMessage,
static_cast<WPARAM>(Result),
0
);
}
End();
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -