Tomas M
Tomas M

Reputation: 7333

ShowWindow() SW_HIDE window instantly, without effect

In my C++ application, I have the following code:

ShowWindow(hDlg, SW_HIDE);
MakeScreenshot();
ShowWindow(hDlg, SW_SHOW);

This should capture screenshot of screen WITHOUT the current application window. However there is a problem. The SW_HIDE takes some time because my windows 8.1 is configured to use Animation effects. So the hiding of window takes about 400 miliseconds and if screenshot is captured during this interval (which it is), it will contain also the window of the app itself, which I do not like.

Is there any way to hide the current window instantly, so it won't be included in the create screenshot function, which is called immediately after it? If not, is there any other preferred way how to take screenshot of windows desktop excluding the application itself? Adding a delay before the MakeScreenshot is not any good solution. Thank you.

Upvotes: 5

Views: 5948

Answers (2)

Adrian McCarthy
Adrian McCarthy

Reputation: 47954

You could use MoveWindow (or SetWindowsPos) to move the undesired window outside the visible region of the virtual desktop, and then move it back.

You might need to enumerate the monitors to find a coordinate beyond the reach of all the monitors, which would be a little bit of work. Presumably your screenshot code is computing the coordinates to snapshot, so you could re-use that calculation to find a safe place to park the window.

Upvotes: 1

sergiol
sergiol

Reputation: 4337

What worked for me:

    this->ModifyStyleEx(0, WS_EX_LAYERED | WS_EX_TOPMOST); //just a backup


    COLORREF c;
    BYTE b;
    DWORD flags;
    this->GetLayeredWindowAttributes(&c, &b, &flags); //just a backup

    this->SetLayeredWindowAttributes(0, 0, LWA_ALPHA);


    //CODE TO TAKE A SCREENSHOT


    this->SetLayeredWindowAttributes(c, b, flags); //just a restore

    this->ModifyStyleEx(WS_EX_LAYERED | WS_EX_TOPMOST, 0); //just a restore

Upvotes: 0

Related Questions