gdiview.cpp
来自「MFC编程实例」· C++ 代码 · 共 110 行
CPP
110 行
#include "stdafx.h"
#include "GDI.h"
#include "GDIDoc.h"
#include "GDIView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CGDIView, CView)
BEGIN_MESSAGE_MAP(CGDIView, CView)
//{{AFX_MSG_MAP(CGDIView)
//}}AFX_MSG_MAP
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
CGDIView::CGDIView()
{
LPLOGPALETTE lpLogPal;
int i;
lpLogPal=(LPLOGPALETTE) new BYTE[sizeof(LOGPALETTE)+255*sizeof(PALETTEENTRY)];
lpLogPal->palVersion=0x300;
lpLogPal->palNumEntries=256;
for(i=0; i<256; i++)
{
lpLogPal->palPalEntry[i].peRed=0;
lpLogPal->palPalEntry[i].peGreen=0;
lpLogPal->palPalEntry[i].peBlue=i;
lpLogPal->palPalEntry[i].peFlags=NULL;
}
VERIFY(m_palDraw.CreatePalette(lpLogPal));
delete [](BYTE *)lpLogPal;
}
CGDIView::~CGDIView()
{
}
BOOL CGDIView::PreCreateWindow(CREATESTRUCT& cs)
{
return CView::PreCreateWindow(cs);
}
void CGDIView::OnDraw(CDC *pDC)
{
CPen pen;
CPen *ptrPenOld;
CRect rect;
int i;
CPalette *ptrPalOld;
CGDIDoc *pDoc=GetDocument();
ASSERT_VALID(pDoc);
ptrPalOld=pDC->SelectPalette(&m_palDraw, FALSE);
pDC->RealizePalette();
GetClientRect(rect);
rect.bottom+=255;
rect.bottom/=256;
for(i=0; i<256; i++)
{
pen.CreatePen(PS_SOLID, rect.Height(), PALETTEINDEX(i));
ptrPenOld=pDC->SelectObject(&pen);
pDC->MoveTo(0, rect.top+rect.Height()/2);
pDC->LineTo(rect.right, rect.top);
pDC->SelectObject(ptrPenOld);
pen.DeleteObject();
rect.OffsetRect(0, rect.Height());
}
pDC->SelectPalette(ptrPalOld, FALSE);
}
BOOL CGDIView::OnPreparePrinting(CPrintInfo* pInfo)
{
return DoPreparePrinting(pInfo);
}
void CGDIView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
}
void CGDIView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
}
#ifdef _DEBUG
void CGDIView::AssertValid() const
{
CView::AssertValid();
}
void CGDIView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CGDIDoc* CGDIView::GetDocument()
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGDIDoc)));
return (CGDIDoc*)m_pDocument;
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?