📄 windowslogon.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 "WindowsLogon.hpp"
#include "settingsApp.hpp"
#include "resource.h"
#include "ControlDefinitions.h"
#include <Controls.hpp>
#include <PaintHelper.hpp>
#include <windowsx.h>
#include "Layout.hpp"
#include "Cred.h"
#include "sspi.h"
#include "VoIPNotify.hpp"
#include "Input.hpp"
#include <sipapi.h>
PTCHAR c_szSspiPackageName = TEXT("KERBEROS");
/*------------------------------------------------------------------------------
GetControlText
Helper function to dynamically get the text from a control
Parameters:
Control: IN - HWND representing the control we are getting text from
String: Wstring (auto-obj) to be filled with the text
Returns (HRESULT): indicating success or failure
------------------------------------------------------------------------------*/
HRESULT
GetControlText(
HWND Control,
ce::wstring& String
)
{
String.clear();
if (! IsWindow(Control))
{
ASSERT(FALSE);
return E_INVALIDARG;
}
int Length = GetWindowTextLength(Control);
if (! Length)
{
return S_OK;
}
//reserve enough space for the string and null-terminator
if (! String.reserve(Length + 1))
{
return E_OUTOFMEMORY;
}
GetWindowText(
Control,
String.get_buffer(),
String.capacity()
);
return S_OK;
}
WindowsLogonDialog_t::WindowsLogonDialog_t()
{
m_ErrorDialog = NULL;
m_HelpDialog = NULL;
m_Control = NULL;
m_OriginalLowestYValue = 0;
m_LowestYValue = 0;
m_InputPanelStatus = FALSE;
}
WindowsLogonDialog_t::~WindowsLogonDialog_t()
{
if (m_ErrorDialog)
{
DestroyWindow(m_ErrorDialog);
}
if (m_HelpDialog)
{
DestroyWindow(m_HelpDialog);
}
}
const WCHAR*
WindowsLogonDialog_t::GetWindowClassName(
void
)
{
return WNDCLASS_WINDOWSLOGON;
}
HRESULT
WindowsLogonDialog_t::CreateDialogScreen(
)
{
HWND Dialog;
HRESULT hr = Create(
MAKEINTRESOURCE(IDD_WINDOWSLOGONDIALOG),
NULL,
dtModelessDialog,
NULL,
&Dialog
);
if (FAILED(hr))
{
return hr;
}
ASSERT(m_hwnd == Dialog);
return S_OK;
}
HWND WindowsLogonDialog_t::GetDialog()
{
return m_hwnd;
}
BOOL
WindowsLogonDialog_t::DialogWindowProc(
UINT Message,
WPARAM wParam,
LPARAM lParam,
bool& Handled
)
{
Handled = true;
switch (Message)
{
case WM_INITDIALOG:
if (FAILED(OnInitDialog()))
{
DestroyWindow(m_hwnd);
}
return FALSE;
case WM_ERASEBKGND:
return LogoScreen_t::OnEraseBackground(
m_hwnd,
IDB_LOGO_BIG,
reinterpret_cast<HDC>(wParam),
lParam
);
case WM_COMMAND:
return SUCCEEDED(OnCommand(
LOWORD(wParam),
HIWORD(wParam),
reinterpret_cast<HWND>(lParam)
));
case WM_PAINT:
return LogoScreen_t::OnPaint(
m_hwnd
);
case WM_KEYDOWN:
OnKeyDown(wParam);
return FALSE;
case WM_SETTINGCHANGE:
Input_HandleEvent(
Input_t::ieWMSettingChanged,
reinterpret_cast<Input_t::IPARAM>(wParam)
);
OnSettingsChange(wParam);
return 0;
case WM_SETFOCUS:
SetFocus(m_Control);
break;
case WM_COMMON_GET_INPUT_PANEL_STATUS:
return m_InputPanelStatus;
case WM_COMMON_SET_INPUT_PANEL_STATUS:
m_InputPanelStatus = static_cast<BOOL>(wParam);
return 0;
case WM_HELP:
return SUCCEEDED(OnHelp());
case WM_NOTIFY:
switch(wParam)
{
case IDC_CRED_DOMAIN:
case IDC_CRED_USERNAME:
case IDC_CRED_PASSWORD:
{
NMHDR *pHdr = reinterpret_cast<NMHDR*>(lParam);
if (pHdr && pHdr->code == VNM_SETFOCUS)
{
m_Control = pHdr->hwndFrom;
}
}
break;
case IDC_ERRORMSG_OK:
DestroyWindow(m_ErrorDialog);
m_ErrorDialog = NULL;
SetFocus(m_Control);
break;
case IDC_HELPMSG_OK:
DestroyWindow(m_HelpDialog);
m_HelpDialog = NULL;
SetFocus(m_Control);
break;
}
break;
}
return FALSE;
}
HRESULT
WindowsLogonDialog_t::OnInitDialog()
{
m_UserNameEdit = GetDlgItem(m_hwnd, IDC_CRED_USERNAME);
m_PasswordEdit = GetDlgItem(m_hwnd, IDC_CRED_PASSWORD);
m_DomainEdit = GetDlgItem(m_hwnd, IDC_CRED_DOMAIN);
InitializeEditControls();
m_MenuBar = GetDlgItem(m_hwnd, IDC_MENUBAR);
m_MenuBar.SetMenu(
GlobalData_t::s_ModuleInstance,
IDMB_WINDOWSLOGON_BACKSPACE_DONE_BUTTONS
);
UpdateMenuBar();
//cache the Y Position of each control
HWND Control;
RECT Rect = {0};
for (int i = 0; i < _countof(c_LogonControls); i++)
{
Control = GetDlgItem(m_hwnd, c_LogonControls[i]);
if (! Control)
{
ASSERT(FALSE);
continue;
}
GetWindowRect(
Control,
&Rect
);
//track the lowest control
if (Rect.bottom > m_LowestYValue)
{
m_LowestYValue = Rect.bottom;
}
}
m_OriginalLowestYValue = m_LowestYValue;
return S_OK;
}
LRESULT
WindowsLogonDialog_t::OnCommand(
WORD CommandId,
WORD NotifyCode,
HWND Control
)
{
LRESULT hr;
switch (NotifyCode)
{
case EN_UPDATE:
case EN_SETFOCUS:
UpdateMenuBar();
break;
}
switch (CommandId)
{
case IDOK:
hr = OnOK();
if (FAILED(hr))
{
return hr;
}
GetSettingsApp()->GoBackToPreviousScreen();
return S_OK;
case IDCANCEL:
GetSettingsApp()->GoBackToPreviousScreen();
return S_OK;
case IDC_BACKSPACE:
SendMessage(
GetFocus(),
WM_CHAR,
L'\b',
0
);
return S_OK;
default:
return E_NOTIMPL;
}
}
VOID
WindowsLogonDialog_t::OnKeyDown(
int Keycode
)
{
if (Keycode != VK_UP && Keycode != VK_DOWN)
{
return;
}
HWND Focus = GetFocus();
HWND NewFocus = NULL;
if (Focus == m_UserNameEdit)
{
NewFocus = (Keycode == VK_UP) ? m_DomainEdit : m_PasswordEdit;
}
else if (Focus == m_PasswordEdit)
{
NewFocus = (Keycode == VK_UP) ? m_UserNameEdit : m_DomainEdit;
}
else
{
NewFocus = (Keycode == VK_UP) ? m_PasswordEdit : m_UserNameEdit;
}
SetFocus(NewFocus);
UpdateMenuBar();
return;
}
void
WindowsLogonDialog_t::OnSettingsChange(
WPARAM wParam
)
{
if ((wParam != SPI_SETSIPINFO) && (wParam != SPI_SIPMOVE))
{
return;
}
int ShiftValue = 0;
BOOL IsSIPVisible = Input_IsInputPanelVisible();
int InputPanelTop = 0;
if (IsSIPVisible)
{
InputPanelTop = Input_GetInputPanelTop();
//if the input panel is lower than our window,
//we don't need to do anything
if (InputPanelTop > m_OriginalLowestYValue)
{
IsSIPVisible = false;
}
}
if (IsSIPVisible)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -