createfromdcview.cpp
来自「Visual C++编程宝典随书光盘里的代码」· C++ 代码 · 共 115 行
CPP
115 行
// CreateFromDCView.cpp : implementation of the CCreateFromDCView class
//
#include "stdafx.h"
#include "CreateFromDC.h"
#include "CreateFromDCDoc.h"
#include "CreateFromDCView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCreateFromDCView
IMPLEMENT_DYNCREATE(CCreateFromDCView, CView)
BEGIN_MESSAGE_MAP(CCreateFromDCView, CView)
//{{AFX_MSG_MAP(CCreateFromDCView)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCreateFromDCView construction/destruction
CCreateFromDCView::CCreateFromDCView()
{
m_bSaved = FALSE;
}
CCreateFromDCView::~CCreateFromDCView()
{
}
BOOL CCreateFromDCView::PreCreateWindow(CREATESTRUCT& cs)
{
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCreateFromDCView drawing
void CCreateFromDCView::OnDraw(CDC* pDC)
{
CCreateFromDCDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
RECT Rect;
GetClientRect( &Rect );
for( int y=0; y<Rect.bottom; y++ ){
int nRed = ( 256 * y ) / Rect.bottom;
int nGreen = ( 384 * y ) / Rect.bottom;
int nBlue = ( 512 * y ) / Rect.bottom;
CPen Pen( PS_SOLID, 1,
RGB( nRed, nGreen, nBlue ) );
CPen *pOldPen = pDC->SelectObject( &Pen );
pDC->MoveTo( 0, y );
pDC->LineTo( Rect.right, y );
pDC->SelectObject( pOldPen );
}
if( !m_bSaved ){
m_bSaved = TRUE;
CImageObject *pImage = new CImageObject( pDC, 0, 0,
Rect.right, Rect.bottom );
if( pImage != NULL ){
pImage->ChangeFormat( 8 );
pImage->Save( "Test.gif" );
delete pImage;
}
pImage = new CImageObject( pDC, 0, 0,
Rect.right, Rect.bottom );
if( pImage != NULL ){
pImage->ChangeFormat( 24 );
pImage->Save( "Test.jpg" );
delete pImage;
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CCreateFromDCView diagnostics
#ifdef _DEBUG
void CCreateFromDCView::AssertValid() const
{
CView::AssertValid();
}
void CCreateFromDCView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCreateFromDCDoc* CCreateFromDCView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCreateFromDCDoc)));
return (CCreateFromDCDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCreateFromDCView message handlers
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?