// BindFileDlg.cpp : implementation file
//
#include "stdafx.h"
#include "BindFile.h"
#include "BindFileDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////////////////////////////////////////////
// 类名:CBindFileDlg
// 功能:进行可执行文件的绑定工作。
// 作者:徐景周(jingzhou_xu@163.net)
// 组织:未来工作室(Future Studio)
// 日期:2001.12.1
////////////////////////////////////////////////////////////////////////////
struct MODIFY_DATA {
unsigned int finder; // 常量(定位自身)
_off_t my_length; //文件长度(自身)
} modify_data = {0x12345678, 0};
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CWBButton m_AboutOK; //改为位图按钮显示
//}}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)
virtual BOOL OnInitDialog();
//}}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)
DDX_Control(pDX, IDOK, m_AboutOK);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBindFileDlg dialog
CBindFileDlg::CBindFileDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBindFileDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBindFileDlg)
m_strFirstPath = _T("");
m_strSecondPath = _T("");
m_strFinalPath = _T("");
m_Parts = _T("状态显示:");
m_Sync = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CBindFileDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBindFileDlg)
DDX_Control(pDX, IDC_PROGRESS, m_Progress);
DDX_Control(pDX, IDCANCEL, m_Cancel);
DDX_Control(pDX, IDC_SECONDBROWSE, m_SecondBrowse);
DDX_Control(pDX, IDC_FIRSTBROWSE, m_FirstBrowse);
DDX_Control(pDX, IDC_FINALBROWSE, m_FinalBrowse);
DDX_Control(pDX, IDC_BUTTON_BINDFILE, m_BindFile);
DDX_Control(pDX, IDC_BUTTON_ABOUT, m_About);
DDX_Control(pDX, IDC_SECONDPATH, m_SecondPath);
DDX_Control(pDX, IDC_FIRSTPATH, m_FirstPath);
DDX_Control(pDX, IDC_FINALPATH, m_FinalPath);
DDX_Text(pDX, IDC_FIRSTPATH, m_strFirstPath);
DDX_Text(pDX, IDC_SECONDPATH, m_strSecondPath);
DDX_Text(pDX, IDC_FINALPATH, m_strFinalPath);
DDX_Text(pDX, IDC_PARTS, m_Parts);
DDX_Radio(pDX, IDC_RADIO_SYNC, m_Sync);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBindFileDlg, CDialog)
//{{AFX_MSG_MAP(CBindFileDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_ABOUT, OnButtonAbout)
ON_BN_CLICKED(IDC_FIRSTBROWSE, OnFirstBrowse)
ON_BN_CLICKED(IDC_SECONDBROWSE, OnSecondBrowse)
ON_BN_CLICKED(IDC_FINALBROWSE, OnFinalBrowse)
ON_BN_CLICKED(IDC_BUTTON_BINDFILE, OnButtonBindFile)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBindFileDlg message handlers
BOOL CBindFileDlg::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
//把两个文件选择路径的静态框,设置内部显示方式为,
//在显示长路径名时,省略中间路径,只显示两边路径。
m_FinalPath.SubclassDlgItem (IDC_FINALPATH, this);
m_FinalPath.SetPath (TRUE);
m_FirstPath.SubclassDlgItem (IDC_FIRSTPATH, this);
m_FirstPath.SetPath (TRUE);
m_SecondPath.SubclassDlgItem (IDC_SECONDPATH, this);
m_SecondPath.SetPath (TRUE);
//设置位图按钮
m_FirstBrowse.LoadBitmaps(IDB_BITMAP2,6, 1, 1, 1, 1 );
m_FirstBrowse.SetFontColor(RGB(240,200,90));
m_SecondBrowse.LoadBitmaps(IDB_BITMAP2,6, 1, 1, 1, 1 );
m_SecondBrowse.SetFontColor(RGB(240,200,90));
m_FinalBrowse.LoadBitmaps(IDB_BITMAP2,6, 1, 1, 1, 1 );
m_FinalBrowse.SetFontColor(RGB(240,200,90));
m_BindFile.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_About.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_Cancel.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
//在此初始化渐变色进度条
m_Progress.SetRange32(1,500);
m_Progress.SetBkColor(RGB(160,180,220));
m_Progress.ShowPercent(true);
m_Progress.SetPos(500);
//初始置各文件名变量为空
strFirstFilePath = "";
strSecondFilePath = "";
strFinalFilePath = "";
//初始化变量
prog1_length = 0;
his_name = "";
buf = NULL;
//获取自身文件名
::GetModuleFileName(0, my_name, sizeof(my_name));
struct _stat ST;
_stat(my_name, &ST);
//此外加入捆绑器程序的最终大小,来判断是绑定文件还是分解执行文件
if(ST.st_size > 184*1024)
{
Unbind_and_Run(); //分离文件并运行
exit(0); //直接退出程序,不显示捆绑程序画面
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CBindFileDlg::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 CBindFileDlg::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 CBindFileDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//枚举所有图标资源
BOOL CALLBACK my_enum_res_callback(
HMODULE hExe, // 资源句柄
LPCTSTR lpszType, // 资源类型
LPTSTR lpszName, // 资源名称
LPARAM lParam // 自定义消息参数
)
{
HRSRC hRsrc = 0;
HGLOBAL hMem;
DWORD nDataLen;
NEWHEADER* pDirHeader;
RESDIR* pResDir;
BYTE* pData;
unsigned int k;
my_enum_res_callback_data* pMyDataStruct = (my_enum_res_callback_data*)lParam;
hRsrc = FindResource(hExe, lpszName, RT_GROUP_ICON);
hMem = LoadResource(hExe, hRsrc);
pDirHeader = (NEWHEADER*)LockResource(hMem);
pResDir = (RESDIR*)(pDirHeader+1);
for (k = 0; k < pDirHeader->ResCount; k++)
{
if (pResDir[k].BytesInRes == pMyDataStruct->pcResDir->BytesInRes &&
pResDir[k].BitCount == pMyDataStruct->pcResDir->BitCount &&
pResDir[k].Planes == pMyDataStruct->pcResDir->Planes &&
memcmp(&pResDir[k].I
- 1
- 2
- 3
前往页