📄 4_2prodlg.cpp
字号:
// 4_2PRODlg.cpp : implementation file
//
#include "stdafx.h"
#include "4_2PRO.h"
#include "4_2PRODlg.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()
/////////////////////////////////////////////////////////////////////////////
// CMy4_2PRODlg dialog
CMy4_2PRODlg::CMy4_2PRODlg(CWnd* pParent /*=NULL*/)
: CDialog(CMy4_2PRODlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMy4_2PRODlg)
m_CSOutput = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMy4_2PRODlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMy4_2PRODlg)
DDX_Control(pDX, IDC_EDIT1, m_Edit_Out);
DDX_Text(pDX, IDC_EDIT1, m_CSOutput);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMy4_2PRODlg, CDialog)
//{{AFX_MSG_MAP(CMy4_2PRODlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDCANCEL2, OnCancel2)
ON_BN_CLICKED(IDOK2, OnOk2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy4_2PRODlg message handlers
BOOL CMy4_2PRODlg::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
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMy4_2PRODlg::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 CMy4_2PRODlg::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 CMy4_2PRODlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//文本文件转换十六进制按钮
void CMy4_2PRODlg::OnOK()
{
// TODO: Add extra validation here
m_nstr="";
UpdateData(FALSE); //使变量清空实现刷屏功能;
int len; //存文件中字符的个数的变量
unsigned char *pBuf; //存文件中的字符的缓冲区
char *a; //字符转换的缓冲区
CFileDialog dlg(TRUE); //初始化打开文件的对话框
if(dlg.DoModal()==IDOK) //点击按钮后弹出打开文件的对话框
{
//打开文件
CString cs;
cs=dlg.GetPathName();
CFile file(cs,CFile::modeRead);
len=file.GetLength();
pBuf=new unsigned char[len];
a=new char[len];
file.Read(pBuf,len);
pBuf[len]=0;
file.Close();
//将文件转换成十六进制
for(int i = 0;i<len;i++)
{
sprintf(a,"%02x ",pBuf[i]);
m_nstr+=a;
}
}
m_CSOutput=m_nstr;
UpdateData(FALSE);
//CDialog::OnOK();
}
//关闭按钮
void CMy4_2PRODlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
//保存按钮
void CMy4_2PRODlg::OnCancel2()
{
// TODO: Add your control notification handler code here
CString
FilePathName;
CFileDialog dlg(FALSE,"txt");///TRUE为打开对话框,FALSE为保存对话框
if(dlg.DoModal()==IDOK)
FilePathName=dlg.GetPathName();
int strlength=m_CSOutput.GetLength()-1; // strlength表示字符串的字节数
CFile file;
file.Open(FilePathName,CFile::modeCreate|CFile::modeWrite,NULL);
//file.Write(&strlength,sizeof(strlength));
file.Write(m_CSOutput,strlength);
file.Close();
m_CSOutput="";
}
//十六进制转换文本文件按钮
void CMy4_2PRODlg::OnOk2()
{
// TODO: Add your control notification handler code here
m_CSOutput="";
UpdateData(FALSE);
int len;
unsigned char *pBuf;
unsigned char *sp;
unsigned char *Hstr;
register Len;
int m,n=0;
char *a;
CFileDialog dlg(TRUE);
if(dlg.DoModal()==IDOK)
{
//打开文件
CString cs;
cs=dlg.GetPathName();
CFile file(cs,CFile::modeRead);
len=file.GetLength();
pBuf=new unsigned char[len];
sp=new unsigned char[len];
a=new char[len];
file.Read(pBuf,len);
pBuf[len]=0;
file.Close();
//去掉字符串中的空格
for (m = 0; *(pBuf + m) != '\0'; m++)
{
if (*(pBuf + m) == ' ' )
continue;
sp[n++]=*(pBuf + m);
}
sp[n] = 0;
//将十六进制转换成字符
Len=n/2;
Hstr=new unsigned char[Len];
for(register i=0;i<Len;i++)
{
if (isdigit(sp[2*i]))
Hstr[i]=(sp[2*i]-'0')*16;
else
Hstr[i]=(toupper(sp[2*i])-'A'+10)*16;
if (isdigit(sp[2*i+1]))
Hstr[i]+=sp[2*i+1]-'0';
else
Hstr[i]+=toupper(sp[2*i+1])-'A'+10;
}
Hstr[Len]=0;
}
for(int i = 0 ; i <= Len ; i++)
{
m_CSOutput+=Hstr[i];
}
UpdateData(FALSE);
//CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -