richedit的使用 我在dialog中用了两个richedit控件,我想从richedit1获得rtf格式的数据,把获得的数据写入richedit2中,怎么做,请出示具体代码。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 BOOL COleRichEditCtrl::CopyFile( const char *lpSrcFilename, const char *lpDestFilename, int nBuffersize ) { CFile Out, In; int Size,nFilesize,total_size; char *lpBuffer; // Attempt to open the input file. if(!In.Open(lpSrcFilename,CFile::modeRead)){ AfxMessageBox("Could not open the input file." ); return(FALSE); } // Attempt to create the output file. if(!Out.Open(lpDestFilename, CFile::modeWrite|CFile::modeCreate) ){ AfxMessageBox( "Could not open the output file." ); return FALSE; } // Create the copy buffer. lpBuffer=new char [nBuffersize]; if(lpBuffer==NULL){ AfxMessageBox( "Could not allocate the copy buffer." ); return( FALSE ); } CFileStatus rStatus; In.GetStatus( lpSrcFilename, rStatus ); nFilesize = In.GetLength(); total_size = nFilesize; char * lpBuffer_total = new char [nFilesize];//xyh Size=0; while(nFilesize>0){ int nSize=nBuffersize; if(nSize > nFilesize ) nSize=nFilesize; try{ In.Read( lpBuffer, nSize ); //memcpy(lpBuffer,lpBuffer,nSize); memcpy(lpBuffer_total+Size,lpBuffer,nSize); Size=Size+nSize; //lpBuffer_total=lpBuffer_total + nSize; } catch(CFileException *e ){ char *lpMsgBuf; if(FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, e->m_lOsError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&lpMsgBuf,0,NULL) > 0 ){ AfxMessageBox(lpMsgBuf); LocalFree(lpMsgBuf); } // Free the exception and // return. e->Delete(); return FALSE; } e->Delete(); return FALSE; } //while nFilesize -= nSize; try{ Out.Write( lpBuffer_total, total_size ); } catch( CFileException *e ){ char *lpMsgBuf; if( FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, e->m_lOsError, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), (LPSTR) &lpMsgBuf, 0, NULL ) > 0 ){ AfxMessageBox( lpMsgBuf ); LocalFree( lpMsgBuf ); } e->Delete(); return( FALSE ); } //Out.Write( lpBuffer_total, total_size );Õâ¸öÒ²¿ÉÒÔ EDITSTREAM es; es.pfnCallback = readFunction; es.dwError = 0; es.dwCookie = (DWORD)lpBuffer_total; StreamIn( SF_RTF, es ); // Close the output file so that the // SetStatus() function won't fail. Out.Close(); CFile::SetStatus( lpDestFilename, rStatus ); // Delete the buffer. delete []lpBuffer; delete []lpBuffer_total; return TRUE; } //这是关键的回调函数 DWORD CALLBACK COleRichEditCtrl::readFunction(DWORD dwCookie, LPBYTE lpBuf, // the buffer to fill LONG nCount, // number of bytes to read LONG* nRead) // number of bytes actually read { char *pstr=(char *)dwCookie; if((LONG)strlen(pstr)<nCount) { *nRead = (LONG)strlen(pstr); memcpy(lpBuf,pstr, *nRead); //pstr->Empty(); } else { LONG nSize = 0; LONG i = 0; LONG j = 0; LONG readBuff=(LONG)strlen(pstr); //*nRead = nCount; i=*nRead; j=nCount; memcpy(lpBuf,pstr+nSize,nCount); nSize = nSize + nCount; i=*nRead; j=nCount; //readBuff=readBuff-nCount; //*pstr=pstr->Right(pstr->GetLength()-nCount); } return 0; } 可以参考http://hi.baidu.com/smlib/blog/item/1bd7193ea9bfcaf9828b13f9.html postmessage的问题 如何在保留ID的条件下更换控件类型 求救,我现在知道如何选中麦克风录音,不知道怎么选中Stereo Mix(混音)或Mono Mix(单声道)录音,哪位看一下我的程序指导一下啊 在vc6编译没有问题的代码,vc7编译通不过? MFC Grid 求教vc控制word的高手 找妞了 I/O问题(在线等) 在上海浦东哪儿可以买到潘先生的COM本质论? 一个窗口和它的子窗口可不可以在不同的线程? 匹配图像问题请教 网络一行一行数据发送的问题?
BOOL COleRichEditCtrl::CopyFile(
const char *lpSrcFilename,
const char *lpDestFilename,
int nBuffersize )
{
CFile Out, In;
int Size,nFilesize,total_size;
char *lpBuffer; // Attempt to open the input file.
if(!In.Open(lpSrcFilename,CFile::modeRead)){
AfxMessageBox("Could not open the input file." );
return(FALSE);
} // Attempt to create the output file.
if(!Out.Open(lpDestFilename,
CFile::modeWrite|CFile::modeCreate) ){
AfxMessageBox( "Could not open the output file." );
return FALSE;
} // Create the copy buffer.
lpBuffer=new char [nBuffersize];
if(lpBuffer==NULL){
AfxMessageBox( "Could not allocate the copy buffer." );
return( FALSE );
} CFileStatus rStatus;
In.GetStatus( lpSrcFilename, rStatus );
nFilesize = In.GetLength();
total_size = nFilesize;
char * lpBuffer_total = new char [nFilesize];//xyh
Size=0;
while(nFilesize>0){ int nSize=nBuffersize;
if(nSize > nFilesize )
nSize=nFilesize; try{
In.Read( lpBuffer, nSize );
//memcpy(lpBuffer,lpBuffer,nSize);
memcpy(lpBuffer_total+Size,lpBuffer,nSize);
Size=Size+nSize;
//lpBuffer_total=lpBuffer_total + nSize;
}
catch(CFileException *e ){
char *lpMsgBuf;
if(FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL, e->m_lOsError,
MAKELANGID(LANG_NEUTRAL,
SUBLANG_DEFAULT),
(LPSTR)&lpMsgBuf,0,NULL) > 0 ){
AfxMessageBox(lpMsgBuf);
LocalFree(lpMsgBuf);
} // Free the exception and
// return.
e->Delete();
return FALSE;
} e->Delete();
return FALSE;
} //while nFilesize -= nSize; try{
Out.Write( lpBuffer_total, total_size );
} catch( CFileException *e ){ char *lpMsgBuf;
if( FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL, e->m_lOsError,
MAKELANGID( LANG_NEUTRAL,
SUBLANG_DEFAULT ),
(LPSTR) &lpMsgBuf, 0, NULL ) > 0 ){
AfxMessageBox( lpMsgBuf );
LocalFree( lpMsgBuf );
} e->Delete();
return( FALSE );
}
//Out.Write( lpBuffer_total, total_size );Õâ¸öÒ²¿ÉÒÔ
EDITSTREAM es;
es.pfnCallback = readFunction;
es.dwError = 0;
es.dwCookie = (DWORD)lpBuffer_total;
StreamIn( SF_RTF, es );
// Close the output file so that the
// SetStatus() function won't fail.
Out.Close();
CFile::SetStatus( lpDestFilename, rStatus ); // Delete the buffer.
delete []lpBuffer;
delete []lpBuffer_total; return TRUE; } //这是关键的回调函数
DWORD CALLBACK COleRichEditCtrl::readFunction(DWORD dwCookie,
LPBYTE lpBuf, // the buffer to fill
LONG nCount, // number of bytes to read
LONG* nRead) // number of bytes actually read
{ char *pstr=(char *)dwCookie;
if((LONG)strlen(pstr)<nCount)
{
*nRead = (LONG)strlen(pstr);
memcpy(lpBuf,pstr, *nRead);
//pstr->Empty();
} else
{
LONG nSize = 0;
LONG i = 0;
LONG j = 0;
LONG readBuff=(LONG)strlen(pstr);
//*nRead = nCount;
i=*nRead;
j=nCount;
memcpy(lpBuf,pstr+nSize,nCount);
nSize = nSize + nCount;
i=*nRead;
j=nCount;
//readBuff=readBuff-nCount;
//*pstr=pstr->Right(pstr->GetLength()-nCount);
} return 0;
}