我需要实现一个截屏功能,截屏我已经实现了,但是当我的计算机锁定后,进入登录桌面后,截屏就失败了,截的是黑屏,我的问题是怎么样才能在计算机锁定后进入登录桌面我的程序还能截屏?
截屏代码
var hWnd = WinAPI.GetDesktopWindow();
IntPtr hSrcDC = WinAPI.GetWindowDC(hWnd);
WinAPI.SetThreadDesktop(hSrcDC);
IntPtr hDC = g.GetHdc();
int retval = WinAPI.BitBlt(hDC, 0, 0, GetPhysicalDisplaySize().Width, GetPhysicalDisplaySize().Height, hSrcDC, 0, 0, (int)(CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt));
g.ReleaseHdc();
windows api
[DllImport("user32.dll")]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern IntPtr GetWindowDC(IntPtr ptr);
[DllImport("user32.dll")]
public static extern bool SwitchDesktop(IntPtr hDesktop);
[DllImport("user32.dll")]
public static extern IntPtr CreateDesktop(string lpszDesktop,
IntPtr lpszDevice,
IntPtr pDevmode,
int dwFlags,
uint dwDesiredAccess,
IntPtr lpsa);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr OpenInputDesktop(uint dwFlags, bool fInherit, uint dwDesiredAccess);
[DllImport("user32.dll", EntryPoint = "CloseDesktop", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CloseDesktop(IntPtr handle);
[DllImport("user32.dll")]
public static extern IntPtr OpenDesktop(string lpszDesktop,
uint dwFlags,
bool fInherit,
uint dwDesiredAccess);
[DllImport("user32.dll")]
public static extern bool SetThreadDesktop(IntPtr hDesktop);