【问题标题】:Simultaneously Get window snapshot in different sessions at same server 2008 r2 by diff users同时获取不同用户在同一服务器2008 r2的不同会话中的窗口快照
【发布时间】: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


【解决方案1】:

我构建了一个简单的应用程序,运行并运行,连接到 2 个单独的会话,使用 2 个不同的用户名,捕获窗口没有问题。

【讨论】:

    猜你喜欢
    • 2012-04-28
    • 2011-01-15
    • 2011-03-25
    • 1970-01-01
    • 2011-07-09
    • 1970-01-01
    • 2017-04-14
    • 1970-01-01
    • 2010-11-11
    相关资源
    最近更新 更多