记事本程序设置字体颜色

2024-11-16 11:46:29
推荐回答(2个)
回答1:

复制粘贴一下

// cseView.h : interface of the CCseView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_CSEVIEW_H__5EC581F1_BEE5_4D81_BDC8_82911EE6826E__INCLUDED_)
#define AFX_CSEVIEW_H__5EC581F1_BEE5_4D81_BDC8_82911EE6826E__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "cseDoc.h"

class CCseView : public CEditView
{
protected: // create from serialization only
CCseView();
DECLARE_DYNCREATE(CCseView)
CFont m_Font;
// Attributes
public:
CCseDoc* GetDocument();

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCseView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual CScrollBar* GetScrollBarCtrl(int nBar) const;
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL

// Implementation
public:
virtual void OnSETFont();
virtual ~CCseView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
//{{AFX_MSG(CCseView)
afx_msg void OnEditUndo();
afx_msg void OnEditCut();
afx_msg void OnEditPaste();
afx_msg void OnEditCopy();
afx_msg void OnMenuitem32771();
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMenuitem32772();
afx_msg void OnMenuitem32773();
afx_msg void OnMenuitem32774();
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
afx_msg void OnKillfocus();
afx_msg void OnFontChange();
afx_msg void OnMenuitem32775();
afx_msg void OnMenuitem32776();
afx_msg void OnMenuitem32777();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG // debug version in cseView.cpp
inline CCseDoc* CCseView::GetDocument()
{ return (CCseDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CSEVIEW_H__5EC581F1_BEE5_4D81_BDC8_82911EE6826E__INCLUDED_)

// cseView.cpp : implementation of the CCseView class
//

#include "stdafx.h"
#include "cse.h"

#include "cseDoc.h"
#include "cseView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCseView

IMPLEMENT_DYNCREATE(CCseView, CEditView)

BEGIN_MESSAGE_MAP(CCseView, CEditView)
//{{AFX_MSG_MAP(CCseView)
ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
ON_COMMAND(ID_EDIT_CUT, OnEditCut)
ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
ON_COMMAND(ID_MENUITEM32771, OnMenuitem32771)
ON_WM_RBUTTONDOWN()
ON_COMMAND(ID_MENUITEM32772, OnMenuitem32772)
ON_COMMAND(ID_MENUITEM32773, OnMenuitem32773)
ON_COMMAND(ID_MENUITEM32774, OnMenuitem32774)
ON_WM_CTLCOLOR_REFLECT()
ON_CONTROL_REFLECT(EN_KILLFOCUS, OnKillfocus)
ON_WM_FONTCHANGE()
ON_COMMAND(ID_MENUITEM32775, OnMenuitem32775)
ON_COMMAND(ID_MENUITEM32776, OnMenuitem32776)
ON_COMMAND(ID_MENUITEM32777, OnMenuitem32777)
ON_WM_CREATE()
//}}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()

/////////////////////////////////////////////////////////////////////////////
// CCseView construction/destruction

CCseView::CCseView()
{
// TODO: add construction code here

}

CCseView::~CCseView()
{
}

BOOL CCseView::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|WS_HSCROLL); // Enable word-wrapping

return bPreCreated;
}

/////////////////////////////////////////////////////////////////////////////
// CCseView drawing

void CCseView::OnDraw(CDC* pDC)
{
CCseDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here

}

/////////////////////////////////////////////////////////////////////////////
// CCseView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CCseView diagnostics

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

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

CCseDoc* CCseView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCseDoc)));
return (CCseDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CCseView message handlers

void CCseView::OnEditUndo()
{
// TODO: Add your command handler code here
this->GetEditCtrl().Undo();
}

void CCseView::OnEditCut()
{
// TODO: Add your command handler code here
this->GetEditCtrl().Cut();
}

void CCseView::OnEditPaste()
{
// TODO: Add your command handler code here
this->GetEditCtrl().Paste();
}

void CCseView::OnEditCopy()
{
// TODO: Add your command handler code here
this->GetEditCtrl().Copy();
}

void CCseView::OnMenuitem32771()
{
// TODO: Add your command handler code here
LOGFONT lf;
//得到当前字体
CFont *font=this->GetEditCtrl().GetFont();
//当前无字体,创建默认的字体
if(font==NULL)
{
font =new CFont;
font->CreatePointFont(120,"Fixedsys");
font->GetLogFont(&lf);
delete font;
}
else
{
font->GetLogFont(&lf);
}
CFontDialog cf(&lf);
if(cf.DoModal()==IDOK)
{
this->m_Font.DeleteObject();
this->m_Font.CreateFontIndirect(&lf);
this->SetFont(&this->m_Font);
}
}

void CCseView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

CEditView::OnRButtonDown(nFlags, point);
}

void CCseView::OnMenuitem32772()
{
// TODO: Add your command handler code here
this->GetEditCtrl().SetSel(0,-1);
}

void CCseView::OnMenuitem32773()
{
// TODO: Add your command handler code here
this->GetEditCtrl().Clear();
}

void CCseView::OnMenuitem32774()
{
// TODO: Add your command handler code here

}

HBRUSH CCseView::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
return NULL;
}

void CCseView::OnKillfocus()
{
// TODO: Add your control notification handler code here

}

void CCseView::OnFontChange()
{
CEditView::OnFontChange();

// TODO: Add your message handler code here

}
void CCseView::OnSETFont()
{

}

void CCseView::OnMenuitem32775()
{
// TODO: Add your command handler code here

}

CScrollBar* CCseView::GetScrollBarCtrl(int nBar) const
{
// TODO: Add your specialized code here and/or call the base class

return CEditView::GetScrollBarCtrl(nBar);
}

void CCseView::OnMenuitem32776()
{
// TODO: Add your command handler code here
CString str;
str="IEXPLORE.EXE"+m_pDocument-> GetPathName();
WinExec( str,SW_SHOW);
}

void CCseView::OnMenuitem32777()
{
// TODO: Add your command handler code here

}

int CCseView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CEditView::OnCreate(lpCreateStruct) == -1)
return -1;

// TODO: Add your specialized creation code here

return 0;
}

回答2:

CFontDialog不行吗?