0

I am building a UI using pure Direct2D and C# with SharpDX. This UI is meant to be user-friendly and good-looking, while being efficient.

Direct2D-powered toolbar

For the sake of demonstration, I built a prototype using hacky undocumented APIs (see this question), but in no way I am going to production with this, being backward-compatibility the first and foremost reason:

var accent = new User32.AccentPolicy { AccentState = AccentState };
int accentStructSize = Marshal.SizeOf(accent);

// allocate space for the struct
IntPtr accentPtr = Marshal.AllocHGlobal(accentStructSize);
Marshal.StructureToPtr(accent, accentPtr, false);

// set composition data
var data = new User32.WindowCompositionAttributeData {
  Attribute = User32.WindowCompositionAttribute.WCA_ACCENT_POLICY,
  SizeOfData = accentStructSize,
  Data = accentPtr
};

// change window composition attributes and release resources
User32.SetWindowCompositionAttribute(Handle, ref data);
Marshal.FreeHGlobal(accentPtr);

I know the instant response to this is to use WPF, but I'm fairly limited to raw Direct2D calls, as I'm intending to move all the UI logic to a DLL for injection in DirectX apps (which, albeit not being sure how I'm going to do this, is out of the scope of this question.)

On Windows 8.1, there is DirectComposition, which enables efficient alpha-blending on top of transparent windows.

But there's no such thing in Windows Vista and 7 (even with the Platform Update).

Is there a way I can use pure, non-hacky Direct2D/DirectX code to make this UI work across all Windows versions (preferably Vista SP2 upwards)?

  • It is preferred if you can post separate questions instead of combining your questions into one. That way, it helps the people answering your question and also others hunting for at least one of your questions. Thanks! – Jake Symons Feb 15 '18 at 21:43
  • @JakeSymons, thanks for your feedback. I've edited the question and will ask the rest depending on the answers of this one. –  Feb 15 '18 at 21:45
  • There's `SharpDX.Direct3D11.BlendStateDescription` for blending when rendering various textures (corresponding to `D3D11_BLEND_DESC`) - this would be what you'd use if you intercept the DirectX application rendering as a texture, then re-render to the window (hooking is possible but is a hack). It's out of my experience, but it looks like `SetLayeredWindowAttributes` lets you set window opacity, if you want to create a window that follows the application you are hooking around but not be completely opaque. That's less hacky since you don't have to intercept the original app's rendering calls. – NextInLine Feb 21 '18 at 17:18

0 Answers0