<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. activiti 涉及的内容

    1 JAVA 委派模式(Delegate) https://blog.csdn.net/mayaofr/article/details/52082665 2 Activiti中的activiti:ex ...

  2. sql语句的删除

    SQL中delete * from 和 delete from 有什么区别? 在SQL Server中两者没有区别,但在Oracle和MySQL的SQL语句中,delete * from是不标准的语法 ...

  3. SSL双向认证和SSL单向认证的流程和区别

    refs: SSL双向认证和SSL单向认证的区别https://www.jianshu.com/p/fb5fe0165ef2 图解 https 单向认证和双向认证!https://cloud.tenc ...

  4. Java Spring Boot VS .NetCore (六) UI thymeleaf vs cshtml

    Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...

  5. 装饰器模式&&ES7 Decorator 装饰器

    装饰器模式(Decorator Pattern)允许向一个现有的对象动态添加新的功能,同时又不改变其结构.相比JavaScript中通过鸡肋的继承来给对象增加功能来说,装饰器模式相比生成子类更为灵活. ...

  6. day14.生成器进阶,推导式

    生成器中取值的三种方法 方法1:next() 方法2:for 循环 方法3:数据类型的强制转换 def func(): for i in range(20): yield '赛车*{}'.format ...

  7. springmvc映射html文件以及解决乱码问题

    <servlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>*.html</u ...

  8. ACA:利用ACA解决TSP优化最佳路径问题——Jason niu

    load citys_data.mat n = size(citys,1); D = zeros(n,n); for i = 1:n for j = 1:n if i ~= j D(i,j) = sq ...

  9. Gym 100963B

    Gym 100963B啊,郁闷,就tm调小了一点范围就A了,就写dp和贪心比较一下,范围到最大值的二倍-1就好了假设最大值的2倍以内能满足最优条件,当金额范围超过最大值2倍的时候:至于为什么,还不清楚 ...

  10. JS对象与原型链

    每个函数都存在一个prototype的属性,然后这个属性值为一个对象,我们称之为原型对象 每个对象都存在着一个隐藏的属性"__proto__" 这个属性引用了创建这个对象的函数的p ...