初学VC我看了好多书都没理出个头绪来。请VC高手解答。多谢。另外,如何在工具栏上加按钮?不要图标,只要文字。

解决方案 »

  1.   

    以下代码供你参考
    DWORD __stdcall MEditStreamOutCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
    {
    extern CString m_TxtFileName;
    CFile mFile; 
    CString sThisWrite;
    sThisWrite.GetBufferSetLength(cb);

    CString *psBuffer = (CString *)dwCookie;

    for (int i=0; i<cb; i++) {
    sThisWrite.SetAt(i, *(pbBuff+i));
    }

    *psBuffer += sThisWrite;
        CString strTemp; 

        mFile.Open(m_TxtFileName, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite);
    mFile.Write(sThisWrite, cb);
    mFile.Flush();

    mFile.Close(); 
    AfxMessageBox("保存成功!");
    *pcb = sThisWrite.GetLength();
    sThisWrite.ReleaseBuffer();
    return 0;
    }void CTTSPDlg::OnBtnSaveinfo() 
    {
    extern CString m_TxtFileName;
    CString filt="txt File (*.txt)|*.txt|All files (*.*)|*.*||";

    CFileDialog FileDlg(FALSE,"*.txt","*.txt",NULL,filt,this);

    FileDlg.m_ofn.Flags|=OFN_FILEMUSTEXIST;
    FileDlg.m_ofn.lpstrTitle="存储聊天内容";

    if (FileDlg.DoModal()==IDOK) 
    {
    m_TxtFileName = FileDlg.GetPathName();
    }
    else
    return;
        
    OnReadout() ; // TODO: Add your control notification handler code here

    }void CTTSPDlg::OnReadout() 
    {
    CString sReadText; //Where the rich text will be streamed into

    EDITSTREAM es;

    es.dwCookie = (DWORD)&sReadText; // Pass a pointer to the CString to the callback function 
    es.pfnCallback = MEditStreamOutCallback; // Specify the pointer to the callback function.

    m_RichEdit.StreamOut(SF_TEXT, es); // Perform the streaming

    // MessageBox(sReadText.Mid(0,500)); // Show you the first 500 chars of rich codes
    }
      

  2.   

    CRichEdit::LoadFile
    CRichEdit::SaveFile
      

  3.   

    只需要使用richeditview就可以实现你所要的功能注意在视图类的初始化函数里加:
    m_nWordWrap = WrapNone;    
    WrapChanged();            
    这两句。
    若不行,你可以去了解一下archive类,就可以搞定了