Screenshot with BitBlt results in black image on Windows 10

后端 未结 2 478
醉酒成梦
醉酒成梦 2021-01-15 23:01

I am using the code below to capture a screenshot of the currently active window. This code comes from Capture screenshot Including Semitransparent windows in .NET, with a f

2条回答
  •  梦毁少年i
    2021-01-15 23:35

    I can suggest a simple workaround:

    First use GetForegroundWindow to get the active window rect. Then call GetDesktopWindow and use that handle with the call to BitBlt:

    Just add a single line to above code:

              IntPtr hDesk = GetForegroundWindow();
              ...       // get dimensions of active window    
              hDesk = GetDesktopWindow();  // add this line
              IntPtr hSrce = GetWindowDC(hDesk);
              IntPtr hDest = CreateCompatibleDC(hSrce);
    

    Works fine.

提交回复
热议问题