📄 fanydlg.cpp
字号:
// fanyDlg.cpp : implementation file
//
#include "stdafx.h"
#include "fany.h"
#include "fanyDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFanyDlg dialog
CString path;
CString filename_in;
CFanyDlg::CFanyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFanyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFanyDlg)
// 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 CFanyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFanyDlg)
DDX_Control(pDX, IDC_LIST, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFanyDlg, CDialog)
//{{AFX_MSG_MAP(CFanyDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_ADDFILE, OnButtonAddfile)
ON_BN_CLICKED(IDC_BUTTON_CUT, OnButtonCut)
ON_BN_CLICKED(IDC_BUTTON_FANY, OnButtonFany)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFanyDlg message handlers
BOOL CFanyDlg::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 CFanyDlg::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 CFanyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFanyDlg::OnButtonAddfile()
{
// TODO: Add your control notification handler code here
static char BASED_CODE szFilter[] = "C Files (*.c)|*.c|H Files (*.h)|*.h";
CFileDialog filedlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,NULL);
filedlg.DoModal();
//path=filedlg.GetPathName();
filename_in=filedlg.GetPathName();
//filename_in=filedlg.GetFileName();
m_list.InsertString(0,filename_in);
}
void CFanyDlg::OnButtonCut()
{
// TODO: Add your control notification handler code here
}
void CFanyDlg::OnButtonFany()
{
// TODO: Add your control notification handler code here
DWORD filelen;
char* buf;
//char* tmp_point;
BOOL val;
int position;
CString filename_out;
CFile file_in,file_out;
unsigned char low1;
unsigned char high1;
unsigned char low2;
unsigned char high2;
unsigned char tmpchar[4];
int i;
filename_out=filename_in;
position=filename_in.Find(".c",0);
if(position>0) //.c的源文件
{
filename_out.Insert(position,"_o");
}
position=filename_in.Find(".C",0);
if(position>0) //.c的源文件
{
filename_out.Insert(position,"_o");
}
position=filename_in.Find(".h",0);
if(position>0) //.c的源文件
{
filename_out.Insert(position,"_o");
}
position=filename_in.Find(".H",0);
if(position>0) //.c的源文件
{
filename_out.Insert(position,"_o");
}
val=file_in.Open(filename_in,CFile::modeRead,NULL);
if(!val)
{
AfxMessageBox("read source file fail\n");
return;
}
else
{
val=file_out.Open(filename_out,CFile::modeCreate|CFile::modeWrite);
if(!val)
{
AfxMessageBox("create object file fail\n");
file_in.Close();
return;
}
else
{
filelen=file_in.GetLength();
buf=(char*)malloc(filelen);
//tmp_point=buf; //保存缓冲区首地址
file_in.Read(buf,filelen);
i=0;
while(i<filelen)
{
if((buf[i] & 0x80) && (buf[i+1] & 0x80)) //汉字
{
low1=0x00;
high1=0x00;
low2=0x00;
high2=0x00;
low1=buf[i]& 0x0F; //取低四位
low1 = low1 + 0x41;
high1=(buf[i]>>4) & 0x0F; //取高四位
high1 = high1 + 0x41;
low2=buf[i+1]& 0x0F; //取低四位
low2 = low2 + 0x41;
high2=(buf[i+1]>>4)&0x0F; //取高四位
high2 = high2 + 0x41;
//buf+=2;
file_out.Write(&high1,1);
file_out.Write(&low1,1);
file_out.Write(&high2,1);
file_out.Write(&low2,1);
i+=2;
}
else
{
if(buf[i]==0x22) //遇到了"符号,表明后面是字符串,不进行任何处理
{
file_out.Write(&buf[i],1);
//buf++;
i++;
while(buf[i]!=0x22)
{
file_out.Write(&buf[i],1);
//buf++;
i++;
}
file_out.Write(&buf[i],1);
//buf++;
i++;
}
else if(buf[i]==0xFF) //空字符
{
//buf++;
i++;
}
else
{
file_out.Write(&buf[i],1);
//buf++;
i++;
}
}
}
}
}
//buf=tmp_point;
free(buf);
file_in.Close();
file_out.Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -