拍摄使用createdesktop api创建的桌面的屏幕截图 [英] take a screenshot of a desktop created using createdesktop api
问题描述
修改:对于无形桌面,这不行,代码,我看到我需要捕获活动桌面(这是不'WinSta0\Default')的屏幕截图,以获得活动用户桌面的处理我' ve使用OpenInputDesktop。
+1 ThievingSix你是对的。
对不起,我的误会。
使用SetThreadDesktop(如果您是通过CreateDestkop创建桌面,那么您具有您传递给SetThreadDesktop的处理)。切换桌面线程后,您可以捕捉截图。好主意将恢复到上一个桌面的线程(不要'打破'其他/未来的代码)。
var
dOldDesktop:HDESK;
begin
lOldDesktop:= GetThreadDesktop(GetCurrentThreadId);
尝试
如果不是SetThreadDesktop(ADesktop),然后//将句柄传递到您的桌面,或从OpenInputDesktop
{错误句柄,如RaiseLastOSError或Exit(False)}获取的dekstop句柄;
//你的屏幕截图/输入/鼠标代码这里
finally
如果lOldDesktop<> 0然后// GetThreadDesktop可以失败(当这个GetThreadDesktop(GetCurrentThreadId)可能失败时,我不知道条件)
SetThreadDesktop(lOldDesktop); //将线程还原到以前的桌面
end;
结束
这个代码应该在非主线程中运行,就像ThievingSix指出的那样,因为SetThreadDesktop在这种情况下可能会失败。安全的方式是生成线程来制作截图。
PS。我不知道这是否可以使用发送输入鼠标/键盘(应该),但是屏幕截图的作用。
编辑 :
- 更多的会话,窗口台,桌面这里 http://blogs.technet.com/b/askperf/archive/2007/07/24/sessions -desktops-and-windows-stations.aspx
- 桌面工具(SysInternals) - http://technet.microsoft.com/en-us/sysinternals/cc817881
i am using the createdesktop api to create a desktop and i would like to take a screenshot or send input mouse/keyboard without dispalying the desktop to the user.any ideeas on how to implement this???
Edit: This won't work for invisible desktops, I've looked to my old code, and I see that I needed that for catching screenshot of active desktop (which was not 'WinSta0\Default'), to get handle of active user desktop I've used OpenInputDesktop.
+1 ThievingSix you are right.
Sorry everyone for my misunderstanding.
You need to use SetThreadDesktop (if you are creating desktop by CreateDestkop, then you have handle for it which you pass to SetThreadDesktop). After switching desktop for thread, you can catch screenshot. Good idea would be revert to previous desktop for thread (to not 'break' other/future code).
var
lOldDesktop: HDESK;
begin
lOldDesktop:= GetThreadDesktop(GetCurrentThreadId);
try
if not SetThreadDesktop(ADesktop) then // pass handle to your desktop, or dekstop handle obtained from OpenInputDesktop
{error handle, like RaiseLastOSError or Exit(False)};
// your screenshot/input/mouse code here
finally
if lOldDesktop<> 0 then // GetThreadDesktop can fail (I don't know condition when this GetThreadDesktop(GetCurrentThreadId) could fail)
SetThreadDesktop(lOldDesktop); // revert thread to previous desktop
end;
end;
This code should run in non-main thread, as ThievingSix pointed because SetThreadDesktop can fail in that case. Safe way is spawn thread to make screenshot.
PS. I'm not sure if this will work with "send input mouse/keyboard" (it should), but for screenshot works.
Edit:
- More on sessions, window stations, desktops here http://blogs.technet.com/b/askperf/archive/2007/07/24/sessions-desktops-and-windows-stations.aspx
- Desktop tool (SysInternals) - http://technet.microsoft.com/en-us/sysinternals/cc817881
这篇关于拍摄使用createdesktop api创建的桌面的屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!