我的是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总是少掉一个字符??求大神帮忙啊啊

解决方案 »

  1.   

    那就GetWindowText(hEdit,strText,len+1);试试?
      

  2.   


    CString src;
    GetWindowText(src);
    int len = src.GetLength();
    lstrcpy(strText, src.GetBuffer(len));
    src.ReleaseBuffer();
      

  3.   

    int GetWindowText(
      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. 
      

  4.   

    字符串后面都会有个结束符'\0'会占一个字节的长度,GetWindowTextLength函数返回的是不包含结束符的长度,所以应该是len+1
      

  5.   

    已经解决了 谢谢各位的回答
    因为是UNICODE 宽字节的 一个字符占两个字节 应该是
    GetWindowText(hEdit,strText,len*2);