调用API的时候,例如GetWindowText/SetWindowText,用char*我会用,不会用CString
请指教如何使用CString
CString str;
m_edit.GetWindowText( str.GetBuffer(0),65535);
...这样肯定不行吧?怎么用呢????????

解决方案 »

  1.   

    CString str;
    m_edit.GetWindowText(str)
      

  2.   

    我日。。
    int GetWindowText(
       LPTSTR lpszStringBuf,
       int nMaxCount 
    ) const;
    void GetWindowText(
       CString& rString 
    ) const谢了CWnd::SetWindowText
    Sets the window's title to the specified text.void SetWindowText(
       LPCTSTR lpszString 
    );
    Parameters
    lpszString 
    Points to a CString object or null-terminated string to be used as the new title or control text. 
    Res
    If the window is a control, the text within the control is set. This function causes a WM_SETTEXT message to be sent to this window.Example
    // set the text in IDC_MYEDIT
    CWnd* pWnd = GetDlgItem(IDC_MYEDIT);
    pWnd->SetWindowText(_T("Hockey is best!"));// Get the text back. CString is convenient, because MFC
    // will automatically allocate enough memory to hold the
    // text--no matter how large it is.CString str;
    pWnd->GetWindowText(str);
    ASSERT(str == _T("Hockey is best!"));// The LPTSTR override works, too, but it might be too short.
    // If we supply a buffer that's too small, we'll only get those
    // characters that fit.TCHAR sz[10];
    int nRet = pWnd->GetWindowText(sz, 10);// Nine characters, plus terminating null
    ASSERT(lstrcmp(sz, _T("Hockey is")) == 0);
    ASSERT(nRet == 9);// You can query the length of the text without the length of
    // the string using CWnd::GetWindowTextLength()
    nRet = pWnd->GetWindowTextLength();
    ASSERT(nRet == 15);