记事本程序设置字体颜色
我想在点“格式”->“字体”的时候设置字体的属性,比如大小,下划线等等,当然还有颜色,而这个问题也还没有解决。我创建的类是YQNotepad,继承了CEditView,下...
我想在点“格式”->“字体”的时候设置字体的属性,比如大小,下划线等等,当然还有颜色,而这个问题也还没有解决。我创建的类是YQNotepad,继承了CEditView,下面是设置字体属性的核心代码:
void CYQNotepadView::OnFormatFont()
{
// 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); //初始化LOGFONT
delete font;
}
else
{
font->GetLogFont(&lf); //初始化LOGFONT
}
CFontDialog dlg(&lf);
if(dlg.DoModal()==IDOK)
{
this->m_Font.DeleteObject();
this->m_Font.CreateFontIndirect(&lf); //创建字体
this->SetFont(&this->m_Font);
}
}
请问怎么在代码中实现设置字体颜色的功能?如需源码,请留言,能达到要求者必追加。 展开
void CYQNotepadView::OnFormatFont()
{
// 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); //初始化LOGFONT
delete font;
}
else
{
font->GetLogFont(&lf); //初始化LOGFONT
}
CFontDialog dlg(&lf);
if(dlg.DoModal()==IDOK)
{
this->m_Font.DeleteObject();
this->m_Font.CreateFontIndirect(&lf); //创建字体
this->SetFont(&this->m_Font);
}
}
请问怎么在代码中实现设置字体颜色的功能?如需源码,请留言,能达到要求者必追加。 展开
2个回答
展开全部
复制粘贴一下
// 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;
}
// 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;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
博思aippt
2024-07-20 广告
2024-07-20 广告
作为深圳市博思云创科技有限公司的工作人员,对于Word文档生成PPT的操作,我们有以下建议:1. 使用另存为功能:在Word中编辑完文档后,点击文件->另存为,选择PowerPoint演示文稿(*.pptx)格式,即可将文档内容转换为PPT...
点击进入详情页
本回答由博思aippt提供
展开全部
CFontDialog不行吗?
参考资料: http://hi.baidu.com/zhaocy0113/blog/item/517a66ec4e585cd02e2e2151.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询