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

📄 wediterview.cpp

📁 微型文本编辑器. 多文档界面
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// WediterView.cpp : implementation of the CWediterView class
//

#include "stdafx.h"
#include "Wediter.h"
#include "MainFrm.h"

#include "InsChar.h"
#include "Finder.h"
#include "GotoDalg.h"
#include "InsWord.h"
#include "insupdntext.h"
#include "Sheet.h"
/*AutoCAD 
#include <acad15.h>
#include <acdb.h>
#include <string.h>
#include <aced.h>
#include <dbents.h>
#include <dbsymtb.h>
#include <dbgroup.h>
#include <dbapserv.h>
*/
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWediterView

IMPLEMENT_DYNCREATE(CWediterView, CEditView)

BEGIN_MESSAGE_MAP(CWediterView, CEditView)
	//{{AFX_MSG_MAP(CWediterView)
	ON_COMMAND(ID_EDIT_LORWER, OnEditLorwer)
	ON_COMMAND(ID_EDIT_UPPER, OnEditUpper)
	ON_COMMAND(ID_TOOL_FONTS, OnToolFonts)
	ON_COMMAND(ID_TOOL_INSCHAR, OnToolInschar)
	ON_UPDATE_COMMAND_UI(ID_EDIT_UPPER, OnUpdateEditUpper)
	ON_COMMAND(ID_TOOL_BACKCOLOR, OnToolBackcolor)
	ON_WM_LBUTTONUP()
	ON_WM_CHAR()
	ON_WM_SETFOCUS()
	ON_WM_KEYDOWN()
	ON_COMMAND(ID_EDIT_FIND, OnEditFind)
	ON_UPDATE_COMMAND_UI(ID_EDIT_REPEAT, OnUpdateEditRepeat)
	ON_COMMAND(ID_EDIT_REPEAT, OnEditRepeat)
	ON_WM_LBUTTONDOWN()
	ON_COMMAND(ID_EDIT_REPLACE, OnEditReplace)
	ON_COMMAND(ID_EDIT_GOTO, OnEditGoto)
	ON_UPDATE_COMMAND_UI(ID_EDIT_GOTO, OnUpdateEditGoto)
	ON_WM_DESTROY()
	ON_COMMAND(ID_TOOL_INSWORD, OnToolInsword)
	ON_WM_CREATE()
	ON_WM_ERASEBKGND()
	ON_WM_CTLCOLOR_REFLECT()
	ON_UPDATE_COMMAND_UI(ID_FORMAT_DOWNLINE, OnUpdateFormatDownline)
	ON_UPDATE_COMMAND_UI(ID_FORMAT_DOWNTEXT, OnUpdateFormatDowntext)
	ON_UPDATE_COMMAND_UI(ID_FORMAT_UPLINE, OnUpdateFormatUpline)
	ON_UPDATE_COMMAND_UI(ID_FORMAT_UPTEXT, OnUpdateFormatUptext)
	ON_COMMAND(ID_FORMAT_DOWNLINE, OnFormatDownline)
	ON_COMMAND(ID_FORMAT_DOWNTEXT, OnFormatDowntext)
	ON_COMMAND(ID_FORMAT_UPDOWNTEXT, OnFormatUpdowntext)
	ON_COMMAND(ID_FORMAT_UPLINE, OnFormatUpline)
	ON_COMMAND(ID_FORMAT_UPTEXT, OnFormatUptext)
	ON_COMMAND(ID_TOOL_SHEET, OnToolSheet)
	ON_UPDATE_COMMAND_UI(ID_EDIT_LORWER, OnUpdateEditUpper)
	ON_COMMAND(ID_FILE_ALLCLOSE, OnFileAllclose)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CEditView::OnFilePrintPreview)
END_MESSAGE_MAP()


//UINT CWediterView::m_nDefTabStops;
//UINT CWediterView::m_nDefTabStopsOld;
LOGFONT NEAR CWediterView::m_lfDefFont;
LOGFONT NEAR CWediterView::m_lfDefFontOld;

COLORREF CWediterView::m_colors;
COLORREF CWediterView::m_oldcolors;
COLORREF CWediterView::m_backcolors;
COLORREF CWediterView::m_oldbackcolors;

