[英]EM_SETHANDLE, EM_GETHANDLE works without DS_LOCALEDIT
I made a program similar to Notepad using Visual Studio Community 2017 on Windows 10. It uses edit control created with CreateWindow with the following styles:我在 Windows 10 上使用 Visual Studio Community 2017 制作了一个类似于记事本的程序。它使用使用 CreateWindow 创建的具有以下样式的编辑控件:
WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL
| WS_BORDER | ES_LEFT | ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL
As you see, there's no DS_LOCALEDIT
.如您所见,没有
DS_LOCALEDIT
。 However, using EM_SETHANDLE or EM_GETHANDLE to access the buffer within the edit control seems to work flawlessly.但是,使用 EM_SETHANDLE 或 EM_GETHANDLE 访问编辑控件中的缓冲区似乎可以完美地工作。 The following is a snippet of code that does initial buffer allocation for edit control that is supposed to have been created with
DS_LOCALEDIT
:以下是一段代码,它为应该使用
DS_LOCALEDIT
创建的编辑控件执行初始缓冲区分配:
HLOCAL hEditMem = ::LocalAlloc(LPTR, sizeof(wchar_t) * 51);
wchar_t* pszEdit = reinterpret_cast<wchar_t*>(::LocalLock(hEditMem));
const std::wstring strData(L"Hello");
std::char_traits<wchar_t>::copy(pszEdit, strData.c_str(), strData.size());
::SendMessageW(hwndEdit, EM_SETHANDLE, reinterpret_cast<WPARAM>(hEditMem), 0);
::SendMessageW(hwndEdit, EM_SETMODIFY, TRUE, 0);
The documentation here clearly states that: 此处的文档明确指出:
An application that uses the default allocation behavior (that is, does not use the
DS_LOCALEDIT style must not send EM_SETHANDLE and EM_GETHANDLE messages to the edit
control.
May be someone in Microsoft inconspicuously made the DS_LOCALEDIT
no longer necessary as of Windows 10 or VS 2017 ?从 Windows 10 或 VS 2017 开始,Microsoft 中的某个人可能在不显眼的
DS_LOCALEDIT
不再需要DS_LOCALEDIT
吗?
Since no answer from anybody, I decided to answer my own ...由于没有任何人的回答,我决定回答我自己的......
Using heuristic approach, I came to the following conclusions, which are unlike what's written on MSDN docs:使用启发式方法,我得出了以下结论,这与 MSDN 文档中所写的不同:
To me the second one was particularly important when implementing text find/replace using FindText and ReplaceText ;对我来说,第二个在使用FindText和ReplaceText实现文本查找/替换时特别重要; you don't want to copy all the text from the edit control, using WM_GETTEXT, just to search for certain keyword, would you?
您不想使用 WM_GETTEXT 从编辑控件复制所有文本,只是为了搜索某个关键字,对吗?
I still haven't tested if plain old new
can substitute LocalAlloc
when setting custom buffer with EM_SETHANDLE.我还没有,如果普通的旧测试
new
可以替代LocalAlloc
设置自定义与EM_SETHANDLE缓冲区时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.