【发布时间】:2014-02-04 14:51:55
【问题描述】:
也许这是一个奇怪的问题,但在实施之前我必须确定这不是问题。
我有服务器 2008 R2,我希望几个用户通过远程访问同时连接到该服务器(我现在可以),每个用户都将运行一个应用程序,使用“GetWindowDC”为特定窗口创建快照...
这有可能行不通吗?
public virtual Bitmap Screen_Shot(IntPtr hWnd, RECT windowRect, bool OffScreen = false)
{
if (!Native_API.IsWindowVisible(hWnd)) return null;
IntPtr hDesk = hWnd;
IntPtr hSrce = Native_API.GetWindowDC(hDesk);
IntPtr hDest = Native_API.CreateCompatibleDC(hSrce);
IntPtr hBmp = Native_API.CreateCompatibleBitmap(hSrce, windowRect.Width, windowRect.Height);
try
{
IntPtr hOldBmp = Native_API.SelectObject(hDest, hBmp);
bool b;
lock (Lock_TAKINGSnapShot)
{
if (OffScreen)
b = Native_API.BitBlt(hDest, 0, 0, windowRect.Width, windowRect.Height,
hSrce, 0, 0,
Native_API.TernaryRasterOperations.SRCCOPY | Native_API.TernaryRasterOperations.CAPTUREBLT);
else
b = Native_API.BitBlt(hDest, 0, 0, windowRect.Width, windowRect.Height,
hSrce, 0, 0,
Native_API.TernaryRasterOperations.SRCCOPY);
}
Bitmap bmp = null;
if (hBmp != IntPtr.Zero)
bmp = Bitmap.FromHbitmap(hBmp);
Native_API.SelectObject(hDest, hOldBmp);
if ((bmp != null) && (IsBlankImage(bmp)))
{
return null;
}
return bmp;
}
catch (System.OutOfMemoryException ex)
{
System.Diagnostics.Debug.WriteLine("OutOfMemoryException:" + ex.Message);
return null;
}
finally
{
Native_API.DeleteObject(hBmp);
Native_API.DeleteDC(hDest);
Native_API.ReleaseDC(hDesk, hSrce);
}
}
【问题讨论】:
-
当您还不知道代码是否包含任何问题时,您是否要求我们调试您的代码?
-
如果您发现任何问题,会很高兴听到,但我的问题是验证我是否可以同时在差异会话中运行此类代码。
标签: windows winapi screenshot windows-server-2008-r2 screen-capture