从最小化的窗口捕获图像

从最小化的窗口捕获图像

本文介绍了从最小化的窗口捕获图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如标题所示,我想从最小化的窗口捕获图像...是甚至可能吗?我使用在搜索我的问题,但它是在c#,我无法使其工作在c + + ...

解决方案

p>您无法捕获最小化的窗口,您必须先恢复它。但是你可以选择在屏幕外还原,或者alpha透明度为1,因此用户看不到它,但操作系统。请务必使用(只有在 SPI_GETANIMATION



例如:

pre> WINDOWPLACEMENT wp = {0};
wp.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hWnd,& wp);

ANIMATIONINFO ai = {0};
bool restoreAnimated = false;

if(wp.showCmd == SW_SHOWMINIMIZED)
{
ai.cbSize = sizeof(ANIMATIONINFO);
SystemParametersInfo(SPI_GETANIMATION,sizeof(ANIMATIONINFO),& ai,0);

if(ai.iMinAnimate!= 0)
{
ai.iMinAnimate = 0;
SystemParametersInfo(SPI_SETANIMATION,sizeof(ANIMATIONINFO),& ai,0);
restoreAnimation = true;
}

//可选地将窗口移动到屏幕外,或
//使用SetLayeredWindowAttributes()...应用alpha。

ShowWindow(hWnd ,SW_SHOWNOACTIVATE);
}

//根据需要捕获...

if(wp.showCmd == SW_SHOWMINIMIZED)
{
SetWindowPlacement(hWnd ,& wp);

//可选的使用SetLayeredWindowAttributes()删除alpha值

if(restoreAnimation)
{
ai.iMinAnimate = 1;
SystemParametersInfo(SPI_SETANIMATION,sizeof(ANIMATIONINFO),& ai,0);
}
}


As the title says, I'd like to capture an image from a minimized window... is that even possible? I use the CaptureAnImage from msdn and it works, unless the window is minimized.

One solution I tried was maximizing it, capturing the image, then returning it to it's original state. Only problem is the animation looks ugly and I'd like to find an alternative... Here is how I tried it:

WINDOWPLACEMENT wInfo;
UINT originalPlacement;

GetWindowPlacement(hWnd, &wInfo);
originalPlacement = wInfo.showCmd;

wInfo.showCmd = SW_MAXIMIZE;
SetWindowPlacement(hWnd, &wInfo);
wInfo.showCmd = originalPlacement;

CaptureAnImage(hWnd); // Capture the image while it's maximized

SetWindowPlacement(hWnd, &wInfo);

So here I'm looking for one of these solutions:

Would it be possible to capture the image even while it's minimized?

or

Would it be possible to maximize it, capture it, then return it to it's original state without showing any kind of animation?

PS: I found that link while searching for my problem, but it's in c# and I'm unable to make it work in c++...

解决方案

You cannot capture a minimized window, you MUST restore it first. But you can optionally restore it off-screen, or with an alpha opacity of 1, so the user does not see it but the OS will. And be sure to temporarily disable the restore/minimize animations as well, using SystemParametersInfo(SPI_SETANIMATION) (only do so if SPI_GETANIMATION reports animations are enabled), to reduce the time needed to show and then re-hide the window.

For example:

WINDOWPLACEMENT wp = {0};
wp.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hWnd, &wp);

ANIMATIONINFO ai = {0};
bool restoreAnimated = false;

if (wp.showCmd == SW_SHOWMINIMIZED)
{
    ai.cbSize = sizeof(ANIMATIONINFO);
    SystemParametersInfo(SPI_GETANIMATION, sizeof(ANIMATIONINFO), &ai, 0);

    if (ai.iMinAnimate != 0)
    {
        ai.iMinAnimate = 0;
        SystemParametersInfo(SPI_SETANIMATION, sizeof(ANIMATIONINFO), &ai, 0);
        restoreAnimation = true;
    }

    // optionally move the window off-screen, or
    // apply alpha using SetLayeredWindowAttributes()...

    ShowWindow(hWnd, SW_SHOWNOACTIVATE);
}

// capture as needed ...

if (wp.showCmd == SW_SHOWMINIMIZED)
{
    SetWindowPlacement(hWnd, &wp);

    // optionally remove alpha using SetLayeredWindowAttributes()...

    if (restoreAnimation)
    {
        ai.iMinAnimate = 1;
        SystemParametersInfo(SPI_SETANIMATION, sizeof(ANIMATIONINFO), &ai, 0);
    }
}

这篇关于从最小化的窗口捕获图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 22:10