Retreives various information about DWM window attributes
Syntax
BOOL WINAPI GetWindowCompositionAttribute (
HWND hwnd,
WINCOMPATTRDATA* pAttrData
)
Parameters
- hwnd
- The window whose information is to be queried
- pAttrData
- Pointer to a structure which both specifies and receives the attribute data
Return Value
Nonzero on success, zero otherwise. Call GetLastError on failure for more information.
Remarks
The layout of the WINCOMPATTRDATA structure is :
struct WINCOMPATTRDATA { DWORD attribute; // the attribute to query, see below PVOID pData; // buffer to store the result ULONG dataSize; // size of the pData buffer };
This function is identical to DwmGetWindowAttribute with the exception that the parameters after the HWND are packed in a struct, rather than passed individually.
Most of the attributes passed to DwmGetWindowAttribute can be used unchanged, however DWMWA_DISALLOW_PEEK and DWMWA_EXCLUDED_FROM_PEEK use values 0x11 and 0xe instead.
The other difference is that some of the attributes have different valuesThis function is also known as NtUserGetWindowCompositionAttribute.
Examples
// Note this sample requires DWM to be enabled #include <windows.h> #include <dwmapi.h> #include <stdio.h> struct WINCOMPATTRDATA { DWORD attribute; PVOID pData; ULONG dataSize; }; void PrintMessage(BOOL bEnabled) { printf("NC Rendering Enabled for console window: %d\n", bEnabled); } DWORD TranslateDWMAttribute(DWORD dwmAttr) { if(dwmAttr < DWMWA_DISALLOW_PEEK) return dwmAttr; if(dwmAttr == DWMWA_DISALLOW_PEEK) return 0x11; if(dwmAttr == DWMWA_EXCLUDED_FROM_PEEK) return 0xe; } int main() { typedef BOOL (WINAPI*pfnGWA)(HWND, WINCOMPATTRDATA*); HMODULE hMod = LoadLibrary(L"user32.dll"); pfnGWA getWindowAttribute = (pfnGWA)GetProcAddress(hMod, "GetWindowCompositionAttribute"); HWND hwndCon = GetConsoleWindow(); BOOL renderingEnabled = FALSE; HRESULT hr = DwmGetWindowAttribute(hwndCon, DWMWA_NCRENDERING_ENABLED, &renderingEnabled, sizeof(renderingEnabled)); if(SUCCEEDED(hr)) { PrintMessage(renderingEnabled); } else { printf("DGWA failed with error %#x\n", hr); } renderingEnabled = FALSE; DWORD attributeVal = TranslateDWMAttribute(DWMWA_NCRENDERING_ENABLED); WINCOMPATTRDATA attrData = {attributeValue, &renderingEnabled, sizeof(renderingEnabled)}; BOOL gwaRet = getWindowAttribute(hwndCon, &attrData); if(gwaRet) { PrintMessage(renderingEnabled); } else { printf("GWA failed with error %lu\n", GetLastError()); } FreeLibrary(hMod); return 0; }