Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show live screens of other applications in one application window

Tags:

c#

wpf

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

like image 996
KMC Avatar asked Oct 09 '22 05:10

KMC


1 Answers

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
like image 87
DerMike Avatar answered Oct 13 '22 09:10

DerMike