📄 coloreditdoc.cpp
字号:
// ColorEditDoc.cpp : implementation of the CColorEditDoc class
//
// Copyright (c) 1996-1997, Keith Rule
// You may freely use or modify this code provided this
// copyright is included in all derived versions.
#include "stdafx.h"
#include "ColorEdit.h"
#include "ColorEditDoc.h"
#include "ProgressBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CColorEditDoc
extern COLORREF KeywordColor;
//extern COLORREF BugColor;
extern COLORREF PmacKeywordColor;
extern COLORREF PVariableColor;
extern COLORREF QVariableColor;
extern COLORREF IVariableColor;
extern COLORREF MVariableColor;
IMPLEMENT_DYNCREATE(CColorEditDoc, CDocument)
BEGIN_MESSAGE_MAP(CColorEditDoc, CDocument)
//{{AFX_MSG_MAP(CColorEditDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(CColorEditDoc, CDocument)
//{{AFX_DISPATCH_MAP(CColorEditDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
// Note: we add support for IID_IColorEdit to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
// {F6898245-462B-11D1-B99D-00A0C9763A0A}
static const IID IID_IColorEdit =
{ 0xf6898245, 0x462b, 0x11d1, { 0xb9, 0x9d, 0x0, 0xa0, 0xc9, 0x76, 0x3a, 0xa } };
BEGIN_INTERFACE_MAP(CColorEditDoc, CDocument)
INTERFACE_PART(CColorEditDoc, IID_IColorEdit, Dispatch)
END_INTERFACE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CColorEditDoc construction/destruction
CColorEditDoc::CColorEditDoc() : CUndo(25, 64*1024)
{
////各变量的三个分量值,辅助作用
int PVariableR,PVariableG,PVariableB; //1
int MVariableR,MVariableG,MVariableB; //2
int IVariableR,IVariableG,IVariableB; //3
int QVariableR,QVariableG,QVariableB; //4
int KeywordR,KeywordG,KeywordB; //5
int PmacKeywordR,PmacKeywordG,PmacKeywordB;//6
////////打开文件,以便进行读取数据操作
CFile myfile;
CString str;
myfile.Open("colordefine.txt",CFile::modeRead);
char pbuf[1024];
myfile.Read(pbuf,1024);
myfile.Close();
str = (CString)pbuf;
/////////////////////////////////
CString str1="PVariableColor:";
CString str2="MVariableColor:";
CString str3="IVariableColor:";
CString str4="QVariableColor:";
CString str5="KeywordColor:";
CString str6="PmacKeywordColor:";
CString str7="End";
long RGBvalue;
int length;
int indexa,indexb;
////////////////////////////////////////////////////////// P_variable 1
indexa=str.Find(str1);
indexb=str.Find(str2);
length=indexb-(indexa+str1.GetLength());
//CString straux=str.Left(indexb);
RGBvalue=atoi(str.Left(indexb).Right(length));
PVariableR=RGBvalue&255;
PVariableG=(RGBvalue&65280)/256;
PVariableB=(RGBvalue&16711680)/256/256;
PVariableColor=RGB(PVariableR,PVariableG,PVariableB);
////////////////////////////////////////////////////////// M_variable 2
indexa=str.Find(str2);
indexb=str.Find(str3);
length=indexb-(indexa+str2.GetLength());
RGBvalue=atoi(str.Left(indexb).Right(length));
MVariableR=RGBvalue&255;
MVariableG=(RGBvalue&65280)/256;
MVariableB=(RGBvalue&16711680)/256/256;
MVariableColor=RGB(MVariableR,MVariableG,MVariableB);
///////////////////////////////////////////////////////////////// I_variable 3
indexa=str.Find(str3);
indexb=str.Find(str4);
length=indexb-(indexa+str3.GetLength());
RGBvalue=atoi(str.Left(indexb).Right(length));
IVariableR=RGBvalue&255;
IVariableG=(RGBvalue&65280)/256;
IVariableB=(RGBvalue&16711680)/256/256;
IVariableColor=RGB(IVariableR,IVariableG,IVariableB);
///////////////////////////////////////////////////////////////// Q_variable 4
indexa=str.Find(str4);
indexb=str.Find(str5);
length=indexb-(indexa+str4.GetLength());
RGBvalue=atoi(str.Left(indexb).Right(length));
QVariableR=RGBvalue&255;
QVariableG=(RGBvalue&65280)/256;
QVariableB=(RGBvalue&16711680)/256/256;
QVariableColor=RGB(QVariableR,QVariableG,QVariableB);
////////////////////////////////////////////////////////////////// Keyword 5
indexa=str.Find(str5);
indexb=str.Find(str6);
length=indexb-(indexa+str5.GetLength());
RGBvalue=atoi(str.Left(indexb).Right(length));
KeywordR=RGBvalue&255;
KeywordG=(RGBvalue&65280)/256;
KeywordB=(RGBvalue&16711680)/256/256;
KeywordColor=RGB(KeywordR,KeywordG,KeywordB);
//////////////////////////////////////////////////////////////// PmacKeyword 6
indexa=str.Find(str6);
indexb=str.Find(str7);
length=indexb-(indexa+str6.GetLength());
RGBvalue=atoi(str.Left(indexb).Right(length));
PmacKeywordR=RGBvalue&255;
PmacKeywordG=(RGBvalue&65280)/256;
PmacKeywordB=(RGBvalue&16711680)/256/256;
PmacKeywordColor=RGB(PmacKeywordR,PmacKeywordG,PmacKeywordB);
////////////////////////////////////////////////////////////////////// The End
///////////////////////////////////////// Left part of the oriental programme
KeywordsSettings();
m_text.AddUpdateTarget(this);
EnableAutomation();
AfxOleLockApp();
}
CColorEditDoc::~CColorEditDoc()
{
AfxOleUnlockApp();
}
BOOL CColorEditDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
CheckPoint();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CColorEditDoc serialization
void CColorEditDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar << m_text;
}
else
{
ar >> m_text;
}
}
/////////////////////////////////////////////////////////////////////////////
// CColorEditDoc diagnostics
#ifdef _DEBUG
void CColorEditDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CColorEditDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CColorEditDoc commands
void CColorEditDoc::DeleteContents()
{
m_text = _T("");
}
void CColorEditDoc::DoColorStringUpdate(BOOL bDataChangedFlag)
{
POSITION pos = GetFirstViewPosition();
while (pos != NULL) {
CView* pView = GetNextView(pos);
if (pView != NULL)
pView->Invalidate();
}
if (bDataChangedFlag) SetModifiedFlag();
}
BOOL CColorEditDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
TCHAR buffer[256];
CProgressBar bar(_T("Reading:"), 40);
m_text.BeginUpdate();
try {
CStdioFile file(lpszPathName, CFile::modeRead | CFile::typeText);
long count = 0;
long length = file.GetLength();
long pos = 0;
bar.SetPos(0);
do {
memset(buffer, 0, sizeof(buffer));
count = file.Read(buffer, sizeof(buffer)-1);
m_text += buffer;
pos += count;
bar.SetPos((int) ((70.0)*((double) pos)/((double) length)));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -