这个我知道
richeditctrl 好象要用LimitText 来设置大小不设置缺省就是64k,读两下就完了
richeditctrl 好象要用LimitText 来设置大小不设置缺省就是64k,读两下就完了
解决方案 »
- 要做一个下载工具,如何判断一些链接是可以下载文件的呢?比如:http://www.icxx.net/Pdf/Down/91C03D88362532DC7C173
- 关于ImmGenerateMessage函数的问题
- 怎么对一个窗口区域的不同控件进行拉放分割?
- 可以利用GDI+判断一条直线是否穿过一个多边形?
- 我结婚了,
- 大家帮帮忙,我写的一个控件有运行错误
- 请问如何给一个 LPCWSTR 数据类型赋值?
- 有没有学过 <<理论计算机科学>> 的
- 已经得到了HBITMAP,如果才能把HBITMAP指向的位图转换成二进制流COPY到缓冲区里?
- 急问DLL如何调试
- 为什么大家都只是讨论关于编程技术以外的问题??
- 单文档程序编译时找不到头文件
还是你其他的地方弄错了?你可以limittext后,用paste()粘贴一个1M的文本上去看看能不能滚动.
不回车就没问题.
可恶......
谁有用richeditctrl做的编辑器?
WordPad太复杂,有没有简单点的?
1、创建RichEdit窗口时,必须指定正确的窗口风格:
(1)应该包含WS_AUTOVSCROLL,否则滚动时会有问题。
(2)或者需要ES_WANTRETURN风格?
2、或者检查您的 EDITSTREAMCALLBACK 函数?以上建议,请尝试。
我把部分代码贴出来吧:
// ChildView.h : interface of the CChildView class
//
/////////////////////////////////////////////////////////////////////////////#if !defined(AFX_CHILDVIEW_H__5D62FBDE_FCE7_11D4_BBD5_5254ABDF4E8A__INCLUDED_)
#define AFX_CHILDVIEW_H__5D62FBDE_FCE7_11D4_BBD5_5254ABDF4E8A__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//#include "MyRichEdit.h"
//#include "MainMediaText.h"
/////////////////////////////////////////////////////////////////////////////
// CChildView window
typedef struct dwcookie{
int m_hFile;
BOOL IsStor;
}COOKIE,* PCOOKIE;
class CChildView : public CWnd
{
// Construction
public:
CChildView();// Attributes
public:
CTabCtrl m_TabView;
// CMyRichEdit m_EditView;
CRichEditCtrl m_EditView;
// CMainMediaText m_PreView;
CEdit m_PreView;
// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CChildView)
protected:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
//}}AFX_VIRTUAL// Implementation
public:
static DWORD CALLBACK EditStreamCallBack(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb);
CString m_FileName;
virtual ~CChildView(); // Generated message map functions
protected:
//{{AFX_MSG(CChildView)
afx_msg void OnPaint();
afx_msg void OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnFileOpen();
afx_msg void OnFileSave();
afx_msg void OnEditCopy();
afx_msg void OnFilePrint();
afx_msg void OnToolBack();
afx_msg void OnToolNote();
afx_msg void OnEditFind();
afx_msg void OnEditFindNext();
afx_msg void OnEditCut();
afx_msg void OnEditPaste();
afx_msg void OnEditUndo();
afx_msg void OnModifyAttrib();
afx_msg void OnModifyBkcolor();
afx_msg void OnModifyCenter();
afx_msg void OnModifyFont();
afx_msg void OnModifyLeft();
afx_msg void OnModifyMarker();
afx_msg void OnModifyNote();
afx_msg void OnModifyPic();
afx_msg void OnModifyRight();
afx_msg void OnModifyTag();
afx_msg void OnModifyTitle();
afx_msg void OnEditAutoline();
afx_msg void OnUpdateEditAutoline(CCmdUI* pCmdUI);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
BOOL m_IsAutoLine;
BOOL m_IsEditViewVisible;
char * m_Context;
};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_CHILDVIEW_H__5D62FBDE_FCE7_11D4_BBD5_5254ABDF4E8A__INCLUDED_)// ChildView.cpp : implementation of the CChildView class
//#include "stdafx.h"
#include "EBookEdit.h"
#include "ChildView.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define TABVIEW 100
#define EDITVIEW 101
#define PREVIEWVIEW 102
/////////////////////////////////////////////////////////////////////////////
// CChildViewCChildView::CChildView()
{
m_FileName=_T("");
m_Context=NULL;
m_IsEditViewVisible=TRUE;
m_IsAutoLine=FALSE;
}CChildView::~CChildView()
{
if(m_Context!=NULL)
delete []m_Context;
}
BEGIN_MESSAGE_MAP(CChildView,CWnd )
//{{AFX_MSG_MAP(CChildView)
ON_WM_PAINT()
ON_NOTIFY(TCN_SELCHANGE,TABVIEW,OnSelchangeTab)
ON_WM_CREATE()
ON_WM_SIZE()
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
ON_COMMAND(ID_TOOL_BACK, OnToolBack)
ON_COMMAND(ID_TOOL_NOTE, OnToolNote)
ON_COMMAND(ID_EDIT_FIND, OnEditFind)
ON_COMMAND(ID_EDIT_FIND_NEXT, OnEditFindNext)
ON_COMMAND(ID_EDIT_CUT, OnEditCut)
ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
ON_COMMAND(ID_MODIFY_ATTRIB, OnModifyAttrib)
ON_COMMAND(ID_MODIFY_BKCOLOR, OnModifyBkcolor)
ON_COMMAND(ID_MODIFY_CENTER, OnModifyCenter)
ON_COMMAND(ID_MODIFY_FONT, OnModifyFont)
ON_COMMAND(ID_MODIFY_LEFT, OnModifyLeft)
ON_COMMAND(ID_MODIFY_MARKER, OnModifyMarker)
ON_COMMAND(ID_MODIFY_NOTE, OnModifyNote)
ON_COMMAND(ID_MODIFY_PIC, OnModifyPic)
ON_COMMAND(ID_MODIFY_RIGHT, OnModifyRight)
ON_COMMAND(ID_MODIFY_TAG, OnModifyTag)
ON_COMMAND(ID_MODIFY_TITLE, OnModifyTitle)
ON_COMMAND(ID_EDIT_AUTOLINE, OnEditAutoline)
ON_UPDATE_COMMAND_UI(ID_EDIT_AUTOLINE, OnUpdateEditAutoline)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChildView message handlersBOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
if (!CWnd::PreCreateWindow(cs))
return FALSE; cs.dwExStyle |= WS_EX_CLIENTEDGE;
cs.style &= ~WS_BORDER;
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL); return TRUE;
}void CChildView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CWnd::OnPaint() for painting messages
}
int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd ::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
if(!m_TabView.Create(WS_VISIBLE|WS_CHILD|TCS_BOTTOM/*|TCS_FIXEDWIDTH*/,
CRect(0,0,0,0),this,TABVIEW))
{
TRACE0("Failed to create Child view window\n");
return -1;
}//WS_VISIBLE|WS_TABSTOP|&~ES_READONLY
m_TabView.InsertItem(0,"编辑");
m_TabView.InsertItem(1,"预览"); if(!m_EditView.Create(ES_WANTRETURN|
WS_BORDER|WS_CHILD|
WS_VSCROLL |ES_AUTOVSCROLL|
ES_MULTILINE|ES_NUMBER ,
CRect(0,0,0,0),&m_TabView,EDITVIEW))
{
TRACE0("Failed to create Edit view window\n");
return -1;
} PARAFORMAT pf;
pf.cbSize = sizeof(PARAFORMAT);
pf.dwMask = PFM_TABSTOPS ;
pf.cTabCount = MAX_TAB_STOPS;
for( int itab = 0 ; itab < pf.cTabCount ; itab++ )
pf.rgxTabs[itab] =100;// (itab + 1) * 1440/5 ; m_EditView.SetParaFormat( pf );
CHARFORMAT cfDefault;
cfDefault.cbSize = sizeof(cfDefault);
cfDefault.dwEffects = CFE_PROTECTED;
cfDefault.dwMask = CFM_BOLD | CFM_FACE | CFM_SIZE | CFM_CHARSET | CFM_PROTECTED;
cfDefault.yHeight = 200;
if (GetACP()==936)
{
cfDefault.bCharSet = GB2312_CHARSET;//0xEE;
strcpy(cfDefault.szFaceName, _T("宋体"));
}
else
{
cfDefault.bCharSet = 0xEE;
strcpy(cfDefault.szFaceName, _T("Courier New"));
}
m_EditView.SetDefaultCharFormat(cfDefault);
m_EditView.SetEventMask(ENM_CHANGE | ENM_SELCHANGE | ENM_PROTECTED);
// if(!m_PreView.init(&m_TabView,PREVIEWVIEW,CRect(0,0,0,0)))
if(!m_PreView.Create(WS_CHILD|WS_VISIBLE|WS_BORDER,CRect(0,0,0,0),&m_TabView,PREVIEWVIEW))
{
TRACE0("Failed to create Privew view window\n");
return -1;
}
return 0;
}void CChildView::OnSize(UINT nType, int cx, int cy)
{
CWnd ::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
int eIsShow=m_IsEditViewVisible?SW_SHOW:SW_HIDE;
int pIsShow=m_IsEditViewVisible?SW_HIDE:SW_SHOW; if(m_TabView.GetSafeHwnd()!=NULL)
m_TabView.SetWindowPos(0,0,0,cx,cy,SWP_NOZORDER|SWP_NOMOVE);
if(m_EditView.GetSafeHwnd()!=NULL)
{
m_EditView.SetWindowPos(0,5,5,cx-10,cy-35,SWP_NOZORDER);
}
if(m_PreView.GetSafeHwnd()!=NULL)
{
m_PreView.SetWindowPos(0,5,5,cx-10,cy-35,SWP_NOZORDER);
}
m_EditView.ShowWindow(eIsShow);
m_PreView.ShowWindow(pIsShow);} void CChildView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult)
{
int nSelect=m_TabView.GetCurSel();
if(nSelect!=-1)
{
switch(nSelect)
{
case 0:
m_IsEditViewVisible=TRUE;
m_EditView.ShowWindow(SW_SHOW);
m_PreView.ShowWindow(SW_HIDE);
break;
case 1:
m_IsEditViewVisible=FALSE;
m_EditView.ShowWindow(SW_HIDE);
m_PreView.ShowWindow(SW_SHOW);
break;
}
}
*pResult = 0;
}void CChildView::OnFileOpen()
{
// TODO: Add your command handler code here
CFileDialog m_FileOpen(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,
"EBook File(*.ebk)|*.ebk|All File(*.*)|*.*||");
if(m_FileOpen.DoModal()==IDOK)
{
m_FileName=m_FileOpen.GetPathName();
CFile file;
UINT openflag=CFile::modeRead;
BOOL m_IsReadOnly=m_FileOpen.GetReadOnlyPref();
if(!m_IsReadOnly)
openflag=CFile::modeReadWrite;
if(!file.Open((LPCTSTR)m_FileName,openflag))
{
MessageBox("Open file error!","warning",MB_OK|MB_ICONWARNING);
return;
}
else
{
m_EditView.SetWindowText("");
CMainFrame *pMFrame=(CMainFrame *)::AfxGetMainWnd();
COOKIE m_Cookie;
EDITSTREAM eStream={0,0,EditStreamCallBack};
m_Cookie.m_hFile=file.m_hFile;
m_Cookie.IsStor=FALSE;
eStream.dwCookie = (DWORD)&m_Cookie;
eStream.pfnCallback =EditStreamCallBack;
eStream.dwError = 0;
m_EditView.StreamIn(SF_TEXT,eStream);
// ::SendMessage (m_EditView.m_hWnd , EM_STREAMIN, (WPARAM)SF_TEXT,(LPARAM)&eStream);
::SendMessage (m_EditView.m_hWnd , EM_SETMODIFY, (WPARAM)TRUE, 0L);
m_EditView.SetFocus();
/* ::SendMessage(m_EditView.m_hWnd,EM_SETSEL,0,0);
int pos=m_FileName.ReverseFind('\\');
CString title=m_FileName.Mid(pos+1,m_FileName.GetLength()-pos-5);
pMFrame->m_wndStatusBar.SetPaneText(1,title);
CString head="<feb>\n<format vertion=\"feb1.0\">\n<title>"+title+"</title>\n</feb>\n";
m_EditView.ReplaceSel(head);
*/ //将文本文档改为EBook电子文档
/* char *m_Context=new char[file.GetLength()];
// ::GetWindowText(m_EditView.m_hWnd,m_Context,file.GetLength());
if(file.ReadHuge(m_Context,file.GetLength())!=file.GetLength())
return;
else
{
m_PreView.SetMediaString(m_Context);
}*/
// m_PreView.SetFileName(m_FileName);
}
file.Close();
}
}void CChildView::OnFileSave()
{
// TODO: Add your command handler code here
CFile file;
if(m_FileName.IsEmpty())
return;
if(!file.Open((LPCTSTR)m_FileName,CFile::modeWrite|CFile::shareDenyWrite))
{
TRACE("Can not open file!");
return ;
}
COOKIE m_Cookie;
EDITSTREAM eStream={0,0,EditStreamCallBack};
m_Cookie.m_hFile=file.m_hFile;
m_Cookie.IsStor=TRUE;
eStream.dwCookie = (DWORD)&m_Cookie;
eStream.pfnCallback =EditStreamCallBack;
eStream.dwError = 0;
::SendMessage (m_EditView.m_hWnd , EM_STREAMOUT, (WPARAM)SF_TEXT,
(LPARAM)&eStream);
}void CChildView::OnEditCopy()
{
// TODO: Add your command handler code here
}void CChildView::OnFilePrint()
{
// TODO: Add your command handler code here
}DWORD CALLBACK CChildView::EditStreamCallBack(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
DWORD dw = 0;
COOKIE *m_Cookie=(COOKIE *)dwCookie;
CFile file(m_Cookie->m_hFile);
TRY
{
if(m_Cookie->IsStor)
try{
file.WriteHuge(pbBuff,cb);
}
catch(...)
{
// MessageBox("Write content to file error");
return 0;
}
else
{
*pcb=file.ReadHuge(pbBuff,cb);
/* CString parse((LPCTSTR)pbBuff,cb);
int pos=parse.Find("img",0));
int pos2=pos;
if(pos!=-1)
{
pos2=parse.Find("size",pos);*/
}
}
CATCH(CFileException, e)
{
*pcb = 0;
// pCookie->m_dwError = (DWORD)e->m_cause;
dw = 1;
// DELETE_EXCEPTION(e);
}
AND_CATCH_ALL(e)
{
*pcb = 0;
// pCookie->m_dwError = (DWORD)CFileException::generic;
dw = 1;
// DELETE_EXCEPTION(e);
}
END_CATCH_ALL
return dw;
}void CChildView::OnToolBack()
{
// TODO: Add your command handler code here
}void CChildView::OnToolNote()
{
// TODO: Add your command handler code here
}void CChildView::OnEditFind()
{
// TODO: Add your command handler code here
}void CChildView::OnEditFindNext()
{
// TODO: Add your command handler code here
}void CChildView::OnEditCut()
{
// TODO: Add your command handler code here
}void CChildView::OnEditPaste()
{
// TODO: Add your command handler code here
}void CChildView::OnEditUndo()
{
// TODO: Add your command handler code here
}void CChildView::OnModifyAttrib()
{
// TODO: Add your command handler code here
}void CChildView::OnModifyBkcolor()
{
// TODO: Add your command handler code here
}void CChildView::OnModifyCenter()
{
// TODO: Add your command handler code here
}void CChildView::OnModifyFont()
{
// TODO: Add your command handler code here
CString SelText;
SelText=m_EditView.GetSelText();
CString fonthead;
fonthead.Format(_T("<font height=24 color=255000000 name=宋体 style=2>"));
fonthead+=SelText;
fonthead+=_T("</font>");
m_EditView.ReplaceSel(fonthead,TRUE);
}void CChildView::OnModifyLeft()
{
// TODO: Add your command handler code here
}void CChildView::OnModifyMarker()
{
// TODO: Add your command handler code here
}void CChildView::OnModifyNote()
{
// TODO: Add your command handler code here
}void CChildView::OnModifyPic()
{
// TODO: Add your command handler code here CFileDialog m_OpenPic(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"JPEG FILE(*.jpg)|*.jpg|All File(*.*)|*.*||");
if(m_OpenPic.DoModal()==IDOK)
{
CFile pic(m_OpenPic.GetPathName(),CFile::modeRead|CFile::typeBinary);
unsigned int lenneed,lenread;
lenneed=pic.GetLength();
unsigned char *buf=new unsigned char[lenneed];
pic.SeekToBegin();
lenread=pic.Read(buf,lenneed);
if(lenread!=lenneed)
{
MessageBox("打开图片文件出错","错误");
pic.Close();
return;
}
for(int i=0;i<lenread;i++)//测试打印字符
if(!_istprint(buf[i]))
buf[i]='.';
CString imghead;
imghead.Format(_T("<img name=\"个人照片\" height=50 width=50align=1 href=\"xx.feb\" format=\"jpeg\" size=%d>"),lenread);
m_EditView.ReplaceSel(imghead);
m_EditView.ReplaceSel((LPCTSTR)buf,TRUE);
delete []buf;
pic.Close();
}
}void CChildView::OnModifyRight()
{
// TODO: Add your command handler code here
}void CChildView::OnModifyTag()
{
// TODO: Add your command handler code here
}void CChildView::OnModifyTitle()
{
// TODO: Add your command handler code here
}void CChildView::OnEditAutoline()
{
// TODO: Add your command handler code here
m_IsAutoLine=!m_IsAutoLine;
if(m_IsAutoLine)
m_EditView.ModifyStyle(WS_HSCROLL| ES_AUTOHSCROLL ,0,0);
else
m_EditView.ModifyStyle(0,WS_HSCROLL| ES_AUTOHSCROLL ,0);
}void CChildView::OnUpdateEditAutoline(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_IsAutoLine);
}