KMC
KMC

Reputation: 20036

Show live screens of other applications in one application window

Is it possible to show in one application window (maximized) live screens of another applications that are running concurrently.

I have the following conceptual idea (see below screenshot): the main application is showing while multiple excel applications are running concurrently. Instead of clicking (or tabbing) between applications or resize these windows to be shown on screen, I would want to simply have the main application maximized to show life screens of all these opened excel workbooks.

enter image description here

Upvotes: 5

Views: 245

Answers (1)

DerMike
DerMike

Reputation: 16190

I use periodic calls to PrintWindow for that.

I'm not completely happy with this solution for it seems a bit hacky. But it also scans hidden windows.

The code is

[DllImport("User32.dll")]
public static extern bool PrintWindow(IntPtr hWnd, IntPtr hdcBlt, int nFlags

[StructLayout(LayoutKind.Sequential)]
struct RECT
{
    public int Left;
    public int Top;
    public int Right;
    public int Bottom;
}

public static Bitmap GetWindow(IntPtr hWnd)
{
    RECT rect;
    GetWindowRect(hWnd, out rect);

    int width = rect.Right - rect.Left;
    int height = rect.Bottom - rect.Top;
    if (width > 0 && height > 0)
    {
        // Build device context (dc)
        Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
        Graphics gfxBmp = Graphics.FromImage(bmp);
        IntPtr hdcBitmap = gfxBmp.GetHdc();

        // drawing options
        int nFlags = 0;

        // execute call
        PrintWindow(hWnd, hdcBitmap, nFlags);

        // some clean-up
        gfxBmp.ReleaseHdc(hdcBitmap);
        gfxBmp.Dispose();

        return bmp;
    }
    else
    {
        return null;
    }

} // end function getWindow

Upvotes: 4

Related Questions