<Window x:Class="XXX.Client.LockScreenView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Title="ClearLid" Height="484" Width="791"
WindowState="Maximized"
WindowStartupLocation="CenterScreen"
ShowInTaskbar="False"
Visibility="Visible"
Background="Transparent"
WindowStyle="None"
SizeChanged="WindowSizeChanged">
<Grid Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="15*"/>
<RowDefinition Height="35*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Canvas Grid.ColumnSpan="2" HorizontalAlignment="Center" Height="140" Margin="182,0,183,0" Grid.Row="1" VerticalAlignment="Top" Width="350" Name="MainCanvas" > <TextBlock Height="23" Canvas.Left="92" TextWrapping="Wrap" Text="User Name" Canvas.Top="25" Width="99" Foreground="White"/>
<TextBlock Height="23" Canvas.Left="191" Canvas.Top="22" Width="153" Name="txtUserName" Foreground="White"/>
<TextBlock Height="20" Canvas.Left="92" TextWrapping="Wrap" Text="Password" Canvas.Top="53" Width="75" Foreground="White"/>
<PasswordBox Height="20" Canvas.Left="191" Canvas.Top="53" Width="153" KeyboardNavigation.TabIndex="0" Name="txtPassword"/>
<Button Content="Switch User" Height="24" Canvas.Left="185" Canvas.Top="90" Width="75" Foreground="White" KeyboardNavigation.TabIndex="2" Click="OnLogOff" />
<Button Content="Login" Height="24" Canvas.Left="268" Canvas.Top="90" Width="75" Foreground="White" IsDefault="True" KeyboardNavigation.TabIndex="1" Name="btnLogin" Click="OnLogin" /> </Canvas>
</Grid>
</Window>
 public partial class LockScreenView : Window
{
public LockScreenView()
{
InitializeComponent(); // Create canvas border
m_canvasBorder = new Rectangle();
m_canvasBorder.Stroke = System.Windows.Media.Brushes.Red;
m_canvasBorder.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
m_canvasBorder.VerticalAlignment = System.Windows.VerticalAlignment.Top;
m_canvasBorder.RadiusX = m_canvasBorder.RadiusY = ;
Grid.SetColumnSpan(m_canvasBorder, );
Grid.SetRow(m_canvasBorder, ); MainGrid.Children.Add(m_canvasBorder); this.m_isEnableDWM = this.CheckDWM(); this.InitializeIOCtrl();
this.EnableLockScreen = true;
FocusManager.SetFocusedElement(this, this.txtPassword);
} private void OnLogin(object sender, RoutedEventArgs e)
{
if (AppClient.Instance.XXXService.VerifyUser(AppClient.Instance.ClientID, this.txtUserName.Text, this.txtPassword.Password))
{
AppClient.Instance.UserContext.CurrentLockCount = AppClient.Instance.UserContext.AutoLockCount;
AppClient.Instance.UserMode = UserMode.None;
this.EnableLockScreen = false;
this.Close();
}
else
{
txtPassword.Clear();
}
} private void OnLogOff(object sender, RoutedEventArgs e)
{ } protected override void OnClosed(EventArgs e)
{
if (this.m_event != null)
this.m_event.Close();
if (this.m_file != null)
this.m_file.Close(); base.OnClosed(e);
} private void WindowSizeChanged(object sender, SizeChangedEventArgs e)
{
var left = this.MainGrid.ColumnDefinitions[].ActualWidth - this.MainCanvas.ActualWidth / ;
var top = this.MainGrid.RowDefinitions[].ActualHeight;
var rect = new System.Drawing.Rectangle((int)left, (int)top, (int)this.MainCanvas.Width, (int)this.MainCanvas.Height); // Draw border
m_canvasBorder.Width = rect.Width;
m_canvasBorder.Height = rect.Height;
m_canvasBorder.Margin = new Thickness(, , , ); if (!this.m_isEnableDWM) return; // Obtain the window handle for WPF application
IntPtr mainWindowPtr = new WindowInteropHelper(this).Handle;
HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(, , , ); System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd(mainWindowPtr);
NativeMethods.DWM_BLURBEHIND blurBehind; blurBehind.dwFlags = NativeMethods.DWM_BB.Enable | NativeMethods.DWM_BB.BlurRegion;
blurBehind.fEnable = true;
blurBehind.fTransitionOnMaximized = false;
blurBehind.hRgnBlur = IntPtr.Zero; var rgn = RoundedRectangle.CreateRegion(rect);
blurBehind.hRgnBlur = rgn.GetHrgn(desktop); NativeMethods.DwmEnableBlurBehindWindow(mainWindowSrc.Handle, ref blurBehind); rgn.Dispose();
} private void InitializeIOCtrl()
{
var file = NativeMethods.CreateFile(NativeMethods.DOS_DEVICE_NAME,
NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE, , IntPtr.Zero, NativeMethods.OPEN_EXISTING, , IntPtr.Zero);
m_file = new SafeFileHandle(file, true); if (m_file.IsInvalid == false)
m_event = new ManualResetEvent(false);
}
private bool EnableLockScreen
{
set
{
if (value != m_isEnableLS)
{
if (value == true)
enableToolStripMenuItem_Click(this, new EventArgs());
else
disableToolStripMenuItem_Click(this, new EventArgs());
m_isEnableLS = value;
}
}
}
private void enableToolStripMenuItem_Click(object sender, EventArgs e)
{
if (m_file.IsInvalid == false)
{
uint bytesReturned = ; if (m_isSetFilterData == false)
{
unsafe
{
var ioCtrl = NativeMethods.CTL_CODE(
NativeMethods.FILE_DEVICE_KEYBOARD_FILTER,
NativeMethods.IOCTL_KEYBOARD_FILTER_SET_EVENT,
NativeMethods.METHOD_BUFFERED,
NativeMethods.FILE_ANY_ACCESS
); int handle = m_event.SafeWaitHandle.DangerousGetHandle().ToInt32();
int* pHandle = &handle; var ret = NativeMethods.DeviceIoControl(m_file.DangerousGetHandle(), ioCtrl, (IntPtr)(pHandle), , IntPtr.Zero, , out bytesReturned, IntPtr.Zero);
List<ushort[]> listFd = new List<ushort[]>();
listFd.Add(NativeMethods.GetSAS_L());
listFd.Add(NativeMethods.GetSAS_R());
listFd.Add(NativeMethods.GetTaskSwitch());
listFd.Add(NativeMethods.GetTaskSwitch3D_L());
listFd.Add(NativeMethods.GetTaskSwitch3D_R());
listFd.Add(NativeMethods.GetWin_L());
listFd.Add(NativeMethods.GetWin_R()); int size = listFd.Count * FILTER_DATA_LENGTH;
ushort* fd = stackalloc ushort[size];
ushort* tmp = fd; for (int i = ; i < listFd.Count; ++i)
{
for (int j = ; j < FILTER_DATA_LENGTH; ++j, ++tmp)
{
*tmp = listFd[i][j];
}
} ioCtrl = NativeMethods.CTL_CODE(
NativeMethods.FILE_DEVICE_KEYBOARD_FILTER,
NativeMethods.IOCTL_KEYBOARD_FILTER_SET_KEY,
NativeMethods.METHOD_BUFFERED,
NativeMethods.FILE_ANY_ACCESS
); ret = NativeMethods.DeviceIoControl(m_file.DangerousGetHandle(), ioCtrl, (IntPtr)(fd), (uint)size * , IntPtr.Zero, , out bytesReturned, IntPtr.Zero);
m_isSetFilterData = true;
}
}
m_event.Set();
}
}
private void disableToolStripMenuItem_Click(object sender, EventArgs e)
{
if (m_file.IsInvalid == false)
{
m_event.Reset();
}
}
private bool CheckDWM()
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= )
{
if (NativeMethods.DwmIsCompositionEnabled() == false)
return false;
else
return true;
}
else
return false;
} private SafeFileHandle m_file = null;
private ManualResetEvent m_event = null;
private bool m_isSetFilterData = false; // Indicate if filter data is sent to kernel
private bool m_isEnableLS = false;
private const int FILTER_DATA_LENGTH = ;
private bool m_isEnableDWM = false;
private Rectangle m_canvasBorder;
} internal class NativeMethods
{
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr CreateFile(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
IntPtr lpSecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
IntPtr hTemplateFile); [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool DeviceIoControl(
IntPtr hDevice,
uint dwIoControlCode,
IntPtr lpInBuffer,
uint nInBufferSize,
IntPtr lpOutBuffer,
uint nOutBufferSize,
out uint lpBytesReturned,
IntPtr lpOverlapped); [DllImport("dwmapi.dll", PreserveSig = false)]
public static extern bool DwmIsCompositionEnabled(); [DllImport("dwmapi.dll")]
public static extern void DwmEnableBlurBehindWindow(IntPtr hwnd, ref DWM_BLURBEHIND blurBehind); public static uint CTL_CODE(uint DeviceType, uint Function, uint Method, uint Access)
{
return ((DeviceType << ) | (Access << ) | (Function << ) | Method);
} public static ushort[] GetSAS_L()
{
var fd = new ushort[FILTER_DATA_LENGTH]; fd[] = KEY_CTRL;
fd[] = KEY_DEL;
fd[] = KEY_ALT;
fd[] = KEY_NUM; return fd;
} public static ushort[] GetSAS_R()
{
var fd = new ushort[FILTER_DATA_LENGTH]; fd[] = KEY_CTRL;
fd[] = KEY_DEL;
fd[] = KEY_ALT;
fd[] = KEY_NUM_PERIOD; return fd;
} public static ushort[] GetTaskSwitch()
{
var fd = new ushort[FILTER_DATA_LENGTH]; fd[] = KEY_ALT;
fd[] = KEY_TAB; return fd;
} public static ushort[] GetWin_L()
{
var fd = new ushort[FILTER_DATA_LENGTH]; fd[] = KEY_LWIN; return fd;
} public static ushort[] GetWin_R()
{
var fd = new ushort[FILTER_DATA_LENGTH]; fd[] = KEY_RWIN; return fd;
} public static ushort[] GetTaskSwitch3D_L()
{
var fd = new ushort[FILTER_DATA_LENGTH]; fd[] = KEY_LWIN;
fd[] = KEY_TAB; return fd;
} public static ushort[] GetTaskSwitch3D_R()
{
var fd = new ushort[FILTER_DATA_LENGTH]; fd[] = KEY_RWIN;
fd[] = KEY_TAB; return fd;
} [Flags]
public enum DWM_BB
{
Enable = ,
BlurRegion = ,
TransitionMaximized =
} [Flags]
public enum SendMessageTimeoutFlags
{
SMTO_NORMAL = 0x0,
SMTO_BLOCK = 0x1,
SMTO_ABORTIFHUNG = 0x2,
SMTO_NOTIMEOUTIFNOTHUNG = 0x8
} [StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Right;
public int Top;
public int Bottom;
}; [StructLayout(LayoutKind.Sequential)]
public struct DWM_BLURBEHIND
{
public DWM_BB dwFlags;
public bool fEnable;
public IntPtr hRgnBlur;
public bool fTransitionOnMaximized;
} public const short FILE_ATTRIBUTE_NORMAL = 0x80;
public const short INVALID_HANDLE_VALUE = -;
public const uint GENERIC_READ = 0x80000000;
public const uint GENERIC_WRITE = 0x40000000;
public const uint CREATE_NEW = ;
public const uint CREATE_ALWAYS = ;
public const uint OPEN_EXISTING = ; public const uint METHOD_BUFFERED = ;
public const uint METHOD_IN_DIRECT = ;
public const uint METHOD_OUT_DIRECT = ;
public const uint METHOD_NEITHER = ;
public const uint FILE_ANY_ACCESS = ;
public const uint FILE_READ_ACCESS = 0x0001;
public const uint FILE_WRITE_ACCESS = 0x0002; public const uint FILE_DEVICE_KEYBOARD_FILTER = 0x8000;
public const uint IOCTL_KEYBOARD_FILTER_SET_EVENT = ;
public const uint IOCTL_KEYBOARD_FILTER_CLEAR_EVENT = ;
public const uint IOCTL_KEYBOARD_FILTER_SET_KEY = ;
public const string DOS_DEVICE_NAME = "\\\\.\\aKbFilter"; public const int ERROR_TIMEOUT = ;
public const int ERROR_INVALID_WINDOW_HANDLE = ; public const int ERROR_SUCCESS = ;
public const int ERROR_LOGIN_FAIL = ;
public const int ERROR_INVALID_LOGIN = ;
public const int ERROR_INVALID_PWD = ;
public const int ERROR_INVALID_USERNAME = ; public const int MAX_NAME_PWD_LENGTH = ;
public const int MAX_TIME_OUT = ;
public const int MAX_PATH = ; private const int FILTER_DATA_LENGTH = ;
private const ushort KEY_CTRL = 0x1D;
private const ushort KEY_ALT = 0x38;
private const ushort KEY_DEL = 0x53;
private const ushort KEY_NUM = 0x2A;
private const ushort KEY_TAB = 0x0F;
private const ushort KEY_NUM_PERIOD = 0x53;
private const ushort KEY_LWIN = 0x5B;
private const ushort KEY_RWIN = 0x5C;
} public abstract class RoundedRectangle
{
public enum RectangleCorners
{
None = , TopLeft = , TopRight = , BottomLeft = , BottomRight = ,
All = TopLeft | TopRight | BottomLeft | BottomRight
} public static GraphicsPath Create(int x, int y, int width, int height,
int radius, RectangleCorners corners)
{
int xw = x + width;
int yh = y + height;
int xwr = xw - radius;
int yhr = yh - radius;
int xr = x + radius;
int yr = y + radius;
int r2 = radius * ;
int xwr2 = xw - r2;
int yhr2 = yh - r2; GraphicsPath p = new GraphicsPath();
p.StartFigure(); //Top Left Corner
if ((RectangleCorners.TopLeft & corners) == RectangleCorners.TopLeft)
{
p.AddArc(x, y, r2, r2, , );
}
else
{
p.AddLine(x, yr, x, y);
p.AddLine(x, y, xr, y);
} //Top Edge
p.AddLine(xr, y, xwr, y); //Top Right Corner
if ((RectangleCorners.TopRight & corners) == RectangleCorners.TopRight)
{
p.AddArc(xwr2, y, r2, r2, , );
}
else
{
p.AddLine(xwr, y, xw, y);
p.AddLine(xw, y, xw, yr);
} //Right Edge
p.AddLine(xw, yr, xw, yhr); //Bottom Right Corner
if ((RectangleCorners.BottomRight & corners) == RectangleCorners.BottomRight)
{
p.AddArc(xwr2, yhr2, r2, r2, , );
}
else
{
p.AddLine(xw, yhr, xw, yh);
p.AddLine(xw, yh, xwr, yh);
} //Bottom Edge
p.AddLine(xwr, yh, xr, yh); //Bottom Left Corner
if ((RectangleCorners.BottomLeft & corners) == RectangleCorners.BottomLeft)
{
p.AddArc(x, yhr2, r2, r2, , );
}
else
{
p.AddLine(xr, yh, x, yh);
p.AddLine(x, yh, x, yhr);
} //Left Edge
p.AddLine(x, yhr, x, yr); p.CloseFigure();
return p;
} public static GraphicsPath Create(System.Drawing.Rectangle rect, int radius, RectangleCorners c)
{ return Create(rect.X, rect.Y, rect.Width, rect.Height, radius, c); } public static GraphicsPath Create(int x, int y, int width, int height, int radius)
{ return Create(x, y, width, height, radius, RectangleCorners.All); } public static GraphicsPath Create(System.Drawing.Rectangle rect, int radius)
{ return Create(rect.X, rect.Y, rect.Width, rect.Height, radius); } public static GraphicsPath Create(int x, int y, int width, int height)
{ return Create(x, y, width, height, ); } public static GraphicsPath Create(System.Drawing.Rectangle rect)
{ return Create(rect.X, rect.Y, rect.Width, rect.Height); } public static System.Drawing.Region CreateRegion(System.Drawing.Rectangle rect)
{ return new System.Drawing.Region(Create(rect.X, rect.Y, rect.Width, rect.Height)); }
}
WindowCollection wins = Application.Current.Windows;
foreach (Window win in wins)
{
if (win is XXX.Client.MainView) continue;
win.Close();
}
AppClient.Instance.UserMode = UserMode.Lock;
LockScreenViewModel vm = new LockScreenViewModel();
WindowManager windowmanager = new WindowManager();
windowmanager.ShowDialog(vm);
AppClient.Instance.UserContext.CurrentLockCount = AppClient.Instance.UserContext.AutoLockCount;
if (this._view != null)
this._view.MouseMove += new MouseEventHandler(uc_MouseMove); if (autolocktimer == null)
{
this.autolocktimer = new System.Timers.Timer();
this.autolocktimer.Interval = ;
this.autolocktimer.Elapsed += new System.Timers.ElapsedEventHandler(autolocktimer_Elapsed);
this.autolocktimer.Start();
} private void uc_MouseMove(object sender, MouseEventArgs e)
{
AppClient.Instance.UserContext.CurrentLockCount = AppClient.Instance.UserContext.AutoLockCount;
} private void autolocktimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (Application.Current == null)
return; Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart)delegate
{
if (AppClient.Instance.UserMode != UserMode.Lock)
{
if (AppClient.Instance.UserContext.CurrentLockCount <= )
{
this.Lock();
}
AppClient.Instance.UserContext.CurrentLockCount--;
}
else
AppClient.Instance.UserContext.CurrentLockCount = AppClient.Instance.UserContext.AutoLockCount;
});
}

