Share via


SetWindowOpacity (Compact 7)

3/12/2014

This function sets the degree of opacity for the specified window.

Syntax

BOOL WINAPI SetWindowOpacity(
    HWND hwnd,
    BYTE bOpacity
);

Parameters

  • hwnd
    [in] Handle to the window that you want to adjust the degree of opacity for. The window can have any window style, and this function supports top-level windows and child windows.
  • bOpacity
    [in] The requested level of opacity. This is a BYTE value that ranges from 0 (completely transparent) to 255 (completely opaque).

Return Value

Returns true if successful; otherwise, returns false.

Remarks

You can create visual effects by combining and overlapping multiple windows with different degrees of opacity. You can change the level of opacity for an entire window or for an overlay area where the specified window overlaps a portion of an underlying window (one that is lower in the z-order). For example, you can overlay a slightly opaque window over the primary window to create the effect of a faded window, or you can let underlying windows show slightly if the overlying windows are slightly transparent.

You can use this function for many different window types in Windows Embedded Compact 7, such as windows with DirectX content and windows with Silverlight for Windows Embedded content.

To use hardware-accelerated graphics for windows that support different opacity levels, you must include an OpenGL driver (the platform-dependent driver (PDD) component) in your OS design that supports the OpenGL Embedded Systems (ES) 2.0 specification.

SetWindowOpacity sets the same degree of opacity for all pixels in the specified window. To create different degrees of opacity for elements in a specified window, use the SetWindowCompositionFlags function.

Example

The following code example shows how to call the SetWindowOpacity function.

Important

For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.

#include <winuser.h>
#include <windows.h>

void ChangeOpacity(HWND hwnd)
{
  float fOpacity = .25;
  if (SUCCEEDED(GetOpacity(&fOpacity)))
      {
          SetWindowOpacity(hwnd, (BYTE) (255 * fOpacity));
      }
}

Requirements

Header

CompositorAPI.h,
winuser.h

sysgen

SYSGEN_COMPOSITION

See Also

Reference

Window Compositor Functions
Window Functions
GetWindowOpacity