c# - 在 Windows 锁定之前截取屏幕截图
问题描述
我只是在玩一会儿。我尝试在用户锁定机器之前截取主监视器的屏幕截图。到目前为止,没有任何效果。
我试过了SystemEvents.SessionSwith
,但当时窗口处理程序不再有效。
我还尝试LowLevelKeyboardProc
捕获 Win+L,截取屏幕截图,然后自己锁定机器 - 但 Win+L 似乎是受某种保护的快捷方式。
这是我到目前为止所拥有的
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
}
private void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
switch (e.Reason)
{
case SessionSwitchReason.SessionLock: TakeScreenShot(); break;
}
}
private void TakeScreenShot()
{
var screen = Screen.AllScreens.Single(x => x.Primary);
var screenshot = new Bitmap(screen.Bounds.Width, screen.Bounds.Height, PixelFormat.Format32bppArgb);
var gfxScreenshot = Graphics.FromImage(screenshot);
gfxScreenshot.CopyFromScreen(screen.Bounds.X, screen.Bounds.Y, 0, 0, screen.Bounds.Size, CopyPixelOperation.SourceCopy);
screenshot.Save("tmp.png");
}
失败System.ComponentModel.Win32Exception: 'The handle is invalid'
解决方案
我最终使用自己的快捷方式 ( Win+Shift+L
) 截取屏幕截图,然后锁定机器。感谢@Hans Passant 的提示。
推荐阅读
- android - 将 android 资产中的图像加载为位图并使用 glideV4 设置 ImaegView 时复制图像
- excel - application.match 返回什么?一个整数?
- go - Go 在外部声明变量与在循环内声明变量
- python - PIL图像调整大小改变像素值?
- swift - Firebase 查询以随机顺序检索数据。数据按 autoID 组织
- azure - 使用 terraform 为 Azure 应用程序网关添加重定向规则
- javascript - rails slim template: Uncaught SyntaxError: Unexpected token if
- python-3.x - 提取嵌入在某个类下的文本
- javascript - Javascript - 带有字符串模板的正则表达式后跟 4 位数字?
- mysql - 插入带有计算列的语句