int CWediterView::m_nundown;

//LOGFONT NEAR CWediterView::m_lfDefPrintFont;
//LOGFONT NEAR CWediterView::m_lfDefPrintFontOld;


// Static initialization/termination

static TCHAR BASED_CODE szSettings[] = _T("Settings");
static TCHAR BASED_CODE szTextColor[] = _T("TextColor");
static TCHAR BASED_CODE szBlockColor[] = _T("BlockColor");
static TCHAR BASED_CODE szNUnDown[] = _T("NUnDown");


static TCHAR BASED_CODE szFont[] = _T("Font");
static TCHAR BASED_CODE szPrintFont[] = _T("PrintFont");
static TCHAR BASED_CODE szHeight[] = _T("Height");
static TCHAR BASED_CODE szWeight[] = _T("Weight");
static TCHAR BASED_CODE szItalic[] = _T("Italic");
static TCHAR BASED_CODE szUnderline[] = _T("Underline");
static TCHAR BASED_CODE szPitchAndFamily[] = _T("PitchAndFamily");
static TCHAR BASED_CODE szCharSet[] = _T("CharSet");
static TCHAR BASED_CODE szFaceName[] = _T("FaceName");
static TCHAR BASED_CODE szSystem[] = _T("System");

static TCHAR BASED_CODE szCharname[] = _T("Charname");
static TCHAR BASED_CODE szWordname[] = _T("Wordname");
static TCHAR BASED_CODE szIcon[] = _T("Icon");
static TCHAR BASED_CODE szRowCol[] = _T("RowCol");
static TCHAR BASED_CODE szStats[] = _T("Stats");
static TCHAR BASED_CODE szTimeis[] = _T("Timeis");
static TCHAR BASED_CODE szTools[] = _T("Tools");
static TCHAR BASED_CODE szTabStops[] = _T("TabStops");

static void GetProfileFont(LPCTSTR szSec, LOGFONT* plf)
{
	CWinApp* pApp = AfxGetApp();
	plf->lfHeight = pApp->GetProfileInt(szSec, szHeight, 0);
	if (plf->lfHeight != 0)
	{
		plf->lfWeight = pApp->GetProfileInt(szSec, szWeight, 0);
		plf->lfItalic = (BYTE)pApp->GetProfileInt(szSec, szItalic, 0);
		plf->lfUnderline = (BYTE)pApp->GetProfileInt(szSec, szUnderline, 0);
		plf->lfPitchAndFamily = (BYTE)pApp->GetProfileInt(szSec, szPitchAndFamily, 0);
		plf->lfCharSet = (BYTE)pApp->GetProfileInt(szSec, szCharSet, DEFAULT_CHARSET);
		CString strFont = pApp->GetProfileString(szSec, szFaceName, szSystem);
		lstrcpyn((TCHAR*)plf->lfFaceName, strFont, sizeof plf->lfFaceName);
		plf->lfFaceName[sizeof plf->lfFaceName-1] = 0;
	}
}

static void WriteProfileFont(LPCTSTR szSec, const LOGFONT* plf, LOGFONT* plfOld)
{
	CWinApp* pApp = AfxGetApp();

	if (plf->lfHeight != plfOld->lfHeight)
		pApp->WriteProfileInt(szSec, szHeight, plf->lfHeight);
	if (plf->lfHeight != 0)
	{
		if (plf->lfHeight != plfOld->lfHeight)
			pApp->WriteProfileInt(szSec, szHeight, plf->lfHeight);
		if (plf->lfWeight != plfOld->lfWeight)
			pApp->WriteProfileInt(szSec, szWeight, plf->lfWeight);
		if (plf->lfItalic != plfOld->lfItalic)
			pApp->WriteProfileInt(szSec, szItalic, plf->lfItalic);
		if (plf->lfUnderline != plfOld->lfUnderline)
			pApp->WriteProfileInt(szSec, szUnderline, plf->lfUnderline);
		if (plf->lfPitchAndFamily != plfOld->lfPitchAndFamily)
			pApp->WriteProfileInt(szSec, szPitchAndFamily, plf->lfPitchAndFamily);
		if (plf->lfCharSet != plfOld->lfCharSet)
			pApp->WriteProfileInt(szSec, szCharSet, plf->lfCharSet);
		if (_tcscmp(plf->lfFaceName, plfOld->lfFaceName) != 0)
			pApp->WriteProfileString(szSec, szFaceName, (LPCTSTR)plf->lfFaceName);
	}
	*plfOld = *plf;
}