LockScreen的更多相关文章

  1. C# Windows Phone App 开发,自制LockScreen 锁定画面类别(Class),从【网路图片】、【Assets资源】、【UI】修改锁定画面。

    原文:C# Windows Phone App 开发,自制LockScreen 锁定画面类别(Class),从[网路图片].[Assets资源].[UI]修改锁定画面. 一般我们在开发Windows ...

  2. Android LockScreen (锁屏弹窗)

    在要弹窗的Activity需要进行以下设置,才可以在锁屏状态下弹窗 @Override protected void onCreate(Bundle savedInstanceState) { fin ...

  3. Fedora 22中的用户和用户组管理

    The control of users and groups is a core element of Fedora system administration. This chapter expl ...

  4. 【转】 iOS9.2-iOS9.3.3越狱插件清单

    以下是iOS9.3.3越狱插件清单 原文地址:http://bbs.feng.com/read-htm-tid-10668605.html 序列 支持与否 插件名称 兼容版本 支持设备 1 是 20 ...

  5. 【UWP】通过特定URI打开Win10指定设置页面[转]

    系统设置其实也是一个Modern应用,它与ms-settings:协议进行了关联. 在设置应用中的每一个具体的设置页面都有一个URI(统一资源标识符)与之对应,通过这些URI就可以直达某个具体的设置页 ...

  6. MAT使用--转

    原文地址: [1]http://ju.outofmemory.cn/entry/172684 [2]http://ju.outofmemory.cn/entry/129445 MAT使用入门 MAT简 ...

  7. 在VFP6中模拟CursorAdapter的功能

    这个是我在2002年做的一个VFP程序中实现的方法, 现在看来功能和VFP8,9中的CursorAdapter非常相似, 因为属性设置有许多相同的地方,我甚至怀疑CA就是就是在这样的基础上再包装出来的 ...

  8. java.lang.OutOfMemoryError: bitmap size exceeds VM budget解决方法

    1 BitmapFactory.decodeFile(imageFile); 用BitmapFactory解码一张图片时,有时会遇到该错误.这往往是由于图片过大造成的.要想正常使用,则需要分配更少的内 ...

  9. Appium中部分api的使用方法

    使用的语言是java,appium的版本是1.3.4,java-client的版本是java-client-2.1.0,建议多参考java-client-2.1.0-javadoc. 1.使用Andr ...

随机推荐

  1. 小程序引入百度api天气预报

    先看下最终的效果(默认可以获得未来三天数据): 第一:首先准备条件(必须): 1.小程序已认证,有appID 2.必须把https://api.map.baidu.com 添加到小程序的合法域名列表中 ...

  2. WPF学习:3.Border & Brush

    上一章<WPF学习:2.Layout-Panels-Countainers>主要介绍了布局,容器和面板.这一章主要开始介绍Border(边界)和Brush(画刷). 代码地址:http:/ ...

  3. 适合前端学习JS的网站

    https://developer.mozilla.org/zh-CN/docs/Web/JavaScript

  4. nginx 配置身份验证 http_auth_basic_module

    ngx_http_auth_basic_module模块实现访问必须输入用户名和密码 正确情况向访问,这为我们一些重要资源访问增添了一道安全锁. 语法:     auth_basic_user_fil ...

  5. Python开发【第十篇】:模块

    模块,用一砣代码实现了某个功能的代码集合. 类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代码的重用性和代码间的耦合.而对于一个复杂的功能来,可能需要多个函数才 ...

  6. day13-迭代器及生成器

    iterable:可迭代的:iterator:迭代器: print(dir([ ]))  #打印出列表所拥有的所有方法: 可迭代协议:只要含有__iter__方法的都是可迭代的. 迭代器协议:含有__ ...

  7. php 文件系统函数及目录函数

    1.basename ,dirname ,pathinfo和realpath basename(path) 返回路径中的文件名部份,包含扩展名,path表示路径: dirname(path) 返回路径 ...

  8. Windows Internals 笔记——进程的权限

    1.大多数用户都用一个管理员账户来登录Windows,在Vista之前,这样的登录会创建一个安全令牌.每当有代码试图使用一个受保护的安全资源时,操作系统就会出示这个令牌.从包括Windows资源管理器 ...

  9. jfinal中,render的时候如何取到view根目录

    https://www.oschina.net/question/138209_63023

  10. String,StringBuffer,StringBudilder区别--2019-04-13

    String,StringBuffer,StringBudilder区别: 1String 是字符串常量,创建内容不可以变, final修饰意味着String类型不能被继承,减少被修改的可能,从而最大 ...