在一个应用程序窗口中显示其他应用程序的实时屏幕

5
有没有可能在一个应用程序窗口(最大化)中显示同时运行的其他应用程序的实时屏幕? 我有以下概念性想法(见下面的屏幕截图):主应用程序正在显示,同时多个Excel应用程序正在同时运行。 而不是在应用程序之间点击(或切换标签),或者调整这些窗口大小以在屏幕上显示,我只想让主应用程序最大化,以显示所有这些打开的Excel工作簿的实时屏幕。

我喜欢这个想法。在Windows 7中,任务栏已经有了类似的功能,因此这种做法应该是可行的。 - Ralf de Kleine
对于我的应用程序,我需要根据另一个应用程序的“行为”或“外观”来确定下一步操作,这些无法通过数据等量化,并且必须在视觉上确定。经常翻阅应用程序(或切换选项卡)将会很麻烦。 - KMC
1个回答

4

我使用定期调用 PrintWindow 来实现这一点。

对于这种解决方案,我并不完全满意,因为它似乎有点繁琐。但它也可以扫描隐藏的窗口。

代码如下:

[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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接