void CWediterView::Initialize()
{
	CWinApp* pApp = AfxGetApp();
	m_colors = pApp->GetProfileInt(szSettings, szTextColor, RGB(0,0,0));
	m_oldcolors=m_colors;
	m_backcolors = pApp->GetProfileInt(szSettings, szBlockColor, RGB(255,255,255));
	m_oldbackcolors=m_backcolors;
	m_nundown = pApp->GetProfileInt(szSettings, szNUnDown, 1);
	//m_oldnundown = m_nundown;
	
	gapp.charname=pApp->GetProfileString(szSettings, szCharname, GetAppPath()+"TxtChars.dat");
	gapp.wordname=pApp->GetProfileString(szSettings, szWordname, GetAppPath()+"TxtWord.dat");
	gapp.icon=pApp->GetProfileInt(szSettings, szIcon, 0);
	gapp.rowcol=pApp->GetProfileInt(szSettings, szRowCol, 1);
	gapp.stats=pApp->GetProfileInt(szSettings, szStats, 1);
	gapp.tabs=pApp->GetProfileInt(szSettings, szTabStops, 8);
	gapp.time=pApp->GetProfileInt(szSettings, szTimeis, 1);
	gapp.tool=pApp->GetProfileInt(szSettings, szTools, 1);

	GetProfileFont(szFont, &m_lfDefFont);
	m_lfDefFontOld = m_lfDefFont;

	//GetProfileFont(szPrintFont, &m_lfDefPrintFont);
	//m_lfDefPrintFontOld = m_lfDefPrintFont;
}

/////////////////////////////////////////////////////////////////////////////
// CWediterView construction/destruction


CWediterView::CWediterView()
{
	// TODO: add construction code here
}


CWediterView::~CWediterView()
{
}

CWediterView* pview;

Appstruct gapp;

CWediterView* getview()
{
	CWediterView* p_view=(CWediterView*)
 		AfxGetApp()->m_pMainWnd->GetTopWindow()->GetDescendantWindow(AfxGetApp()->m_pMainWnd->GetTopWindow()->GetDlgCtrlID());
	if(p_view)
		return p_view;
	else
		return	NULL;
	p_view=NULL;
	delete p_view;
}


BOOL CWediterView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	BOOL bPreCreated = CEditView::PreCreateWindow(cs);
	cs.style &= ~(ES_AUTOHSCROLL);	// Enable word-wrapping 

	SetFinder();
	CloseView(FALSE);

	return bPreCreated;
}
/////////////////////////////////////////////////////////////////////////////
// CWediterView drawing

/////////////////////////////////////////////////////////////////////////////
// CWediterView printing

BOOL CWediterView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default CEditView preparation
	return CEditView::OnPreparePrinting(pInfo);
}

void CWediterView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView begin printing.
	CEditView::OnBeginPrinting(pDC, pInfo);
}

void CWediterView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView end printing
	CEditView::OnEndPrinting(pDC, pInfo);
}

/////////////////////////////////////////////////////////////////////////////
// CWediterView diagnostics

#ifdef _DEBUG
void CWediterView::AssertValid() const
{
	CEditView::AssertValid();
}

void CWediterView::Dump(CDumpContext& dc) const
{
	
	CEditView::Dump(dc);
}

