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