www.pudn.com > dip_1_1_bmp2jpeg.rar > dip_1_1View.cpp
// dip_1_1View.cpp : implementation of the CDip_1_1View class
//
#include "stdafx.h"
#include "dip_1_1.h"
#include "Mainfrm.h"
#include "dip_1_1Doc.h"
#include "dip_1_1View.h"
#include "Image.h"
//#include "HuffmanCoding.h"
//#include "jpegfile.h"
#include "jpeg.h"
#include "jpegctr.h"
#include "Bmp2Jpeg.h"
#include "jpegdisplay.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDip_1_1View
IMPLEMENT_DYNCREATE(CDip_1_1View, CScrollView)
BEGIN_MESSAGE_MAP(CDip_1_1View, CScrollView)
//{{AFX_MSG_MAP(CDip_1_1View)
ON_COMMAND(ID_BMPTOJPEG, OnBmptojpeg)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDip_1_1View construction/destruction
CDip_1_1View::CDip_1_1View()
{
// TODO: add construction code here
}
CDip_1_1View::~CDip_1_1View()
{
}
BOOL CDip_1_1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDip_1_1View drawing
void CDip_1_1View::OnDraw(CDC* pDC)
{
CDip_1_1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->m_iDib->Display(pDC, CPoint(0,0));
// TODO: add draw code for native data here
}
void CDip_1_1View::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CDip_1_1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = pDoc->m_iDib->Width();
sizeTotal.cy = pDoc->m_iDib->Height();
SetScrollSizes(MM_TEXT, sizeTotal);
CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
ASSERT_KINDOF(CMainFrame, pAppFrame);
CRect rc;
pAppFrame->GetClientRect(&rc);
if (rc.Width() >= sizeTotal.cx && rc.Height() >= sizeTotal.cy &&
(sizeTotal.cx>0 || sizeTotal.cy>0))
ResizeParentToFit(FALSE);
}
/////////////////////////////////////////////////////////////////////////////
// CDip_1_1View printing
BOOL CDip_1_1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDip_1_1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDip_1_1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDip_1_1View diagnostics
#ifdef _DEBUG
void CDip_1_1View::AssertValid() const
{
CScrollView::AssertValid();
}
void CDip_1_1View::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CDip_1_1Doc* CDip_1_1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDip_1_1Doc)));
return (CDip_1_1Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDip_1_1View message handlers
LRESULT CDip_1_1View::OnRealizePal(WPARAM wParam, LPARAM lParam)
{
ASSERT(wParam != NULL);
CDip_1_1Doc* pDoc = GetDocument();
CPalette* pPal = pDoc->m_iDib->Palette();
if (pPal != NULL)
{
CWnd* pAppFrame = AfxGetApp()->m_pMainWnd;
CClientDC appDC(pAppFrame);
// All views but one should be a background palette.
// wParam contains a handle to the active view, so the SelectPalette
// bForceBackground flag is FALSE only if wParam == m_hWnd (this view)
CPalette* oldPalette = appDC.SelectPalette(pPal, ((HWND)wParam) != m_hWnd);
if (oldPalette != NULL)
{
UINT nColorsChanged = appDC.RealizePalette();
if (nColorsChanged > 0)
GetDocument()->UpdateAllViews(NULL);
appDC.SelectPalette(oldPalette, TRUE);
}
else
{
TRACE0("\tSelectPalette failed!\n");
}
}
return 0L;
}
void CDip_1_1View::OnBmptojpeg()
{
//CString f;
LPCSTR filename,pathname;
CBmp2Jpeg B2j;
// LPPICTURE gpPicture;
if(B2j.DoModal() == IDOK)
{
filename = B2j.m_filename;
pathname = B2j.m_getpathname;
}
// SetWindowText(filename);
CJpeg *Jpeg_1= new CJpeg;
CDip_1_1Doc* pDoc = GetDocument();
// f = pDoc->m_file_name;
// *f;
// CJpegCtr *Jpeg_2 = new CJpegCtr;
//BYTE* buf=(BYTE *)pDoc->m_seDib->m_pDib;
// CSize bmpsize = pDoc->m_seDib->GetSize();
WORD width = pDoc->m_iDib->Width();
WORD height = pDoc->m_iDib->Height();
Jpeg_1->SaveJPG((LPSTR)filename,width,height,(BYTE *)pDoc->m_seDib->m_Dataa,7);
delete Jpeg_1;
CJpegDisplay Jd;
CDC* pDC;
pDC=GetDC();
Jd.m_pathname = pathname;
Jd.m_height = height;
Jd.m_width = width;
if(!Jd.DoModal())
{
AfxMessageBox("Jpeg display process failure!");
}
}