CWediterDoc* CWediterView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWediterDoc)));

	return (CWediterDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CWediterView message handlers



void CWediterView::OnEditLorwer() 
{
	// TODO: Add your command handler code here
	CString mstr;
	mstr=Getselstext();
	if (!mstr.IsEmpty())
	{
		int nFrom, nTo;
		GetEditCtrl().GetSel(nFrom,nTo);
		mstr.MakeLower();
		GetEditCtrl().ReplaceSel(mstr,TRUE);
		GetEditCtrl().SetSel(nFrom,nTo,TRUE);
	}
}

void CWediterView::OnEditUpper() 
{
	// TODO: Add your command handler code here
	CString mstr;
	mstr=Getselstext();
	if (!mstr.IsEmpty())
	{
		int nFrom, nTo;
		GetEditCtrl().GetSel(nFrom,nTo);
		mstr.MakeUpper();
		GetEditCtrl().ReplaceSel(mstr,TRUE);
		GetEditCtrl().SetSel(nFrom,nTo,TRUE);
	}
	//COleDispatchDriver ACADapp;
	//AcDbEntity *pEntity;
}

void CWediterView::OnToolFonts() 
{
	// TODO: Add your command handler code here
    CFont* pFont = GetFont();
    LOGFONT lf;
	if(m_lfDefFont.lfHeight!=0)
		lf=m_lfDefFont;
	else if(pFont != NULL)
	   pFont->GetObject(sizeof(LOGFONT), &lf);
  else
	   ::GetObject(GetStockObject(SYSTEM_FONT), sizeof(LOGFONT), &lf);

	CFontDialog dlg(&lf);
	if (dlg.DoModal() == IDOK)
	{
		m_txtcolor=dlg.GetColor();
		m_colors=m_txtcolor;
		m_font.DeleteObject();
		if (m_font.CreateFontIndirect(&lf))
		{
			SetFont(&m_font);
			m_lfDefFont = lf;
		}
		if(m_blkcolor==m_txtcolor)
    {
			m_blkcolor=RGB(255,255,255)-m_txtcolor;
			m_backcolors=m_blkcolor;
    }
		SetRedraw();
	}
}


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

	CWnd *pWndPrev;
	if (pWndPrev = CWnd::FindWindow(_T("#32770"),"插入符号"))
	{
		pWndPrev->SetFocus();
		pWndPrev=NULL;
	}
	else
	{
		CString mstr,fm;
		CStdioFile file;
		if(gapp.charname.IsEmpty())
			gapp.charname=GetAppPath()+"TxtChars.dat";
		fm=gapp.charname;
		if (file.Open(fm,CFile::modeRead|CFile::typeText))
		{
			file.ReadString(mstr);
			file.Close();
			CInsChar *dlg=new CInsChar(this);
			dlg->m_chars=mstr;
			dlg->Create(IDD_INSCHAR,this);
			dlg->ShowWindow(SW_SHOW);
			dlg=NULL;
			delete dlg;
		}
		else
			MessageBox("文件<+fm+>不存在,或已坏!",NULL,MB_ICONERROR);
	}
	pWndPrev=NULL;
	delete pWndPrev;
}

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

void CWediterView::OnToolBackcolor() 
{
	// TODO: Add your command handler code here
	CColorDialog dlg(m_blkcolor);
	if(dlg.DoModal()==IDOK)
	{
		m_blkcolor=dlg.GetColor();
		m_backcolors=m_blkcolor;
		if(m_blkcolor==m_txtcolor)
    {
			m_txtcolor=RGB(255,255,255)-m_blkcolor;
			m_colors=m_txtcolor;
    }
		SetRedraw();
	}
}


void CWediterView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	ShowRowCol();

	CEditView::OnLButtonUp(nFlags, point);
}

void CWediterView::ShowRowCol()
{
	CStatusBar* pStatus=(CStatusBar *)
		AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);
	if(pStatus && gapp.rowcol==1) 
	{
		//wsprintf(text,"x=%d,y=%d",point.x,point.y);
		CString srow,scol;
		int nrow,ncol,nFrom, nTo;
		GetEditCtrl().GetSel(nFrom,nTo);
		nrow=GetEditCtrl().LineFromChar();
		ncol=GetEditCtrl().LineIndex();
		srow.Format("%d",nrow+1);
		scol.Format("%d",nFrom-ncol+1);
		pStatus->SetPaneText(1,"Row:"+srow);
		pStatus->SetPaneText(2,"Col:"+scol);
	}
	pStatus=NULL;
	delete pStatus;
}

⌨️ 快捷键说明

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