?? bmp_readview.cpp
字號:
// BMP_READView.cpp : implementation of the CBMP_READView class
//
#include "stdafx.h"
#include "BMP_READ.h"
#include "BMP_READDoc.h"
#include "BMP_READView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBMP_READView
IMPLEMENT_DYNCREATE(CBMP_READView, CView)
BEGIN_MESSAGE_MAP(CBMP_READView, CView)
//{{AFX_MSG_MAP(CBMP_READView)
// 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
// Standard printing commands
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()
/////////////////////////////////////////////////////////////////////////////
// CBMP_READView construction/destruction
CBMP_READView::CBMP_READView()
{
// TODO: add construction code here
}
CBMP_READView::~CBMP_READView()
{
}
BOOL CBMP_READView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CBMP_READView drawing
void CBMP_READView::OnDraw(CDC* pDC)
{
CBMP_READDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CFile cf;
CString TransValue("未命名.bmp");
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;
RGBTRIPLE* rgb;
if (!cf.Open(TransValue,CFile::modeRead/*,&e*/))
{
MessageBox("Can not open the file!","Open File");
return;
}
cf.SeekToBegin();
cf.Read(&bmfh,sizeof(BITMAPFILEHEADER));//讀取文件頭
cf.Read(&bmih,sizeof(BITMAPINFOHEADER));//讀取文件信息頭
rgb=new RGBTRIPLE[bmih.biWidth*bmih.biHeight];
cf.SeekToBegin();
cf.Seek(54,CFile::begin);
//讀取文件數據
if(cf.GetLength()>64*1024)
{
cf.ReadHuge(rgb,bmih.biWidth*bmih.biHeight*3);
}
else
{
cf.Read(rgb,bmih.biWidth*bmih.biHeight);
}
//在屏幕上打點顯示圖像
for(int i=0;i<bmih.biHeight;i++)
{
for(int j=0;j<bmih.biWidth;j++)
{
pDC->SetPixel(j,bmih.biHeight-i,RGB(rgb[i*bmih.biWidth+j].rgbtRed,rgb[i*bmih.biWidth+j].rgbtGreen,rgb[i*bmih.biWidth+j].rgbtBlue));
}
}
bmih.biHeight+=20;
bmih.biWidth+=20;
for(int m=bmih.biHeight-20;m<bmih.biHeight;m++)
{
for(int n=0;n<bmih.biWidth;n++)
{
pDC->SetPixel(n,bmih.biHeight-m,00);
}
}
for(int mm=bmih.biWidth-20;mm<bmih.biWidth;mm++)
{
for(int nn=0;nn<bmih.biWidth;nn++)
{
pDC->SetPixel(mm,bmih.biHeight-nn,00);
}
}
cf.Close();//關閉文件
delete rgb;//釋放內存
}
/////////////////////////////////////////////////////////////////////////////
// CBMP_READView printing
BOOL CBMP_READView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CBMP_READView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CBMP_READView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CBMP_READView diagnostics
#ifdef _DEBUG
void CBMP_READView::AssertValid() const
{
CView::AssertValid();
}
void CBMP_READView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CBMP_READDoc* CBMP_READView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBMP_READDoc)));
return (CBMP_READDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CBMP_READView message handlers
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -