Why is the device context blank when I minimize the browser and restore it to its original size?

Asked 1 years ago, Updated 1 years ago, 347 views

Contents of questions

Paste your browser's device context into the upper left corner of your desktop in the following program:
Initially, it appears, but once you minimize the browser, restore it to its original size, and then run the program.
Blank for Firefox or black box for Edge.
Why is the contents of the window not displayed?
Also, what should I do to make it appear?

Source Code

bitbtl01.c

#include<windows.h>

# pragma comment (lib, "user32")
# pragma comment (lib, "gdi32")

int main()
{
    HWND hwnddesk = GetDesktopWindow();
    HWND hwndsrc = GetForegroundWindow();
    HDC hdcdest = GetDC (hwnddesk);
    HDC hdcsrc = GetDC (hwndsrc);

    BitBlt (hdcdest, 0, 0, 300, 300, hdcsrc, 0, 0, SRCCOPY | CAPTUREBLT);

    ReleaseDC (hwnddesk, hdcdest);
    ReleaseDC(hwndsrc, hdcsrc);

    return 0;
}

How to reproduce

cl/EHsc bitblt01.c
sleep3;.\bitblt01.exe
Mouse-click the browser

Environment

OS:Windows 10 professional 64-bit
Browser: Firefox 105.0.1 or Microsoft Edge 106.0.1370.34 (Official Build) (64-bit)

windows winapi visual-c

2022-10-08 01:01

1 Answers

If you draw, it's not over there, but you have to redraw it for the drawing request to keep it in that state.
First of all, I would like to learn how to create a Windows desktop application.
Module 1 First Windows Program
https://learn.microsoft.com/ja-jp/windows/win32/learnwin32/your-first-windows-program

If I implement it,
(1) Create a browser capture area (CreateCompatibleDC/CreateCompatibleBitmap/SelectObject)
(2) Create a window and paste it on your desktop with SetParent
(3) When the window receives a WM_PAINT message, transfer the image from (1)
That's what I think.


2022-10-08 01:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.