📄 scanstringtooldlg.cpp
字号:
// scanstringtoolDlg.cpp : implementation file
//
#include "stdafx.h"
#include "scanstringtool.h"
#include "scanstringtoolDlg.h"
#include "SBDestination.h"
#include "ReadScanBaseThd.h"
#include "FileLine.h"
#include "Help.h"
#include "MacroObj.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()
/////////////////////////////////////////////////////////////////////////////
// CScanstringtoolDlg dialog
CScanstringtoolDlg::CScanstringtoolDlg(CWnd* pParent /*=NULL*/)
: CDialog(CScanstringtoolDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CScanstringtoolDlg)
m_dir = _T("");
m_szOutFile = _T("");
m_lFileNum = 0;
m_bSubFolder = FALSE;
m_szMacroName = _T("");
m_lReplaceNum = 0;
m_bInclude = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
CReadScanBaseThd* htask = new CReadScanBaseThd(this);
htask->CreateThread();
m_pScanThd = (void*)htask;
m_bComplete = true;
m_bInclude = true;
m_bOutFileComplete = false;
m_pOutFile = NULL;
}
void CScanstringtoolDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CScanstringtoolDlg)
DDX_Control(pDX, IDC_CHK_INCLUDE, m_ctlChoose);
DDX_Control(pDX, IDC_CHECK_SubFolder, m_chkSubFolder);
DDX_Control(pDX, IDC_OUT_FILE, m_ctlOutFile);
DDX_Control(pDX, IDC_EDIT_DIR, m_ctlDir);
DDX_Control(pDX, IDC_STATIC_DSP_ITEM, m_ctlDsp);
DDX_Control(pDX, IDC_REPLACE_NUM, m_ctlReplaceNum);
DDX_Control(pDX, IDC_MARCO_NAME, m_ctlMacroName);
DDX_Control(pDX, IDC_BTN_FILE, m_btnFile);
DDX_Control(pDX, IDC_BTN_DIR, m_btnDir);
DDX_Control(pDX, IDOK, m_ctlOk);
DDX_Control(pDX, IDC_COMBO_PRG_TYPE, m_ctlPrgType);
DDX_Control(pDX, IDC_FILENUM, m_ctlFileNum);
DDX_Text(pDX, IDC_EDIT_DIR, m_dir);
DDX_Text(pDX, IDC_OUT_FILE, m_szOutFile);
DDX_Text(pDX, IDC_FILENUM, m_lFileNum);
DDX_Check(pDX, IDC_CHECK_SubFolder, m_bSubFolder);
DDX_Text(pDX, IDC_MARCO_NAME, m_szMacroName);
DDX_Text(pDX, IDC_REPLACE_NUM, m_lReplaceNum);
DDX_Check(pDX, IDC_CHK_INCLUDE, m_bInclude);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CScanstringtoolDlg, CDialog)
//{{AFX_MSG_MAP(CScanstringtoolDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_DIR, OnBtnDir)
ON_BN_CLICKED(IDC_BTN_FILE, OnBtnFile)
ON_BN_CLICKED(IDC_BTN_STOP, OnBtnStop)
ON_BN_CLICKED(IDC_BTN_HELP, OnBtnHelp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScanstringtoolDlg message handlers
BOOL CScanstringtoolDlg::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
m_ctlPrgType.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
}
void CScanstringtoolDlg::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 CScanstringtoolDlg::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 CScanstringtoolDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CScanstringtoolDlg::OnBtnDir()
{
// TODO: Add your control notification handler code here
CSBDestination sb(m_hWnd,IDS_BFF_NEWDIR);
sb.SetFlags(BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT);
sb.SetInitialSelection(m_dir);
if (sb.SelectFolder())
{
m_dir = sb.GetSelectedFolder();
m_ctlDir.SetWindowText(m_dir);
}
}
void CScanstringtoolDlg::OnBtnFile()
{
// TODO: Add your control notification handler code here
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
CString sFilter = "提取字符串输出文件 (*.*)|*.*||";
CFileDialog Save(false, "txt", "resource", dwFlags, sFilter);
if (Save.DoModal() != IDOK)
return;
m_szOutFile = Save.GetPathName();
m_ctlOutFile.SetWindowText(m_szOutFile);
}
void CScanstringtoolDlg::OnOK()
{
// TODO: Add extra validation here
if(!UpdateData())
return;
m_dir.TrimLeft();
if(m_dir.IsEmpty())
{
//
AfxMessageBox("程序目录不能为空!" );
m_btnDir.SetFocus();
return;
}
m_szOutFile.TrimLeft();
if(m_szOutFile.IsEmpty())
{
//
AfxMessageBox("输出提取文件不能为空!" );
m_btnFile.SetFocus();
return;
}
m_szMacroName.TrimLeft();
if(m_szMacroName.IsEmpty())
{
//
AfxMessageBox("宏函数名不能为空!");
m_ctlMacroName.SetFocus();
return;
}
if(m_pOutFile == NULL)
{
CFileStatus fStatus;
if(CFile::GetStatus(m_szOutFile, fStatus) )
{
try{
CFile::Remove(m_szOutFile);
}
catch(CFileException e)
{
//
AfxMessageBox("输出文件覆盖失败!" );
return;
}
}
m_pOutFile = fopen(m_szOutFile,"a");
}
if(m_pOutFile == NULL)
{
//
AfxMessageBox("输出文件不能建立!" );
return;
}
StartTaskFlag();
CReadScanBaseThd* htask = (CReadScanBaseThd*)m_pScanThd;
htask->m_bStopScan = false; //把结束扫描标志置为false
SetEvent(htask->m_hEventStart);
// CDialog::OnOK();
}
void CScanstringtoolDlg::OnBtnStop()
{
// TODO: Add your control notification handler code here
CReadScanBaseThd* htask = (CReadScanBaseThd*)m_pScanThd;
if(htask !=NULL)
htask->m_bStopScan = true;
}
void CScanstringtoolDlg::OnCancel()
{
// TODO: Add extra cleanup here
if(!m_bComplete)
{
//
AfxMessageBox("任务没有完成,请不要退出!");
return;
}
CloseOutFile();
CReadScanBaseThd* htask = (CReadScanBaseThd*)m_pScanThd;
if(htask !=NULL)
htask->KillThread();
CDialog::OnCancel();
}
void CScanstringtoolDlg::StartTaskFlag()
{
m_lMacFileNum = 0;
m_lReplaceNum = 0;
m_ctlReplaceNum.SetWindowText("0");
m_bComplete = false;
m_ctlOk.EnableWindow(false);
m_ctlPrgType.EnableWindow(false);
m_btnDir.EnableWindow(false);
m_chkSubFolder.EnableWindow(false);
m_btnFile.EnableWindow(false);
m_ctlMacroName.EnableWindow(false);
m_ctlChoose.EnableWindow(false);
theApp.ClearStrMap();
theApp.ClearMarcoMap();
}
void CScanstringtoolDlg::CloseOutFile()
{
int curType = m_ctlPrgType.GetCurSel();
if(curType == 0 && !m_bComplete && (m_lMacFileNum - 1)%10 != 9)
{
fprintf(m_pOutFile,"END\r\n");
}
if(m_pOutFile != NULL)
{
fclose(m_pOutFile);
m_pOutFile = NULL;
}
}
void CScanstringtoolDlg::WriteCMac(char *szMacro, char *szValue)
{
if(m_lMacFileNum%10 == 0)
{
fprintf(m_pOutFile,"\r\nSTRINGTABLE DISCARDABLE\r\nBEGIN\r\n");
}
else if(m_lMacFileNum%10 == 9)
{
fprintf(m_pOutFile,"END\r\n");
m_bOutFileComplete = true;
}
else{
fprintf(m_pOutFile,"%s%4s%s\r\n",szMacro," ",szValue);
m_bOutFileComplete = false;
}
// fflush(m_pOutFile);
m_lMacFileNum++;
}
void CScanstringtoolDlg::WriteJavaMac(char *szMacro, char *szValue)
{
fprintf(m_pOutFile,"%s%8s%s\r\n",szMacro," = ",szValue);
m_lMacFileNum++;
}
void CScanstringtoolDlg::OnBtnHelp()
{
// TODO: Add your control notification handler code here
CHelp helpDlg;
helpDlg.DoModal();
}
void CScanstringtoolDlg::WriteMacroValue()
{
CString szOutMacroValue = m_szOutFile +".map";
CFileStatus fStatus;
if(CFile::GetStatus(szOutMacroValue, fStatus) )
{
try{
CFile::Remove(szOutMacroValue);
}
catch(CFileException e)
{
//
AfxMessageBox("输出宏值文件覆盖失败!");
return;
}
}
int curType = m_ctlPrgType.GetCurSel();
if(curType!=1)
{
char szTmp[256];
long j = 1;
FILE *fp = fopen(szOutMacroValue,"a");
CString* p;
CString s;
POSITION pos = theApp.m_strToMacroMap.GetStartPosition();
while ( pos != NULL )
{
theApp.m_strToMacroMap.GetNextAssoc(pos, s, (CObject* &)p);
int iFormat = MAX_LINE_LEN - strlen(*p);
sprintf(szTmp,"#define %%s %%%dd\r\n",iFormat);
fprintf(fp, szTmp,*p,theApp.m_lMacroValue+j);
j++;
}
fclose(fp);
}//end if(curType!=1)
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -