📄 chrcdlg.cpp
字号:
// chrcDlg.cpp : implementation file
//
#include "stdafx.h"
#include "chrc.h"
#include "chrcDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CChrcDlg dialog
CChrcDlg::CChrcDlg(CWnd* pParent /*=NULL*/)
: CDialog(CChrcDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CChrcDlg)
// 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 CChrcDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChrcDlg)
DDX_Control(pDX, IDC_EDIT1, m_SrcPath);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChrcDlg, CDialog)
//{{AFX_MSG_MAP(CChrcDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChrcDlg message handlers
BOOL CChrcDlg::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 CChrcDlg::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 CChrcDlg::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 CChrcDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
FILE *fCode = NULL;
void CChrcDlg::CreatCode(CString cf[50],int number)
{
int x1=0,y1=0,x2=0,y2=0;
char tmp[1024];
memset(tmp,0,1024);
if (cf[0].Find("BUTTON")>=0) {
if(cf[7].GetLength() == 0)
{
fprintf(fCode,".Creat(%s,WS_VISIBLE|WS_CHILD,CRect(%s*2,%s*2,(%s+%s)*2,(%s+%s)*2),this,%s);\n",
cf[1],cf[3],cf[4],cf[3],cf[5],cf[4],cf[6],cf[2]);
}
else
{
fprintf(fCode,".Creat(%s,WS_VISIBLE|WS_CHILD|%s,CRect(%s*2,%s*2,(%s+%s)*2,(%s+%s)*2),this,%s);\n",
cf[1],cf[7] ,cf[3],cf[4],cf[3],cf[5],cf[4],cf[6],cf[2]);
}
}
if (cf[0].Find("LTEXT")>=0) {
if(cf[7].GetLength() == 0)
{
fprintf(fCode,".Create(%s,WS_VISIBLE|WS_CHILD|SS_LEFT,CRect(%s*2,%s*2,(%s+%s)*2,(%s+%s)*2),this,%s);\n",
cf[1],cf[3],cf[4],cf[3],cf[5],cf[4],cf[6],cf[2]);
}
else
{
fprintf(fCode,".Create(%s,WS_VISIBLE|WS_CHILD|SS_LEFT|%s,CRect(%s*2,%s*2,(%s+%s)*2,(%s+%s)*2),this,%s);\n",
cf[1],cf[7] ,cf[3],cf[4],cf[3],cf[5],cf[4],cf[6],cf[2]);
}
}
if (cf[0].Find("RTEXT")>=0) {
if(cf[7].GetLength() == 0)
{
fprintf(fCode,".Create(%s,WS_VISIBLE|WS_CHILD|SS_LEFT,CRect(%s*2,%s*2,(%s+%s)*2,(%s+%s)*2),this,%s);\n",
cf[1],cf[3],cf[4],cf[3],cf[5],cf[4],cf[6],cf[2]);
}
else
{
fprintf(fCode,".Create(%s,WS_VISIBLE|WS_CHILD|SS_LEFT|%s,CRect(%s*2,%s*2,(%s+%s)*2,(%s+%s)*2),this,%s);\n",
cf[1],cf[7] ,cf[3],cf[4],cf[3],cf[5],cf[4],cf[6],cf[2]);
}
}
if (cf[0].Find("CTEXT")>=0)
{
if(cf[7].GetLength() == 0)
{
fprintf(fCode,".Creat(%s,WS_VISIBLE|WS_CHILD|SS_CENTER,CRect(%s*2,%s*2,(%s+%s)*2,(%s+%s)*2),this,%s);\n",
cf[1],cf[3],cf[4],cf[3],cf[5],cf[4],cf[6],cf[2]);
}
else
{
fprintf(fCode,".Creat(%s,WS_VISIBLE|WS_CHILD|%s,CRect(%s*2,%s*2,(%s+%s)*2,(%s+%s)*2),this,%s);\n",
cf[1],cf[7] ,cf[3],cf[4],cf[3],cf[5],cf[4],cf[6],cf[2]);
}
}
/*
if (cf[0].Find("GROUP")>=0) {
}
*/
}
void CChrcDlg::searchOneLine(CString validPart)
{
CString segPart[50],tmpPart;
int segcount;
char ch;
int len,count,cpBegin,i;
validPart.TrimLeft();
len = validPart.GetLength();
segcount = 0;
for(i=0;i<50;i++)
segPart[i].Empty();
//找头
count = 0;
ch = validPart.GetAt(count++);
while((ch!=',')&&(ch!=10)&&(ch!=13)&&(ch!=' '))
ch = validPart.GetAt(count++);
segPart[segcount++] = validPart.Mid(0,count);
//找参数
while (count<len) {
cpBegin = count ;
ch = validPart.GetAt(count++);
while((ch!=',')&&(ch!=10)&&(ch!=13)&&(count<len))
ch = validPart.GetAt(count++);
tmpPart = validPart.Mid(cpBegin,count-cpBegin);
for (i=0;i<count-cpBegin;i++) {
ch = tmpPart.GetAt(i);
if (ch==',') tmpPart.SetAt(i,' ');
}
for (i=0;i<tmpPart.GetLength();i++) {
ch = tmpPart.GetAt(i);
if (ch!=' ')
segPart[segcount] += ch;
}
segcount++;
}
CreatCode(segPart,segcount);
}
int CChrcDlg::GetOneLine(CString cf,int pos,CString *validPart)
{
int i,len,newpos;
CString tmpPart;
len = cf.GetLength();
char ch,memtmp[1024];
validPart->Empty();
i = pos;
while (1) {
for (;i<len;i++) {
ch = cf.GetAt(i);
if ((ch==10)||(ch==13)) break;
}
if (i+6<len) {
if (cf.GetAt(i+6)==' ') {
i+=6;
continue;
}
}
break;
}
i+=2;
tmpPart = cf.Mid(pos,i);
memcpy(memtmp,cf.Mid(pos,i),i-pos);
memtmp[i-pos] = 0;
tmpPart = memtmp;
newpos = i;
for (i=0;i<tmpPart.GetLength();i++) {
ch = tmpPart.GetAt(i);
if ((ch!=10)&&(ch!=13))
*validPart += ch;
}
return newpos;
}
void CChrcDlg::searchOnePart(CString cf)
{
int newpos,len;
int pos = 0;
CString validPart;
len = cf.GetLength();
while (newpos<len) {
//查找一行,即一个控件
newpos = GetOneLine(cf,pos,&validPart);
//解析控件
searchOneLine(validPart);
pos = newpos;
}
}
void CChrcDlg::change(CString cf)
{
int sp = 0;
int cpDialog=0 ,cpBegin=0 ,cpEnd=0;
CString validPart,tmpPart;
int count=0,i=0,exitflag=0;
CString tmp[50];
int usecount = 0;
char ch;
while (1) {
cpDialog = cf.Find(" DIALOG",sp);
if (cpDialog == -1) break;
cpBegin = cf.Find("BEGIN",cpDialog);
cpEnd = cf.Find("END",cpDialog);
validPart = cf.Mid(cpBegin+8,cpEnd - cpBegin - 10);
sp = cpEnd;
if (validPart.IsEmpty()) break;
cpDialog = validPart.Find("LEFTMARGIN");
if (cpDialog != -1) continue;
cpDialog = validPart.Find("RIGHTMARGIN");
if (cpDialog != -1) continue;
cpDialog = validPart.Find("BOTTOMMARGIN");
if (cpDialog != -1) continue;
cpDialog = validPart.Find("TOPMARGIN");
if (cpDialog != -1) continue;
//查到单个DIALOG
searchOnePart(validPart);
fprintf(fCode,"\n");
}
}
int CChrcDlg::ChangeRc(char *fname)
{
FILE *fp;
CString cf;
int len;
char *buf;
fp = fopen(fname,"rb");
if (fp==NULL) return FALSE;
fseek(fp,0l,SEEK_END);
len = ftell(fp);
fseek(fp,0l,SEEK_SET);
buf = new char [len+10];
memset(buf,0,len+10);
if ((int)fread(buf,1,len,fp) != len)
{
AfxMessageBox("ERROR");
return -1;
}
cf = buf;
change(cf);
fclose(fp);
return TRUE;
}
void CChrcDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString strCount;
CString szPath;
m_SrcPath.GetWindowText(szPath);
if(szPath.GetLength() == 0)
return;
CString NewFile;
NewFile = szPath.Left(szPath.GetLength()-4);
NewFile += "1.txt";
fCode = fopen(NewFile,"wt");
//changeFileOneByOne(szPath.GetBuffer(0) ,NULL);
ChangeRc(szPath.GetBuffer(0));
fprintf(fCode,"\n\n************************************\n\n");
fclose(fCode);
}
int CChrcDlg::CloneFolder( CString sSrc, CString sDest )
{
::CreateDirectory( sDest.GetBuffer(0), NULL );
CFileFind ff;
BOOL b = ff.FindFile( sSrc + "*.*" );
while ( b )
{
b = ff.FindNextFile();
if ( ff.IsDots() )
continue;
if ( ff.IsDirectory() )
{
CString sFolder = ff.GetFileName() + "\\";
CString sSubSrc = sSrc+sFolder;
CString sSubDest = sDest+sFolder;
CloneFolder( sSubSrc.GetBuffer(0), sSubDest.GetBuffer(0) );
}
}
return 0;
}
int CChrcDlg::GetAllFileName( CString sFolder, CStringArray *pAry )
{
CFileFind ff;
BOOL b = ff.FindFile( sFolder + "*.*" );
while ( b )
{
b = ff.FindNextFile();
if ( ff.IsDots() )
continue;
if ( ff.IsDirectory() )
GetAllFileName( ff.GetFilePath()+"\\", pAry );
else
pAry->Add( ff.GetFilePath() );
}
return pAry->GetSize();
}
int CChrcDlg::changeFileOneByOne(char *srcDir,char *desDir)
{
int filenumber;
CStringArray pAry;
CString OldFileName,newFileName;
int i;
// CloneFolder( srcDir, desDir);
filenumber = GetAllFileName(srcDir, &pAry );
for (i=0;i<filenumber;i++)
{
OldFileName = pAry.GetAt(i);
// newFileName = OldFileName;
// newFileName.Replace(srcDir,desDir);
if(OldFileName.Right(3)==".rc")
{
ChangeRc(OldFileName.GetBuffer(0));
}
}
return 0;
}
/********************************creat at file*****************************************/
FILE *frc,*fcpp;
CString Fcpp;
int getRCfile(char *filename)
{
char tmp[1024];
frc = fopen(filename,"rt");
if (fp==NULL) return -1;
fcpp = NULL;
读frc一行
while (1) {
if (frc文件结束) break;
if (首字符 == #) {
if (fcpp!=NULL) fclose(fcpp);
打开fcpp,内容置于cpptmp中,
读frc一行
回到循环开头
}
在fcpp中查找IDC_所对应的变量
将变量+.creat......写在新文件中。
读frc一行
回到循环开头
}
}
int CreatFile()
{
getRCfile("rcFile");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -