LockScreen
<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的更多相关文章
- C# Windows Phone App 开发,自制LockScreen 锁定画面类别(Class),从【网路图片】、【Assets资源】、【UI】修改锁定画面。
原文:C# Windows Phone App 开发,自制LockScreen 锁定画面类别(Class),从[网路图片].[Assets资源].[UI]修改锁定画面. 一般我们在开发Windows ...
- Android LockScreen (锁屏弹窗)
在要弹窗的Activity需要进行以下设置,才可以在锁屏状态下弹窗 @Override protected void onCreate(Bundle savedInstanceState) { fin ...
- Fedora 22中的用户和用户组管理
The control of users and groups is a core element of Fedora system administration. This chapter expl ...
- 【转】 iOS9.2-iOS9.3.3越狱插件清单
以下是iOS9.3.3越狱插件清单 原文地址:http://bbs.feng.com/read-htm-tid-10668605.html 序列 支持与否 插件名称 兼容版本 支持设备 1 是 20 ...
- 【UWP】通过特定URI打开Win10指定设置页面[转]
系统设置其实也是一个Modern应用,它与ms-settings:协议进行了关联. 在设置应用中的每一个具体的设置页面都有一个URI(统一资源标识符)与之对应,通过这些URI就可以直达某个具体的设置页 ...
- MAT使用--转
原文地址: [1]http://ju.outofmemory.cn/entry/172684 [2]http://ju.outofmemory.cn/entry/129445 MAT使用入门 MAT简 ...
- 在VFP6中模拟CursorAdapter的功能
这个是我在2002年做的一个VFP程序中实现的方法, 现在看来功能和VFP8,9中的CursorAdapter非常相似, 因为属性设置有许多相同的地方,我甚至怀疑CA就是就是在这样的基础上再包装出来的 ...
- java.lang.OutOfMemoryError: bitmap size exceeds VM budget解决方法
1 BitmapFactory.decodeFile(imageFile); 用BitmapFactory解码一张图片时,有时会遇到该错误.这往往是由于图片过大造成的.要想正常使用,则需要分配更少的内 ...
- Appium中部分api的使用方法
使用的语言是java,appium的版本是1.3.4,java-client的版本是java-client-2.1.0,建议多参考java-client-2.1.0-javadoc. 1.使用Andr ...
随机推荐
- vue.js过滤器
import Vue from 'vue' import { ENV } from '@/config/conf' const dateFormat = (str) => { var date ...
- vue ajax返回html代码不渲染解决
<span v-html='lists.html'></span>
- 三目算法、if/else,switch/case运用
//输入学生的成绩,判断考试是否及格,及格6大于等于0 //第一种写法:三目运算 大多用于单独判断是否满足某个条件 import java.util.Scanner; public class Hel ...
- mac os安装shell man中文帮助工具(manpages-zh),即man命令显示中文帮助文档
一.从官网(http://pkgs.fedoraproject.org/repo/pkgs/man-pages-zh-CN)下载安装包:或者从开源代码(https://github.com/man-p ...
- SpringBoot系列二:SpringBoot自动配置原理
主程序类的注解 @SpringBootApplication 注解,它其实是个组合注解,源码如下: @Target({ElementType.TYPE}) @Retention(RetentionPo ...
- iPhoneX理发指南
 iPhoneX的正面几乎都是屏幕,除了一块齐刘海(sensor housing)来放置前置摄像头和一些传感器.为了让全屏的网页在iPhoneX上有比较好的浏览效果,必须保证布局的内容不被iPhne ...
- 整理一下python中with的用法
ith替代了之前在python里使用try...finally来做清理工作的方法.基本形式如下: with expression [as variable]: with-block 当expressi ...
- if的{}的省略
if (表达式) 语句; else if(表达式) 语句; else if(表达式) 语句; else 语句; 对应: if (表达式) { 语句1; 语句2; 语句N;//多个语句组成代码块 } e ...
- P1516 青蛙的约会
P1516 青蛙的约会x+mt-p1L=y+nt-p2L(m-n)t+L(p2-p1)=y-x令p=p2-p1(m-n)t+Lp=y-x然后套扩欧就完事了 #include<iostream&g ...
- 【NPOI】通过NPOI从内存流中创建EXCEL
一言不合就开始帖代码 XSSFWorkbook workbook = new XSSFWorkbook(); //创建工作簿 XSSFSheet sheet = (XSSFSheet)workbook ...