📄 jpeg_prodlg.cpp
字号:
// JPEG_PRODlg.cpp : implementation file
//
#include "stdafx.h"
#include "JPEG_PRO.h"
#include "JPEG_PRODlg.h"
#include "Splash.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CJPEG_PRODlg dialog
CJPEG_PRODlg::CJPEG_PRODlg(CWnd* pParent /*=NULL*/)
: CDialog(CJPEG_PRODlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CJPEG_PRODlg)
// 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_PRODlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CJPEG_PRODlg)
DDX_Control(pDX, IDC_BUTTON_TRANS, m_Trans);
DDX_Control(pDX, IDC_BUTTON_READ, m_ReadBmp);
DDX_Control(pDX, IDC_BUTTON_OPENJPEG, m_OpenJpeg);
DDX_Control(pDX, IDC_BUTTON_EXIT, m_Exit);
DDX_Control(pDX, IDC_BUTTON_ABOUT, m_About);
DDX_Control(pDX, IDC_COMBO_Q, m_Q);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CJPEG_PRODlg, CDialog)
//{{AFX_MSG_MAP(CJPEG_PRODlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_READ, OnButtonRead)
ON_BN_CLICKED(IDC_BUTTON_TRANS, OnButtonTrans)
ON_BN_CLICKED(IDC_BUTTON_OPENJPEG, OnButtonOpenjpeg)
ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit)
ON_BN_CLICKED(IDC_BUTTON_ABOUT, OnButtonAbout)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CJPEG_PRODlg message handlers
BOOL CJPEG_PRODlg::OnInitDialog()
{
CDialog::OnInitDialog();
Q=100;
BmpDib=NULL;
JpegDib=NULL;
BmpDibBuffer=NULL;
JpegDibBuffer=NULL;
JpegFileName="";
BmpFileName="";
Bmp2JpegFileName="";
m_Q.SelectString(-1,"100");
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
//////////////////////////////////////////////////////////////////////////
//设置按钮风格
m_Exit.SetIcon(IDI_ICONCLOSE, (int)BTNST_AUTO_GRAY);
m_Exit.SetPlaySound(true,"IDR_WAVE1");
m_Exit.DrawBorder(FALSE);
m_Exit.SetColor(CButtonST::BTNST_COLOR_BK_OUT, RGB(80,120,200));
m_Exit.SetColor(CButtonST::BTNST_COLOR_BK_IN, RGB(80,120,200));
m_Exit.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(80,120,200));
m_Exit.SetTooltipText(_T("退出程序"));
m_OpenJpeg.SetIcon(IDI_JPEG, (int)BTNST_AUTO_GRAY);
m_OpenJpeg.SetPlaySound(true,"IDR_WAVE1");
m_OpenJpeg.DrawBorder(FALSE);
m_OpenJpeg.SetColor(CButtonST::BTNST_COLOR_BK_OUT, RGB(80,120,200));
m_OpenJpeg.SetColor(CButtonST::BTNST_COLOR_BK_IN, RGB(80,120,200));
m_OpenJpeg.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(80,120,200));
m_OpenJpeg.SetTooltipText(_T("浏览JPEG格式的图片"));
m_ReadBmp.SetIcon(IDI_BMP, (int)BTNST_AUTO_GRAY);
m_ReadBmp.SetPlaySound(true,"IDR_WAVE1");
m_ReadBmp.DrawBorder(FALSE);
m_ReadBmp.SetColor(CButtonST::BTNST_COLOR_BK_OUT, RGB(80,120,200));
m_ReadBmp.SetColor(CButtonST::BTNST_COLOR_BK_IN, RGB(80,120,200));
m_ReadBmp.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(80,120,200));
m_ReadBmp.SetTooltipText(_T("读取Bmp格式的图象文件"));
m_About.SetIcon(IDI_ABOUT, (int)BTNST_AUTO_GRAY);
m_About.SetPlaySound(true,"IDR_WAVE1");
m_About.DrawBorder(FALSE);
m_About.SetColor(CButtonST::BTNST_COLOR_BK_OUT, RGB(80,120,200));
m_About.SetColor(CButtonST::BTNST_COLOR_BK_IN, RGB(80,120,200));
m_About.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(80,120,200));
m_About.SetTooltipText(_T("关于程序以及作者"));
m_Trans.SetIcon(IDI_TRANS, (int)BTNST_AUTO_GRAY);
m_Trans.SetPlaySound(true,"IDR_WAVE1");
m_Trans.DrawBorder(FALSE);
m_Trans.SetColor(CButtonST::BTNST_COLOR_BK_OUT, RGB(80,120,200));
m_Trans.SetColor(CButtonST::BTNST_COLOR_BK_IN, RGB(80,120,200));
m_Trans.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(80,120,200));
m_Trans.SetTooltipText(_T("将Bmp格式的图片压缩为JPEG格式"));
CSplashWnd::ShowSplashScreen( this);
Sleep(2000);
return TRUE; // return TRUE unless you set the focus to a control
}
void CJPEG_PRODlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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_PRODlg::OnPaint()
{
CDC* pDC=GetDC();
if (BmpDib) { //如果图像为非空的那么显示
pDC->SetStretchBltMode(HALFTONE);
BmpDib->Paste(pDC,26,50,337,337, SRCCOPY);
}
if (JpegDib) { //如果图像为非空的那么显示
pDC->SetStretchBltMode(HALFTONE);
JpegDib->Paste(pDC,458,50,337,337, SRCCOPY);
}
else
{NULL;}
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_PRODlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CJPEG_PRODlg::OnButtonRead()
{
// TODO: Add your control notification handler code here
char szExt[] = "图像文件(*.bmp;)|*.bmp;||";
CFileDialog dlg(TRUE, NULL, NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
szExt);
if(dlg.DoModal() == IDOK) //读入一个新的文件
{
BmpFileName=dlg.GetPathName();
if (BmpDib) {
BmpDib->DestroyDIB();
}
BmpDib=new CDIBDC;
BmpDib->Load(BmpFileName);
}
else
{
NULL;
}
Invalidate(FALSE);
}
//////////////////////////////////////////////////////////////////////////
//JPEG转换的函数
void CJPEG_PRODlg::OnButtonTrans()
{
// TODO: Add your control notification handler code here
if (BmpFileName=="") {
MessageBox("还没有读入位图文件!");
return;
}
char szExt[] = "图像文件(*.jpg;)|*.jpg;|所有文件(*.*)|*.*||";
CFileDialog dlg(FALSE, NULL, NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
szExt);
UpdateData(FALSE);
JPEG_CODE Jcode;
Q=(5-m_Q.GetCurSel())*20;
if(dlg.DoModal() == IDOK) //转换文件
{
Bmp2JpegFileName=dlg.GetPathName();
if (Bmp2JpegFileName.Find(".jpg")<0) {
Bmp2JpegFileName=Bmp2JpegFileName+".jpg";
}
string s1(BmpFileName),s2(Bmp2JpegFileName);
Jcode.Invoke(s1, s2,Q); //进行Jpeg的压缩编码
if (JpegDib) {
JpegDib->DestroyDIB();
}
JpegDib=new CDIBDC;
JpegDib->Load(Bmp2JpegFileName);
}
else
NULL;
Invalidate(FALSE);
}
void CJPEG_PRODlg::OnButtonOpenjpeg()
{
// TODO: Add your control notification handler code here
// TODO: Add your control notification handler code here
char szExt[] = "图像文件(*.jpg;)|*.jpg;|图像文件(*.bmp;*.jpg;*.gif;*.png;*.ico)|*.bmp;*.jpg;*.gif;*.png;*.ico|所有文件(*.*)|*.*||";
CFileDialog dlg(TRUE, NULL, NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
szExt);
if(dlg.DoModal() == IDOK) //读入一个新的文件
{
JpegFileName=dlg.GetPathName();
if (JpegDib) {
JpegDib->DestroyDIB();
}
JpegDib=new CDIBDC;
JpegDib->Load(JpegFileName);
}
else
{
NULL;
}
Invalidate(FALSE);
}
void CJPEG_PRODlg::OnButtonExit()
{
// TODO: Add your control notification handler code here
OnOK();
}
void CJPEG_PRODlg::OnButtonAbout()
{
// TODO: Add your control notification handler code here
CAboutDlg dlg;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -