

Note that CDataEdit is not derived from MFC CEdit and does not necessarily support CEdit methods.

Put a CDataEdit member variable in a parent window class such as a dialog or view. Also you will likely need to add imm32.lib to your Project Settings -> Link -> General -> Object/Library modules due to Windows IME support. To use CDataEdit in your Visual Studio MFC project, just add DataEdit.cpp and DataEdit.h. The source code for CDataEdit comes in the firstobject XML Editor with the Advanced CMarkup Developer License. See CDataEdit specific notes in the firstobject XML Editor release notes. It provides editing of text in fixed or variable width fonts and supports undo/redo and printing. Now, since your C++ code is already Windows-specific, that should not be a problem.Īnd, anyway, IMO the standard should be fixed to allow something like overwriting the terminating NUL with another NUL a valid well-defined operation.The CDataEdit class is a standalone MFC edit control derived directly from CWnd using a Unicode UTF-8 or UTF-16 text string that can be over a gigabyte.

However, it seems to work just fine in Visual Studio (tested on both 20). However, note that overwriting the NUL terminator in STL strings with another NUL terminator seems to be "undefined behavior", at least according to this discussion on Stack"" This approach is more efficient than having a separate std::vector for buffer allocation, with a separate dynamic memory allocation, and then a deep-copy into the std::wstring. However, you have to pass the whole destination buffer length (*including* the terminating NUL) to GetWindowText() as third parameter. Note that the length value returned by GetWindowTextLength() excludes the terminating NUL. Str.resize(len) // make enough room in string Something like this: int len = GetWindowTextLength(hwnd) Then how are you supposed to get any window text ?Īn option would be to make enough room inside the string for storing text in it.
