根据MSDN,EM_GETTEXTEX
返回以下内容:
The return value is the number of TCHARs copied into the
output buffer, including the null terminator.
现在看一下下面的代码:
GETTEXTLENGTHEX gtl;
GETTEXTEX gt;
int len;
TCHAR *buf;
memset(>l, 0, sizeof(GETTEXTLENGTHEX));
gtl.flags = GTL_DEFAULT;
gtl.codepage = 1200;
len = SendMessage(hEditWnd, EM_GETTEXTLENGTHEX, (WPARAM) >l, 0);
printf("LEN: %d\n", len);
buf = malloc((len + 1) * sizeof(TCHAR));
memset(>, 0, sizeof(GETTEXTEX));
gt.cb = (len + 1) * sizeof(TCHAR);
gt.flags = GT_DEFAULT;
gt.codepage = 1200;
len = SendMessage(hEditWnd, EM_GETTEXTEX, (WPARAM) >, (LPARAM) buf);
printf("LEN: %d NULLCHECK: %d\n", len, buf[len]);
对于包含文本Hello
的RichEdit控件,此程序输出以下内容:
LEN: 5
LEN: 5 NULLCHECK: 0
这让我感到困惑,因为MSDN说由EM_GETTEXTEX
重新调整的计数值应该包含空终止符,因此我期望6但是我得到5。
这是文档错误还是我在这里做错了什么?
修改
这是清单:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="x86"
name="ELIMINATED FOR PRIVACY REASONS"
type="win32"
/>
<description>ELIMINATED FOR PRIVACY REASONS</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
这是CreateWindowEx()
电话:
hEditWnd = CreateWindowEx(0, L"RichEdit20W", L"",
WS_VSCROLL|WS_HSCROLL|ES_LEFT|ES_AUTOHSCROLL|ES_AUTOVSCROLL|
WS_CHILD|ES_MULTILINE|WS_BORDER,
0,0,0,0, hWnd, NULL, hInstance, NULL);