📄 mysigmakerdlg.cpp
字号:
// MySigMakerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MySigMaker.h"
#include "MySigMakerDlg.h"
#include <process.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BOOL IsFileExist(PCHAR pszFileName);
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CMySigMakerDlg dialog
CMySigMakerDlg::CMySigMakerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMySigMakerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMySigMakerDlg)
m_strLibName = _T("");
m_strSigPath = _T("");
m_strSigName = _T("");
m_strSigDesc = _T("");
m_strSigNameExt = _T("");
m_strProcess = _T("");
m_bDelTmpFile = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMySigMakerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMySigMakerDlg)
DDX_Control(pDX, CHK_DELTMPFILE, m_chkDelTmpFile);
DDX_Control(pDX, EDT_SIGPATH, m_edtSigPath);
DDX_Control(pDX, EDT_SIGNAME, m_edtSigName);
DDX_Control(pDX, EDT_SIGDESC, m_edtSigDesc);
DDX_Control(pDX, EDT_LIBNAME, m_edtLibName);
DDX_Control(pDX, BTN_OPENSIG, m_btnOpenSig);
DDX_Control(pDX, BTN_OPENLIB, m_btnOpenLib);
DDX_Control(pDX, BTN_MAKESIG, m_btnMakeSig);
DDX_Control(pDX, BTN_ABOUT, m_btnAbout);
DDX_Text(pDX, EDT_LIBNAME, m_strLibName);
DDX_Text(pDX, EDT_SIGPATH, m_strSigPath);
DDX_Text(pDX, EDT_SIGNAME, m_strSigName);
DDX_Text(pDX, EDT_SIGDESC, m_strSigDesc);
DDX_Text(pDX, EDT_SIGNAMEEXT, m_strSigNameExt);
DDX_Text(pDX, IDC_STATIC_PROCESS, m_strProcess);
DDX_Check(pDX, CHK_DELTMPFILE, m_bDelTmpFile);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMySigMakerDlg, CDialog)
//{{AFX_MSG_MAP(CMySigMakerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(BTN_OPENLIB, OnOpenlib)
ON_BN_CLICKED(BTN_OPENSIG, OnOpensig)
ON_BN_CLICKED(BTN_MAKESIG, OnMakesig)
ON_BN_CLICKED(BTN_ABOUT, OnAbout)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMySigMakerDlg message handlers
BOOL CMySigMakerDlg::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
TCHAR szModuleFile[MAX_PATH] = {0};
GetModuleFileName(NULL, szModuleFile, sizeof(szModuleFile)); //获取当前程序所在路径
if (_tcsrchr(szModuleFile, _T('\\')))
{
(_tcsrchr(szModuleFile, _T('\\')))[1] = 0;//删除文件名,只获得路径
}
if (0 == _tcslen(szModuleFile))
{
MessageBox(_T("本程序所在路径有问题,请将本程序放置在根目录下!"));
ExitProcess(-1);
}
_tcscpy(m_szCurrDir, szModuleFile);
SetCurrentDirectory(m_szCurrDir);
m_strSigPath = m_szCurrDir;
m_strSigNameExt = _T(".sig");
m_bDelTmpFile = TRUE;
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CMySigMakerDlg::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 CMySigMakerDlg::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 CMySigMakerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMySigMakerDlg::OnOpenlib()
{
// TODO: Add your control notification handler code here
CFileDialog openDlg(TRUE, _T("lib"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
_T("LIB库文件(*.lib)|*.lib||"), this);
if (openDlg.DoModal() != IDOK)
{
return;
}
m_strLibName = openDlg.GetPathName();
m_strSigName = openDlg.GetFileName();
m_strSigName = m_strSigName.Left(m_strSigName.Find(_T(".")));
m_strSigDesc = _T("My") + m_strSigName;
UpdateData(FALSE);
}
void CMySigMakerDlg::OnOpensig()
{
// TODO: Add your control notification handler code here
BROWSEINFO bi;
TCHAR szDisname[MAX_PATH]={0},szPath[MAX_PATH]={0};
ITEMIDLIST *pidl;
bi.hwndOwner=0;
bi.pidlRoot=0;
bi.pszDisplayName=szDisname;
bi.lpszTitle=_T("请选择Sig文件的存放路径:");
bi.ulFlags=BIF_RETURNONLYFSDIRS;// | BIF_EDITBOX;
bi.lpfn=0;
bi.lParam=1;
bi.iImage=1;
if(pidl=SHBrowseForFolder(&bi))
{
SHGetPathFromIDList(pidl,szPath);
UpdateData();
CString strSigPath=CString(szPath);
if(strSigPath.Right(1)!="\\")
{
strSigPath+="\\";
}
m_strSigPath = strSigPath;
UpdateData(false);
}
}
void MyThreadProc(LPVOID lpParam)
{
CMySigMakerDlg *pWnd = (CMySigMakerDlg *)lpParam;
if (NULL == pWnd)
{
return;
}
CString strNewSigName;
strNewSigName = pWnd->m_strSigName + pWnd->m_strSigNameExt;
//调用CSigMaker对象的MakeSig函数生成Sig文件
BOOL bRet = pWnd->m_SigMaker.MakeSig(pWnd->m_szCurrDir, pWnd->m_strLibName.GetBuffer(0),
pWnd->m_strSigPath.GetBuffer(0), strNewSigName.GetBuffer(0), pWnd->m_strSigDesc.GetBuffer(0),
pWnd->m_bDelTmpFile);
if (bRet)
{
MessageBox(NULL, _T("Sig文件生成成功!"), _T("提示"), MB_OK);
}
else
{
MessageBox(NULL, _T("Sig文件生成失败!"), _T("提示"), MB_OK);
}
pWnd->SetCtrlEnable(TRUE);
}
void CMySigMakerDlg::OnMakesig()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
SetCurrentDirectory(m_szCurrDir);
//判断路径和名称是否已经指定
m_strSigName.TrimLeft();
m_strSigDesc.TrimLeft();
if (m_strLibName.IsEmpty())
{
MessageBox(_T("Lib文件不能为空!"));
return;
}
if (m_strSigPath.IsEmpty())
{
MessageBox(_T("Sig保存路径不能为空!"));
return;
}
if (m_strSigName.IsEmpty())
{
MessageBox(_T("Sig文件名不能为空!"));
return;
}
if (m_strSigDesc.IsEmpty())
{
MessageBox(_T("Sig描述不能为空!"));
return;
}
//判定pcf.exe 和 sigmake.exe 文件是否和本程序在同一目录中
if (!(IsFileExist(_T("pcf.exe")) && IsFileExist(_T("sigmake.exe"))))
{
MessageBox(_T("未找到 pcf.exe 和 sigmake.exe 文件,请将这两个文件放置在本程序所在目录!"));
return;
}
SetCtrlEnable(FALSE);
//开线程生成sig文件
m_hThread = (HANDLE)_beginthread(MyThreadProc, 0, this);
}
void CMySigMakerDlg::OnAbout()
{
// TODO: Add your control notification handler code here
CAboutDlg dlg;
dlg.DoModal();
}
void CMySigMakerDlg::SetCtrlEnable(BOOL bEnable)
{
m_edtSigDesc.SetReadOnly(!bEnable);
m_edtSigName.SetReadOnly(!bEnable);
m_btnOpenLib.EnableWindow(bEnable);
m_btnOpenSig.EnableWindow(bEnable);
m_btnMakeSig.EnableWindow(bEnable);
m_chkDelTmpFile.EnableWindow(bEnable);
if (bEnable)
{
KillTimer(1);
SetDlgItemText(IDC_STATIC_PROCESS, _T(""));
}
else
{
SetTimer(1, 1000, NULL);
}
}
void CMySigMakerDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
UpdateData(TRUE);
if (m_strProcess.GetLength() > 28)
{
m_strProcess = _T(">>");
}
else
{
m_strProcess += _T(">>");
}
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -