// BindHiderDlg.cpp : implementation file
//
// Auhor:Zhengqiu Zhang, Sept 11, 2005
// Corresponding address: zqzhang@cams.cma.gov.cn
//
#include "stdafx.h"
#include "BindHider.h"
#include "BindHiderDlg.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)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBindHiderDlg dialog
CBindHiderDlg::CBindHiderDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBindHiderDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBindHiderDlg)
m_Filename_Bind = _T("");
m_Filename_Client = _T("");
m_Filename_Host = _T("");
m_Filesize_Bind = _T("");
m_Filesize_Client = _T("");
m_Filesize_Host = _T("");
m_status = _T("");
m_Password = _T("");
m_Protected = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bBind=TRUE;
}
void CBindHiderDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBindHiderDlg)
DDX_Control(pDX, IDC_PASSWORD, m_editPassword);
DDX_Control(pDX, IDC_UNBIND, m_btnUnbind);
DDX_Control(pDX, IDC_BIND, m_btnBind);
DDX_Control(pDX, IDC_BROWSE_HOST, m_btnBrowseHost);
DDX_Control(pDX, IDC_BROWSE_CLIENT, m_btnBrowseClient);
DDX_Control(pDX, IDC_BROWSE_BIND, m_btnBrowseBind);
DDX_Control(pDX, IDC_FILENAME_HOST, m_editFilenameHost);
DDX_Control(pDX, IDC_FILENAME_CLIENT, m_editFilenameClient);
DDX_Control(pDX, IDC_FILENAME_BIND, m_editFilenameBind);
DDX_Control(pDX, IDC_PROGRESS, m_cProgress);
DDX_Text(pDX, IDC_FILENAME_BIND, m_Filename_Bind);
DDX_Text(pDX, IDC_FILENAME_CLIENT, m_Filename_Client);
DDX_Text(pDX, IDC_FILENAME_HOST, m_Filename_Host);
DDX_Text(pDX, IDC_FILESIZE_BIND, m_Filesize_Bind);
DDX_Text(pDX, IDC_FILESIZE_CLIENT, m_Filesize_Client);
DDX_Text(pDX, IDC_FILESIZE_HOST, m_Filesize_Host);
DDX_Text(pDX, IDC_STATUS, m_status);
DDX_Text(pDX, IDC_PASSWORD, m_Password);
DDX_Text(pDX, IDC_PROTECTED, m_Protected);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBindHiderDlg, CDialog)
//{{AFX_MSG_MAP(CBindHiderDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BROWSE_HOST, OnBrowseHost)
ON_BN_CLICKED(IDC_BROWSE_CLIENT, OnBrowseClient)
ON_BN_CLICKED(IDC_BROWSE_BIND, OnBrowseBind)
ON_BN_CLICKED(IDC_BIND, OnBind)
ON_BN_CLICKED(IDC_UNBIND, OnUnbind)
ON_BN_CLICKED(IDC_RADIO_BIND, OnRadioBind)
ON_BN_CLICKED(IDC_RADIO_UNBIND, OnRadioUnbind)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBindHiderDlg message handlers
BOOL CBindHiderDlg::OnInitDialog()
{
CDialog::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
CButton *pBtnBind=(CButton*)GetDlgItem(IDC_RADIO_BIND);
CButton *pBtnUnbind=(CButton*)GetDlgItem(IDC_RADIO_UNBIND);
pBtnBind->SetCheck(m_bBind);
pBtnUnbind->SetCheck(!m_bBind);
CheckBind();
return TRUE; // return TRUE unless you set the focus to a control
}
void CBindHiderDlg::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 CBindHiderDlg::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 CBindHiderDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CBindHiderDlg::EnableBindCtrl()
{
UpdateData();
//激活捆绑控件
m_btnBind.EnableWindow(m_bBind);
m_btnBrowseHost.EnableWindow(m_bBind);
m_editFilenameHost.EnableWindow(m_bBind);
//
m_btnBrowseClient.EnableWindow(m_bBind);
m_editFilenameClient.EnableWindow(m_bBind);
//激活分解控件
m_btnUnbind.EnableWindow(!m_bBind);
m_btnBrowseBind.EnableWindow(!m_bBind);
m_editFilenameBind.EnableWindow(!m_bBind);
//激活密码输入框
m_editPassword.EnableWindow(m_bBind);
}
// 从全程文件名中提取短文件名.
CString CBindHiderDlg::GetShortFileName(LPCSTR lpszFullPathName)
{
CString strFileName=lpszFullPathName;
CString strShortName;
strFileName.TrimLeft();
strFileName.TrimRight();
int n=strFileName.ReverseFind('\\');
strShortName=strFileName.Right(strFileName.GetLength()-n-1);
return strShortName;
}
CString CBindHiderDlg::Filesize(CString strFilename)
{
CString strFilesize;
struct _stat ST;
_stat(strFilename, &ST);
strFilesize.Format("%d", ST.st_size);
return strFilesize;
}
//选取宿主的文件
void CBindHiderDlg::OnBrowseHost()
{
CFileDialog fileDialog(TRUE,NULL,NULL,NULL,
"可执行文件(*.exe)|*.exe|所有文件(*.*)|*.*||");
if (fileDialog.DoModal() == IDOK)
{
m_Filename_Host = fileDialog.GetPathName(); //保存宿主的文件名
m_Filesize_Host=Filesize(m_Filename_Host);
m_Filename_Host=GetShortFileName(m_Filename_Host);
m_btnBind.EnableWindow((!m_Filename_Host.IsEmpty())&&
(!m_Filename_Client.IsEmpty()));
UpdateData(FALSE);
}
}
//选取被捆绑的文件
void CBindHiderDlg::OnBrowseClient()
{
CFileDialog fileDialog(TRUE,NULL,NULL,NULL,
"可执行文件(*.exe)|*.exe|所有文件(*.*)|*.*||");
if (fileDialog.DoModal() == IDOK)
{
m_Filename_Client = fileDialog.GetPathName(); //保存被捆绑的文件名
m_Filesize_Client=Filesize(m_Filename_Client);
m_Filename_Client=GetShortFileName(m_Filename_Client);
m_btnBind.EnableWindow((!m_Filename_Host.IsEmpty())&&
(!m_Filename_Client.IsEmpty()));
UpdateData(FALSE);
}
}
//选取已捆绑的文件
void CBindHiderDlg::OnBrowseBind()
{
CFileDialog fileDialo
- 1
- 2
- 3
前往页