⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 passwordgendlg.cpp

📁 按照不同的组合生成密码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// PasswordGenDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PasswordGen.h"
#include "PasswordGenDlg.h"
#include "math.h"
#include "shlwapi.h"
#include "shlobj.h"
#include "PasswordGeneration.h"

//#include "htmlhelp.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()

/////////////////////////////////////////////////////////////////////////////
// CPasswordGenDlg dialog
CString str;
CString strComposition;
CString strNum,strCount;
UINT ComputeThreadProc(LPVOID pParam)
{
    CPasswordGeneration *pwg = new CPasswordGeneration;
	char cFileDir[100];
	int i;

	for (i=0; i<str.GetLength(); i++)
	{
		cFileDir[i] = str.GetAt(i);
	}
	cFileDir[i] = '\0';
	TRACE("\n\n%s\n\n",cFileDir);

	if (strComposition == "数字")
	{
		pwg->DigPasswordGen(cFileDir,StrToInt(strNum),StrToInt(strCount));
	}
	if (strComposition == "小写字母")
	{
		pwg->LowercasePasswordGen(cFileDir,StrToInt(strNum),StrToInt(strCount));
	}
	if (strComposition == "数字大写字母")
	{
		pwg->DigCapitalPasswordGen(cFileDir,StrToInt(strNum),StrToInt(strCount));
	}
	if (strComposition == "大小写字母")
	{
		pwg->LowercaseCapitalPasswordGen(cFileDir,StrToInt(strNum),StrToInt(strCount));
	}
	if (strComposition == "数字小写字母")
	{
		pwg->DigLowercasePasswordGen(cFileDir,StrToInt(strNum),StrToInt(strCount));
	}
	if (strComposition == "数字大小写字母")
	{
		pwg->DigLowercaseCapitalPasswordGen(cFileDir,StrToInt(strNum),StrToInt(strCount));
	}
	if (strComposition == "大写字母")
	{
		pwg->CapitalPasswordGen(cFileDir,StrToInt(strNum),StrToInt(strCount));
	}

	delete pwg;	
//	AfxMessageBox("完成!","生成密码",MB_OK);

//	volatile int nTemp; // volatile else compiler optimizes too much

//	for (g_nCount = 0; g_nCount < CComputeDlg::nMaxCount;
//	                   ::InterlockedIncrement((long*) &g_nCount)) {
//		for (nTemp = 0; nTemp < 10000; nTemp++) {
			// uses up CPU cycles
//		}
//	}
	// WM_THREADFINISHED is user-defined message
	::PostMessage((HWND) pParam, WM_THREADFINISHED, 0, 0);
//	g_nCount = 0;
	return 0; // ends the thread
}

CPasswordGenDlg::CPasswordGenDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPasswordGenDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPasswordGenDlg)
	m_Static_CodeInfo = _T("");
	m_Edit_Num = _T("");
	m_Edit_Count = _T("");
	m_Edit_Loc = _T("");
	m_Static_Descr = _T("");
	m_Edit_FileNum = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CPasswordGenDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPasswordGenDlg)
	DDX_Control(pDX, IDC_PROGRESS_FILE, m_ProgressFileCtrl);
	DDX_Control(pDX, IDC_CHECK_LC, m_Check_LCCtrl);
	DDX_Control(pDX, IDC_CHECK_L, m_Check_LCtrl);
	DDX_Control(pDX, IDC_CHECK_DL, m_Check_DLCtrl);
	DDX_Control(pDX, IDC_CHECK_DC, m_Check_DCCtrl);
	DDX_Control(pDX, IDC_CHECK_D, m_Check_DCtrl);
	DDX_Control(pDX, IDC_CHECK_C, m_Check_CCtrl);
	DDX_Control(pDX, IDC_CHECK_DLC, m_Check_DLCCtrl);
	DDX_Text(pDX, IDC_STATIC_CODE, m_Static_CodeInfo);
	DDX_Text(pDX, IDC_EDIT_NUM, m_Edit_Num);
	DDX_Text(pDX, IDC_EDIT_COUNT, m_Edit_Count);
	DDX_Text(pDX, IDC_EDIT_LOC, m_Edit_Loc);
	DDX_Text(pDX, IDC_STATIC_Descr, m_Static_Descr);
	DDX_Text(pDX, IDC_EDIT_FILENUM, m_Edit_FileNum);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPasswordGenDlg, CDialog)
	//{{AFX_MSG_MAP(CPasswordGenDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_CHECK_C, OnCheckC)
	ON_BN_CLICKED(IDC_CHECK_DLC, OnCheckDLC)
	ON_BN_CLICKED(IDC_CHECK_DL, OnCheckDL)
	ON_BN_CLICKED(IDC_CHECK_LC, OnCheckLC)
	ON_BN_CLICKED(IDC_CHECK_DC, OnCheckDC)
	ON_BN_CLICKED(IDC_CHECK_L, OnCheckL)
	ON_BN_CLICKED(IDC_CHECK_D, OnCheckD)
	ON_EN_CHANGE(IDC_EDIT_NUM, OnChangeEditNum)
	ON_EN_SETFOCUS(IDC_EDIT_NUM, OnSetfocusEditNum)
	ON_BN_CLICKED(IDC_BUTTON_DIR, OnButtonDir)
	ON_EN_CHANGE(IDC_EDIT_COUNT, OnChangeEditCount)
	ON_BN_CLICKED(IDRESET, OnReset)
	ON_BN_CLICKED(IDHELP, OnHelp)
	ON_MESSAGE(WM_THREADFINISHED, OnThreadFinished)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPasswordGenDlg message handlers

BOOL CPasswordGenDlg::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
	//把除了组合之外的控件变为不可用
	GetDlgItem(IDOK)->EnableWindow(false);//开始按钮不可用
	GetDlgItem(IDC_EDIT_NUM)->EnableWindow(false);//密码位数编辑框不可用
	GetDlgItem(IDC_BUTTON_DIR)->EnableWindow(false);//文件存放位置不可用
	GetDlgItem(IDC_EDIT_COUNT)->EnableWindow(false);//每个文件存放的密码个数不可用

    //m_strComposition = "密码信息显示";
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CPasswordGenDlg::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 CPasswordGenDlg::OnPaint() 
{
	static int iFirst = 0;
	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();
	}

	if (iFirst == 0)
	{
		MessageBox("本程序要占用大量的资源,因此在生成密码前,强烈建议把其它的应用程序关闭!","生成密码",MB_OK);
		iFirst = 1;
	}

//	UpdateData(false);
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CPasswordGenDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CPasswordGenDlg::OnCheckC() 
{
	// TODO: Add your control notification handler code here
	if (m_Check_CCtrl.GetCheck() == 1)
	{
		//把其它的选项变为不可用
		GetDlgItem(IDC_CHECK_DLC)->EnableWindow(false);
		GetDlgItem(IDC_CHECK_DL)->EnableWindow(false);
		GetDlgItem(IDC_CHECK_LC)->EnableWindow(false);
		GetDlgItem(IDC_CHECK_DC)->EnableWindow(false);
		GetDlgItem(IDC_CHECK_D)->EnableWindow(false);
		GetDlgItem(IDC_CHECK_L)->EnableWindow(false);
		//密码位数输入编辑框可用
		GetDlgItem(IDC_EDIT_NUM)->EnableWindow(true);
		//显示选择了组合名称
		strComposition = "大写字母";
		iNum = 26;
	}
	else
	{
		//启动其它的控件
		GetDlgItem(IDC_CHECK_DLC)->EnableWindow(true);
		GetDlgItem(IDC_CHECK_DL)->EnableWindow(true);
		GetDlgItem(IDC_CHECK_LC)->EnableWindow(true);
		GetDlgItem(IDC_CHECK_DC)->EnableWindow(true);
		GetDlgItem(IDC_CHECK_D)->EnableWindow(true);
		GetDlgItem(IDC_CHECK_L)->EnableWindow(true);
		//密码位数输入编辑框不可用
		GetDlgItem(IDC_EDIT_NUM)->EnableWindow(false);
		m_Edit_Num = "0";
	}
}

void CPasswordGenDlg::OnCheckDLC() 
{
	// TODO: Add your control notification handler code here
	if (m_Check_DLCCtrl.GetCheck() == 1)
	{
		//把其它的选项变为不可用
		GetDlgItem(IDC_CHECK_C)->EnableWindow(false);
		GetDlgItem(IDC_CHECK_DL)->EnableWindow(false);
		GetDlgItem(IDC_CHECK_LC)->EnableWindow(false);
		GetDlgItem(IDC_CHECK_DC)->EnableWindow(false);
		GetDlgItem(IDC_CHECK_D)->EnableWindow(false);
		GetDlgItem(IDC_CHECK_L)->EnableWindow(false);
		//密码位数输入编辑框可用
		GetDlgItem(IDC_EDIT_NUM)->EnableWindow(true);
		//显示选择了组合名称
		strComposition = "数字大小写字母";
		iNum = 62;
	}
	else
	{
		//启动其它的控件
		GetDlgItem(IDC_CHECK_C)->EnableWindow(true);
		GetDlgItem(IDC_CHECK_DL)->EnableWindow(true);
		GetDlgItem(IDC_CHECK_LC)->EnableWindow(true);
		GetDlgItem(IDC_CHECK_DC)->EnableWindow(true);
		GetDlgItem(IDC_CHECK_D)->EnableWindow(true);
		GetDlgItem(IDC_CHECK_L)->EnableWindow(true);
		//密码位数输入编辑框不可用
		GetDlgItem(IDC_EDIT_NUM)->EnableWindow(false);
		m_Edit_Num = "0";
	}
}

void CPasswordGenDlg::OnCheckDL() 
{
	// TODO: Add your control notification handler code here
	if (m_Check_DLCtrl.GetCheck() == 1)
	{
		//把其它的选项变为不可用
		GetDlgItem(IDC_CHECK_C)->EnableWindow(false);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -