Share via

Changing `IDWriteTextLayout`'s text in DirectWrite

thebluetropics 1,046 Reputation points
2022-09-20T10:55:10.247+00:00

I used IDWriteTextLayout to render text on a Direct2D application instead of direct use of DrawTextW().

I have many benefits of using DirectWrite text layout, e.g determining text boundaries before drawn to the screen.

The problem is, whenever I need to change the text, I need to recreate the text layout. Is there any alternative to this?

In some case, I need to change text every miliseconds, which may result recreating text layouts for every WM_PAINT.

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

Answer accepted by question author

Castorix31 91,876 Reputation points
2022-09-20T11:20:15.343+00:00

I need to change text every miliseconds

In your case it seems better to use DrawText (like when FPS is displayed for example)

As you said and from MSDN : Text Formatting and Layout

The text in an IDWriteTextLayout object cannot be changed once the object is created. To change the text you must delete the existing object and create a new IDWriteTextLayout object.

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

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.