📄 chaogedlg.cpp
字号:
// chaogeDlg.cpp : implementation file
//
#include "stdafx.h"
#include "chaoge.h"
#include "chaogeDlg.h"
#include "afxwin.h"
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <tchar.h>
#include <string.h>
#include <process.h>
#include <stdlib.h>
#include "fileopen.h"
#include "libFile.h"
#include "libRSA.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern void SHA1_Compute(unsigned char *pucInData,unsigned int uiInLen,unsigned char *pucDigest);
extern TCHAR szFileName[256],szTitleName[256];
CString csSignFileBuff;
int iSignFileLen;
ULONG ulBeginAddr,ulEndAddr,ulSignAddr,ulCmpLen,ulLen;
#define BIF_NEWDIALOGSTYLE 0x0040
#define BIF_USENEWUI (BIF_NEWDIALOGSTYLE | BIF_EDITBOX)
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CChaogeDlg dialog
CChaogeDlg::CChaogeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CChaogeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CChaogeDlg)
m_strCurPath = _T("");
m_BeginAdd = _T("0000");
m_EndAdd = _T("FFFF");
m_InsertAdd = _T("0000");
m_Sha1Data = _T("");
m_SignData = _T("");
m_RSAData = _T("");
m_Mod = _T("CDEDA3CEEC6CFDAC18FC835115A558E7487F5C01A1627A9659A6EDB8E9C78513D4359F5F745D7CFED594CFD5A5C8E4B2E0356557F2E088E2BDEEB709CBAD563F817AC2D5F3427AEC4B2083233AB274BCB2B3B98E8C894762AFE4ED95B718F682E2BF4EFFB1E0A3F17DF37C5F0F54FF55AE71F25504E3BC54EBFEFA8DC11EA9AA");
m_Key = _T("010001");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);
}
void CChaogeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChaogeDlg)
DDX_Text(pDX, IDC_EDIT1_FILEADDR, m_strCurPath);//文件路径
DDX_Text(pDX, IDC_EDIT3_BEGINADD, m_BeginAdd); //签名起始地址
DDV_MaxChars(pDX, m_BeginAdd, 4);
DDX_Text(pDX, IDC_EDIT4_ENDADD, m_EndAdd); //签名终止地址
DDV_MaxChars(pDX, m_EndAdd, 4);
DDX_Text(pDX, IDC_EDIT5_INSERTADD, m_InsertAdd);//签名地址
DDV_MaxChars(pDX, m_InsertAdd, 4);
DDX_Text(pDX, IDC_EDIT6_SHA1, m_Sha1Data);
DDV_MaxChars(pDX, m_Sha1Data, 42);
DDX_Text(pDX, IDC_EDIT7_SIGN, m_SignData);
DDX_Text(pDX, IDC_EDIT10_RSADATA, m_RSAData);
DDV_MaxChars(pDX, m_RSAData, 260);
DDX_Text(pDX, IDC_EDIT8_MOD, m_Mod);
DDV_MaxChars(pDX, m_Mod, 1024);
DDX_Text(pDX, IDC_EDIT9_KEY, m_Key);
DDV_MaxChars(pDX, m_Key, 1024);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChaogeDlg, CDialog)
//{{AFX_MSG_MAP(CChaogeDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_OPENFILE, OnButtonOpenfile)
ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit)
ON_BN_CLICKED(IDC_BUTTON_COMPUTECHECK, OnButtonComputecheck)
ON_BN_CLICKED(IDC_BUTTON_CREATESIGNFILE, OnButtonCreatesignfile)
ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear)
ON_BN_CLICKED(IDC_BUTTON_RSA, OnButtonRsa)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChaogeDlg message handlers
BOOL CChaogeDlg::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 CChaogeDlg::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 CChaogeDlg::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 CChaogeDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
int CChaogeDlg::SelectFolder(HWND hWnd,CString& strFolder)
{
strFolder.Empty();
LPMALLOC lpMalloc;
if (::SHGetMalloc(&lpMalloc) != NOERROR)
return 0;
char szDisplayName[_MAX_PATH];
char szBuffer[_MAX_PATH];
BROWSEINFO browseInfo;
browseInfo.hwndOwner = hWnd;
browseInfo.pidlRoot = NULL; // set root at Desktop
browseInfo.pszDisplayName = szDisplayName;
browseInfo.lpszTitle = "选择一个文件夹";
browseInfo.ulFlags = BIF_USENEWUI;
browseInfo.lpfn = NULL;
browseInfo.lParam = 0;
LPITEMIDLIST lpItemIDList;
if ((lpItemIDList = ::SHBrowseForFolder(&browseInfo)) != NULL)
{
// Get the path of the selected folder from the item ID list.
if (::SHGetPathFromIDList(lpItemIDList, szBuffer))
{ // At this point, szBuffer contains the path the user chose.
if (szBuffer[0] == '\0')
return 0;
// We have a path in szBuffer! Return it.
strFolder = szBuffer;
return 1;
}
else
return 1; // strResult is empty
lpMalloc->Free(lpItemIDList);
lpMalloc->Release();
}
return 1;
}
/*------------------------------------------------------------------*/
/* 日期: 2008-6-5 */
/* */
/* 用途与描述:选择文件夹,获得文件夹的路径 */
/*------------------------------------------------------------------*/
void CChaogeDlg::OnButtonDirbrowser()
{
// TODO: Add your control notification handler code here
static char displayname[MAX_PATH];
static char path[MAX_PATH];
LPITEMIDLIST pidlBrowse; // PIDL selected by user
BROWSEINFO bi;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -