Question

Maybe this is a weird question, but I must be sure it is not an issue before implement it.

I have server 2008 R2, I want a few users to connect to this server simultaneously via Remote access (I can now), each will run an application that do a snapshot for specific windows using the "GetWindowDC"...

Is there a chance this can't work?

 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);
    }
}
Was it helpful?

Solution

I built a simple app,ran and it works, connect into 2 separate sessions, using 2 diff user names, and had no issue to capture the window.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top