Why doesn't this BitBlt example work anymore?

I am currently returning to some Windows programs using the Petzold book (5th edition). I compiled the following example using BitBlt and it does not work as intended.

It should copy the window icon (CxSource, CySource) and copy it to the entire surface of the window. What actually happens with Windows 7 is that the bitmap under the window gets the source and is copied to the surface of the drawing, that is, hdcClient.

I don’t understand why it behaves this way, knowing that it clears the DC transmitted by BitBlt, it is hdcWindow, which refers to the device context obtained through GetWindowDC (hwnd) of the current application.

At first I thought that this is due to the fact that the transparency mode is enabled by default, but deactivating it does not change anything. It seems that BitBlt always takes the surface under the application window! I don’t understand! :) Does anyone know why this works this way and how to fix it?

+4
source share
2 answers

Creating screenshots using BitBlt () has not become easier since the addition of DWM (Desktop Window Manager, aka Aero). Petzold's sample code suffers from a subtle time problem; it takes a screenshot too soon. He does this while Aero is still busy animating the frame, fading into view. So, you see what is outside the window, it may already have partially disappeared depending on how quickly the first WM_PAINT message is generated.

You can easily fix this by disabling the effect:

#include <windows.h>
#include <dwmapi.h>
#pragma comment(lib, "dwmapi.lib")

CreateWindow():

BOOL disabled = TRUE;
DwmSetWindowAttribute(hwnd, DWMWA_TRANSITIONS_FORCEDISABLED, &disabled, sizeof(disabled));

, Blt , DWM , .

, , . Aero, , , . , , , BitBlt(), , . SO, .

+6

Windows, Windows, .

( 20- ):

  • GetSystemMetrics , GetSystemMetrics , .

  • Windows DWM , ( ).

XP:

XP

( , ( Windows 98/2000, ), , . HDC)

Windows DWM - DC, shadow/border/effects DC:

Windows 8

, , , , HICON DrawIconEx. , , , , .

+4

Source: https://habr.com/ru/post/1691652/


All Articles