📄 applicationdlg.cpp
字号:
// ApplicationDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Application.h"
#include "ApplicationDlg.h"
#include "Engine.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static TCHAR 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()
/////////////////////////////////////////////////////////////////////////////
// CApplicationDlg dialog
CApplicationDlg::CApplicationDlg(CWnd* pParent /*=NULL*/)
: CDialog(CApplicationDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CApplicationDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CApplicationDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CApplicationDlg)
DDX_Control(pDX, IDC_EWEDIT, m_ExtTxt);
DDX_Control(pDX, IDC_SWEDIT, m_OriTxt);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CApplicationDlg, CDialog)
//{{AFX_MSG_MAP(CApplicationDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButtonRBmpFile)
ON_BN_CLICKED(IDC_BUTTON3, OnWRead)
ON_BN_CLICKED(IDC_BUTTON2, OnButtonSBmpFile)
ON_BN_CLICKED(IDC_BUTTON4, OnWSave)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_BUTTON7, OnWEmbed)
ON_BN_CLICKED(IDC_BUTTON5, OnButtonWBmpFile)
ON_BN_CLICKED(IDC_BUTTON6, OnWExtract)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CApplicationDlg message handlers
BOOL CApplicationDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
m_pMainDib=NULL;
m_pWMainDib=NULL;
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CApplicationDlg::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 CApplicationDlg::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;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
HCURSOR CApplicationDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//从文件读图象并显示到控件中
void CApplicationDlg::OnButtonRBmpFile()
{
CString strFile;
//打开位图文件
CFileDialog FileDlg(TRUE, "", NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT,
"BMP图像(*.bmp)|*.bmp|所有文件(*.*)|*.*||",
AfxGetMainWnd());
if (FileDlg.DoModal () != IDOK)
return;
POSITION pos = FileDlg.GetStartPosition();
strFile = FileDlg.GetNextPathName(pos);
m_sFileName=strFile;
if(m_pMainDib!=NULL)
delete m_pMainDib;
//创建一个位图类对象并将位图数据读入到该对象中
m_pMainDib = new CDib();
if(m_pMainDib->Open(strFile)!=TRUE)
{
AfxMessageBox("不能打开位图文件");
delete m_pMainDib;
return;
}
//获得图片框的设备上下文及大小
CWnd *pWndBmp= GetDlgItem(IDC_RBMP_SHOW);
CDC *pDCShow = pWndBmp->GetDC();
RECT rt;
pWndBmp->GetWindowRect(&rt);
// m_nWndWidth = m_pMainDib->GetWidth();
// m_nWndHeight= m_pMainDib->GetHeight();
int l_nWndWidth=rt.right-rt.left;
int l_nWndHeight=rt.bottom-rt.top;
//显示读入的位图
m_pMainDib->Draw(pDCShow,l_nWndWidth, l_nWndHeight);
}
/*void CApplicationDlg::LoadOriPixel(CDib *pDib)
{BYTE *colorTable;
colorTable = (BYTE *)pDib->m_pDibBits;
int byteBitCount = pDib->GetBiBitCount()/8;
m_tOriPixelArray = new RGBQUAD*[m_nWndHeight];
m_tResPixelArray = new RGBQUAD*[m_nWndHeight];
for(int l=0 ; l<m_nWndHeight; l++)
{
m_tOriPixelArray[l] = new RGBQUAD[m_nWndWidth];
m_tResPixelArray[l] = new RGBQUAD[m_nWndWidth];
}
int count = 0;
for(int i=m_nWndHeight-1; i>=0; i--)
{
for(int j=0; j<m_nWndWidth; j++)
{
m_tOriPixelArray[i][j].rgbBlue =colorTable[count++];
m_tOriPixelArray[i][j].rgbGreen=colorTable[count++];
m_tOriPixelArray[i][j].rgbRed =colorTable[count++];
m_tOriPixelArray[i][j].rgbReserved = 0;
m_tResPixelArray[i][j]=m_tOriPixelArray[i][j];
count += byteBitCount-3;
}
count += (4-(m_nWndWidth*byteBitCount)%4)%4;
}
}*/
//从文件读取文本信息到控件中
void CApplicationDlg::OnWRead()
{
CFileDialog dlg(TRUE, "SQL", "*.txt",OFN_HIDEREADONLY
|OFN_OVERWRITEPROMPT,"Text Files(*.txt)|All Files(*.*)|*.*||");
if ( dlg.DoModal()!=IDOK ) return;
//获取文件的绝对路径
CString sFileName=dlg.GetPathName();
//打开文件
CStdioFile in;
bool flag;
in.Open(sFileName, CFile::modeRead);
CString sStr="",s;
//读取文件
do{
flag=in.ReadString(s);
sStr=sStr+s+"\r\n";
}while(flag);
//将文件内容显示到文本控件中
m_OriTxt.SetWindowText(sStr);
// pWndTxt->SetWindowText(sStr);
in.Close();
}
void CApplicationDlg::OnButtonSBmpFile()
{
CFileDialog dlg(FALSE, "BMP", "*.bmp",OFN_HIDEREADONLY
|OFN_OVERWRITEPROMPT,"Bmp Files(*.bmp)|All Files(*.*)|*.*||");
if ( dlg.DoModal()!=IDOK ) return;
//获取文件的绝对路径
CString strFile =dlg.GetPathName();
if(m_pMainDib==NULL)
{
AfxMessageBox("没有位图文件");
return;
}
// TODO: Add your control notification handler code here
if( m_pMainDib->Save(strFile)!=TRUE)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -