How to implement Text Input in Direct2D applications

thebluetropics 1,046 Reputation points
2022-09-15T05:58:10.277+00:00

I have forward plan after finished learn the basics of Direct2D.

I know that Direct2D is not a UI Control library. But, if there any built-in support for Text Input (like <input type="text"/> in HTML) from Direct2D, I don't really need to handle user input on my own.

However, if Direct2D does not serve that, how can I implement a Text Input in my Direct2D application?

Is there any user-input handling support in Win32 API?

Note that I don't want to handle physical keyboard input, if the user presses key S + A, the "input" should be sa. If the user has a different input methods, e.g Microsoft Japanese IME, for example, when the user presses key S + A, the input should be Japanese character (pronounced "sa") and not ASCII sa.

Windows development | Windows API - Win32
Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Jeanine Zhang-MSFT 11,356 Reputation points Microsoft External Staff
    2022-09-15T06:24:22.057+00:00

    @thebluetropics

    You could try to use WM_CHAR message to implement Text Input.

    If you want to high-quality text rendering, you could try to use DirectWrite and follow the Doc: Text Rendering with Direct2D and DirectWrite


1 additional answer

Sort by: Most helpful
  1. Castorix31 91,496 Reputation points
    2022-09-18T09:14:19.767+00:00

    You can use standard Win32 Edit control (with some code to add to handle the caret if there are animations...)
    Test with Chinese :

    242225-direct2d-edit.gif


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.