IDCompositionDesktopDevice::CreateSurfaceFromHwnd method (dcomp.h)

Creates a wrapper object that represents the rasterization of a layered window, and that can be associated with a visual for composition.

Syntax

HRESULT CreateSurfaceFromHwnd(
  [in]  HWND     hwnd,
  [out] IUnknown **surface
);

Parameters

[in] hwnd

The handle of the layered window for which to create a wrapper. A layered window is created by specifying WS_EX_LAYERED when creating the window with the CreateWindowEx function or by setting WS_EX_LAYERED via SetWindowLong after the window has been created.

[out] surface

The new composition surface object. This parameter must not be NULL.

Return value

If the function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. See DirectComposition Error Codes for a list of error codes.

Remarks

You can use the surface pointer in calls to the IDCompositionVisual::SetContent method to set the content of one or more visuals. After setting the content, the visuals compose the contents of the specified layered window as long as the window is layered. If the window is unlayered, the window content disappears from the output of the composition tree. If the window is later re-layered, the window content reappears as long as it is still associated with a visual. If the window is resized, the affected visuals are re-composed.

The contents of the window are not cached beyond the life of the window. That is, if the window is destroyed, the affected visuals stop composing the window.

If the window is moved off-screen or resized to zero, the system stops composing the content of those visuals. You should use the DwmSetWindowAttribute function with the DWMWA_CLOAK flag to "cloak" the layered child window when you need to hide the original window while allowing the system to continue to compose the content of the visuals.

Requirements

Requirement Value
Target Platform Windows
Header dcomp.h

See also

IDCompositionDesktopDevice

IDCompositionVisual::SetContent