Win32 DWMAPI DwmGetWindowAttribute failure

Boris Alexandrov 1 Reputation point
2022-09-30T23:11:08.237+00:00

i'm developing VSTO add-in for outlook which includes overlay on top of the word window. I'm building my UI using WPF. Problem is that when i'm trying to attach WPF Window ( merge left/top/width/height ) to outlook window when STARTING application at scale more than 100% GetWindowsRect Returns wrong rectangle. BUT when i'm starting application at 100% scale then change windows scale at runtime to whatever value everything is good and DPI Aware. Both cases ( starting and runtime ) GetDpiForWindow returns correct values which is...strange. DPI Awareness is set using SetThreadDpiAwareness when forms are created.
After countless attempts i decided to try DwmGetWindowAttribute which also fails with hresult 0x80070006 (invalid handle). Strange thing is that DwmGetWindowAttribute works perfectly for root outlook window but fails to child one ( _WwG to be precise )
DwmGetWindowAttribute docs don't say anything about it. Feels like some windows bug. Any advices will be appreciated.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,681 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,306 questions
{count} votes