⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wediterview.cpp

📁 微型文本编辑器. 多文档界面
💻 CPP
📖 第 1 页 / 共 2 页
字号:
void CWediterView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	ShowRowCol();
	
	CEditView::OnChar(nChar, nRepCnt, nFlags);
}

 void CWediterView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
 {
 	// TODO: Add your message handler code here and/or call default
 	if (nChar>=VK_LEFT && nChar<=VK_DOWN)
 		ShowRowCol();
 	CEditView::OnKeyDown(nChar, nRepCnt, nFlags);
 }

void CWediterView::OnSetFocus(CWnd* pOldWnd) 
{
	CEditView::OnSetFocus(pOldWnd);

	// TODO: Add your message handler code here
	ShowRowCol();
	pview=this;

}

void CWediterView::OnEditFind() 
{
	// TODO: Add your command handler code here
	finding();
}

void CWediterView::OnUpdateEditRepeat(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(fd.bfind && !fd.text.IsEmpty());
}

void CWediterView::OnEditRepeat() 
{
	// TODO: Add your command handler code here

	if(FindText(fd.text,fd.inext==1,fd.icase==1))
	{
		ShowmessgeBar("找到\""+fd.text+"\"");
		fd.icount=fd.icount+1;
	}
	else
	{
		if(fd.icount==0)
			ShowmessgeBar("没有找到!");
		else
		{
			CString mstr;
			mstr.Format("%d",fd.icount);
			ShowmessgeBar("找到\""+mstr+"\"处");
		}
		fd.bfind=FALSE;
		fd.icount=0;
	}
}

void CWediterView::SetFinder(CString text,int inext,int icase,int icount,bool bfind)
{
	fd.text=text;fd.inext=inext;fd.icase=icase,fd.icount=icount;fd.bfind=bfind;
}

void CWediterView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	fd.bfind=TRUE;
	CEditView::OnLButtonDown(nFlags, point);
}





void CWediterView::finding(bool breplace)
{
	CWnd *pWndPrev;
	if ((pWndPrev = CWnd::FindWindow(_T("#32770"),"查找")) || (pWndPrev = CWnd::FindWindow(_T("#32770"),"替换")))
	{
		pWndPrev->SetFocus();
		pWndPrev=NULL;
	}
	else
	{
		CString mstr;
		mstr=Getselstext();
		fd.bfind=!mstr.IsEmpty();
		if(mstr.IsEmpty())
		{
			CFindComboBx* P_Cbox=(CFindComboBx*)
				AfxGetApp()->m_pMainWnd->GetDescendantWindow(IDR_FIND_COMBOBOX);
			if (P_Cbox)
				P_Cbox->GetWindowText(mstr);
			P_Cbox=NULL;
			delete P_Cbox;
		}
		else
			fd.icount=1;
		CFinder *dlg=new CFinder(this);
		dlg->m_findtext=mstr;
		dlg->Create(IDD_FINDER,this);
		dlg->setdalg(breplace);
		dlg->ShowWindow(SW_SHOW);
		dlg=NULL;	
		delete dlg;
	}
	pWndPrev=NULL;
	delete pWndPrev;
}

void CWediterView::OnEditReplace() 
{
	// TODO: Add your command handler code here
	finding(TRUE);
}

void CWediterView::OnEditGoto() 
{
	// TODO: Add your command handler code here
	CWnd *pWndPrev;
	if (pWndPrev = CWnd::FindWindow(_T("#32770"),"定位"))
	{
		pWndPrev->SetFocus();
		pWndPrev=NULL;
	}
	else
	{
		int nFrom;
		nFrom=GetEditCtrl().LineFromChar();
		CGotoDalg *dlg=new CGotoDalg(this);
		dlg->m_gotonumber=nFrom+1;
		dlg->Create(IDD_GOTO,this);
		dlg->ShowWindow(SW_SHOW);
		dlg=NULL;
		delete dlg;
	}
	pWndPrev=NULL;
	delete pWndPrev;
}

void CWediterView::OnUpdateEditGoto(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CString mstr;
	GetWindowText(mstr);
	pCmdUI->Enable(!mstr.IsEmpty());
}

void CWediterView::OnDestroy() 
{
	CEditView::OnDestroy();
	// TODO: Add your message handler code here 

	CWinApp* pApp = AfxGetApp();
	if(m_colors!=m_oldcolors)
		pApp->WriteProfileInt(szSettings, szTextColor, m_colors);
	if(m_backcolors!=m_oldbackcolors)
		pApp->WriteProfileInt(szSettings, szBlockColor, m_backcolors);
	WriteProfileFont(szFont, &m_lfDefFont, &m_lfDefFontOld);
	//WriteProfileFont(szPrintFont, &m_lfDefPrintFont, &m_lfDefPrintFontOld);
	if(AfxGetApp()->m_pMainWnd->GetMenu()->GetMenuItemCount()<5)
	{
		pApp->WriteProfileInt(szSettings, szNUnDown, m_nundown);
		pApp->WriteProfileString(szSettings, szCharname, gapp.charname);
		pApp->WriteProfileString(szSettings, szWordname,gapp.wordname);
		pApp->WriteProfileInt(szSettings, szIcon, gapp.icon);
		pApp->WriteProfileInt(szSettings, szRowCol, gapp.rowcol);
		pApp->WriteProfileInt(szSettings, szStats, gapp.stats);
		pApp->WriteProfileInt(szSettings, szTabStops, gapp.tabs);
		pApp->WriteProfileInt(szSettings, szTimeis, gapp.time);
		pApp->WriteProfileInt(szSettings, szTools, gapp.tool);

		CloseView();
	}
}

void CWediterView::CloseView(bool bclose)
{
	CFindComboBx* P_Cbox=(CFindComboBx*)
		AfxGetApp()->m_pMainWnd->GetDescendantWindow(IDR_FIND_COMBOBOX);
	if(bclose)
	{
		CWnd *pWndPrev;
		if (pWndPrev = CWnd::FindWindow(_T("#32770"),"定位"))
			pWndPrev->DestroyWindow();
		if (pWndPrev = CWnd::FindWindow(_T("#32770"),"查找"))
			pWndPrev->DestroyWindow();
		if (pWndPrev = CWnd::FindWindow(_T("#32770"),"替换"))
			pWndPrev->DestroyWindow();
		if (pWndPrev = CWnd::FindWindow(_T("#32770"),"插入符号"))
			pWndPrev->DestroyWindow();
		if (pWndPrev = CWnd::FindWindow(_T("#32770"),"插入词条"))
			pWndPrev->DestroyWindow();
		if (pWndPrev = CWnd::FindWindow(_T("#32770"),"堆叠文本"))
			pWndPrev->DestroyWindow();
		pWndPrev=NULL;
		delete pWndPrev;
		if (P_Cbox)
			P_Cbox->EnableWindow(FALSE);
	}
	else
	if (P_Cbox)
		P_Cbox->EnableWindow(TRUE);
	P_Cbox=NULL;
	delete P_Cbox;
}


void CWediterView::OnToolInsword() 
{
	// TODO: Add your command handler code here
	CWnd *pWndPrev;
	if (pWndPrev = CWnd::FindWindow(_T("#32770"),"插入词条"))
	{
		pWndPrev->SetFocus();
		pWndPrev=NULL;
	}
	else
	{
		CString mstr1,mstr2,fm;
		CStdioFile file;
		if(gapp.wordname.IsEmpty())
			gapp.wordname=GetAppPath()+"TxtWord.dat";
		fm=gapp.wordname;
		if (file.Open(fm,CFile::modeRead|CFile::typeText))
		{
			while(file.ReadString(mstr2))
			{
				if(mstr1.IsEmpty())
					mstr1=mstr2;
				else
					mstr1=mstr1+"\r\n"+mstr2;
			}
			file.Close();
			CInsWord *dlg=new CInsWord(this);
			dlg->m_words=mstr1;
			dlg->Create(IDD_INSWORD,this);
			dlg->ShowWindow(SW_SHOW);
			dlg=NULL;
			delete dlg;
		}
		else
			MessageBox("文件<"+fm+">不存在,或已坏!",NULL,MB_ICONERROR);
	}
	pWndPrev=NULL;
	delete pWndPrev;
}

int CWediterView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CEditView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	if (m_lfDefFont.lfHeight != 0)
	{
		m_font.CreateFontIndirect(&m_lfDefFont);
		SetFont(&m_font);
	}
	SetTabStops(gapp.tabs);
	m_blkcolor=m_backcolors;
	m_txtcolor=m_colors;

	return 0;
}

