www.pudn.com > JPEG_DEMO.rar > JPEG_DEMODlg.cpp
// JPEG_DEMODlg.cpp : implementation file
//
#include "stdafx.h"
#include "JPEG_DEMO.h"
#include "JPEG_DEMODlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CJPEG_DEMODlg dialog
CJPEG_DEMODlg::CJPEG_DEMODlg(CWnd* pParent /*=NULL*/)
: CDialog(CJPEG_DEMODlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CJPEG_DEMODlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CJPEG_DEMODlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CJPEG_DEMODlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CJPEG_DEMODlg, CDialog)
//{{AFX_MSG_MAP(CJPEG_DEMODlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_SHOW_JPEG, OnShowJpeg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CJPEG_DEMODlg message handlers
BOOL CJPEG_DEMODlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CJPEG_DEMODlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CJPEG_DEMODlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CJPEG_DEMODlg::OnShowJpeg()
{
OPENFILENAME of;
char filename[100]="";
char szFilter[100]="所有文件(*.*)\0*.*\0图象源文件(*.jpg)\0*.jpg\0\0";
char szCustomFilter[]="*.jpg\0";
of.Flags=OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST;
of.hInstance=NULL;
of.hwndOwner=this->m_hWnd;
of.lCustData=0;
of.lpfnHook=NULL;
of.lStructSize=sizeof(of);
of.lpstrCustomFilter=NULL;
of.nMaxCustFilter=0;
of.lpstrDefExt=NULL;
of.lpstrFile=NULL;
of.nMaxFile=0;
of.lpstrFileTitle=filename;
of.nMaxFileTitle=sizeof(filename);
of.lpstrFilter=szFilter;
of.nFilterIndex=1;
of.lpstrInitialDir="d:\\qcif";
of.lpstrTitle=NULL;
of.lpTemplateName=NULL;
of.nFileExtension=0;
of.nFileOffset=0;
unsigned char *fJpegBuf;
int i=0;
char bfilename[100]="c:\\";
FILE *fJpeg=NULL;
static HFILE file;
if(GetOpenFileName(&of))
{
static OFSTRUCT ofs;
ofs.cBytes=sizeof(ofs);
file=OpenFile(filename,&ofs,OF_READ);
int nBytetoRead=GetFileSize((HANDLE)file,NULL);
unsigned long nByteRead;
fJpegBuf=(unsigned char *) malloc(nBytetoRead);
ReadFile((HANDLE)file,fJpegBuf,nBytetoRead,&nByteRead,NULL);
i=0;
while(filename[i]!='.') { bfilename[i+3]=filename[i]; i++; }
bfilename[i+3]='\0';
strcat(bfilename,".bmp");
if(!this->m_clrJpegDec.ShowJpegToScreen(fJpegBuf,bfilename))
MessageBox("解码出错!");
else MessageBox("解码成功,BMP文件保存到C盘根目录");
}
else this->MessageBox("文件出错!");
}