我的是win32窗口中,WM_CREATE中创建一个edit:
hEdit=CreateWindowEx(NULL, TEXT("EDIT"), NULL, WS_CHILD|WS_VISIBLE, 0, 0, 200, 100, hWnd, NULL, NULL, NULL);
在编辑框中输入内容,获取编辑框的内容:
TCHAR strText[MAX_PATH];
int len=GetWindowTextLength(hEdit);
GetWindowText(hEdit,strText,len);
获取的长度len没有错,但是内容strText总是少掉一个字符??求大神帮忙啊啊
hEdit=CreateWindowEx(NULL, TEXT("EDIT"), NULL, WS_CHILD|WS_VISIBLE, 0, 0, 200, 100, hWnd, NULL, NULL, NULL);
在编辑框中输入内容,获取编辑框的内容:
TCHAR strText[MAX_PATH];
int len=GetWindowTextLength(hEdit);
GetWindowText(hEdit,strText,len);
获取的长度len没有错,但是内容strText总是少掉一个字符??求大神帮忙啊啊
CString src;
GetWindowText(src);
int len = src.GetLength();
lstrcpy(strText, src.GetBuffer(len));
src.ReleaseBuffer();
HWND hWnd, // handle to window or control
LPTSTR lpString, // text buffer
int nMaxCount // maximum number of characters to copy
);
Parameters
hWnd
[in] Handle to the window or control containing the text.
lpString
[out] Pointer to the buffer that will receive the text.
nMaxCount
[in] Specifies the maximum number of characters to copy to the buffer, including the NULL character. If the text exceeds this limit, it is truncated.
因为是UNICODE 宽字节的 一个字符占两个字节 应该是
GetWindowText(hEdit,strText,len*2);