1

I'm still kind of new to Direct2D so this may be a stupid question.

I want the UI of my application to support things like partial transparency and hardware acceleration. To do proper transparency I need to use the UpdateLayeredWindow API, which expects a source device context. So I use Direct2D to create a ID2D1DCRenderTarget and simply draw to that. So far so good, it seems to work nicely.

Now, I'd like to use some common controls together with this setup. A simple button would be relatively easy to recreate using normal Direct2D drawing functions, but things like edit controls would take a lot more work. Especially when you want to do the regular text processing things that users have come to expect from edit controls. So I'd like to use existing Windows functionality for that.

From reading MSDN, it's possible to get common controls to draw themselves to a device context by sending WM_PRINT messages. But then, how would I know WHEN to send this message? Sure, I can get notifications from an edit control when the user types in it, but I'd still need to figure out when the flashing cursor is supposed to be drawn or not, for example.

How is this usually done? What are my options? Thanks in advance for any pointers.

Jehjoa
  • 551
  • 8
  • 23
  • 1
    Your options are: Ditch Direct2D and live a happier life. Unless you have a convincing reason to use Direct2D, don't use it. There are few use cases for Direct2D, rendering a 2D HUD in a 3D game is basically the only relevant one. If you hope to improve performance, you're in for a disappointment: The overhead involved will typically make rendering slower. GDI is hardware accelerated where it matters (block transfers and alpha blending). It will generally be faster for applications that do not already use Direct3D. – IInspectable Jun 02 '14 at 08:38
  • @IInspectable XAML and HTML use Direct2D in preference to GDI, and it's orders of magnitude faster for rendering, particularly for animations. – Eric Brown Jun 02 '14 at 20:50
  • That being said, however, D2D and common controls don't play well together (XAML & HTML implement edit controls internally), and DC Render targets aren't the fastest around, either. – Eric Brown Jun 02 '14 at 20:51
  • @EricBrown XAML and HTML are markup languages. They certainly do not use Direct2D. I'm only guessing that you are referring to WPF and Internet Explorer, respectively. WPF is different in that it renders directly to Direct3D surfaces, without going through GDI DC's. Regardless of that, smooth animations are a poor measure for performance. Plus, Direct2D's image quality is below that of GDI when doing aliased rendering (as is common with controls). – IInspectable Jun 02 '14 at 21:00
  • 1
    @IInspectable As far as I know, all major HTML renderers use Direct2D instead of GDI. WPF also doesn't use GDI, but I was referring to the XAML renderer used by Windows Store apps. – Eric Brown Jun 02 '14 at 22:03

0 Answers0