BOOL CWediterView::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default

	CBrush brush;
	brush.CreateSolidBrush(m_blkcolor);
	CBrush* pOldBrush = pDC->SelectObject(&brush);
	CRect rc;
	GetClientRect(&rc);
	pDC->Rectangle(&rc);
	pDC->SelectObject(pOldBrush);
  brush.DeleteObject();
  pOldBrush->DeleteObject();
	//return TRUE;
	return CEditView::OnEraseBkgnd(pDC);
}

HBRUSH CWediterView::CtlColor(CDC* pDC, UINT nCtlColor) 
{
	// TODO: Change any attributes of the DC here
	
	// TODO: Return a non-NULL brush if the parent's handler should not be called
	pDC->SetBkColor(m_blkcolor);
	pDC->SetTextColor(m_txtcolor);
	CBrush brush;
	brush.CreateSolidBrush(m_blkcolor);
	return brush;
	//return NULL;

}

void CWediterView::OnUpdateFormatDownline(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(Selsis());
}

bool CWediterView::Selsis()
{
 	int nFrom, nTo;
 	GetEditCtrl().GetSel(nFrom,nTo);
 	return (nTo!=nFrom);
}

CString CWediterView::Getselstext()
{
	int nFrom, nTo;
	CString mstr;
	GetEditCtrl().GetSel(nFrom,nTo);
	if (nTo!=nFrom)
	{
		GetWindowText(mstr);
		mstr=mstr.Mid(nFrom,nTo-nFrom);
	}
	else
		mstr.Empty();
	return mstr;
}

void CWediterView::OnUpdateFormatDowntext(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(Selsis());
}

void CWediterView::OnUpdateFormatUpline(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(Selsis());
}

void CWediterView::OnUpdateFormatUptext(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(Selsis());
}

void CWediterView::OnFormatDownline() 
{
	// TODO: Add your command handler code here
	CString mstr;
	mstr=Getselstext();
	if (!mstr.IsEmpty())
	{
		mstr="{\\L"+mstr+"\\l}";
		GetEditCtrl().ReplaceSel(mstr,TRUE);
	}
	GetEditCtrl().SetWindowText((LPCTSTR)"ABCDEFG");
}

void CWediterView::OnFormatDowntext() 
{
	// TODO: Add your command handler code here
	CString mstr;
	mstr=Getselstext();
	if (!mstr.IsEmpty())
	{
		mstr="{\\H0.625x;\\S^"+mstr+";\\H1.6x;}";
		GetEditCtrl().ReplaceSel(mstr,TRUE);
	}
}

void CWediterView::OnFormatUpdowntext() 
{
	// TODO: Add your command handler code here
	CWnd *pWndPrev;
	if (pWndPrev = CWnd::FindWindow(_T("#32770"),"堆叠文本"))
	{
		pWndPrev->SetFocus();
		pWndPrev=NULL;
	}
	else
	{
		Cinsupdntext *dlg=new Cinsupdntext(this);
		CString mstr;
		mstr=Getselstext();
		if(!mstr.IsEmpty())
			dlg->m_uptext=mstr;
			dlg->m_undown=m_nundown;
		dlg->Create(IDD_UPDNTEXT,this);
		dlg->ShowWindow(SW_SHOW);
		dlg=NULL;	
		delete dlg;
	}
	pWndPrev=NULL;
	delete pWndPrev;
}

void CWediterView::OnFormatUpline() 
{
	// TODO: Add your command handler code here
	CString mstr;
	mstr=Getselstext();
	if (!mstr.IsEmpty())
	{
		mstr="{\\O"+mstr+"\\o}";
		GetEditCtrl().ReplaceSel(mstr,TRUE);
	}
}

void CWediterView::OnFormatUptext() 
{
	// TODO: Add your command handler code here
	CString mstr;
	mstr=Getselstext();
	if (!mstr.IsEmpty())
	{
		mstr="{\\H0.625x;\\S"+mstr+"^;\\H1.6x;}";
		GetEditCtrl().ReplaceSel(mstr,TRUE);
	}
}

void CWediterView::OnToolSheet() 
{
	// TODO: Add your command handler code here
	CSheet dlg("选项",this ,0);
	dlg.DoModal();
}



void CWediterView::OnFileAllclose() 
{
	// TODO: Add your command handler code here

	AfxGetApp()->CloseAllDocuments(FALSE);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -