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

📄 filecryptdlg.cpp

📁 一些加密算法的介绍,可对文件或字符串加密
💻 CPP
📖 第 1 页 / 共 4 页
字号:
		poEdit->SetWindowText(oStrFilePath);
	}
}

void CFileCryptDlg::OnSelchangeCombomethods() 
{
	CComboBox* poComboBox;
	poComboBox = static_cast<CComboBox*>(GetDlgItem(IDC_COMBOMETHODS));
	int iSel = poComboBox->GetCurSel();
	ASSERT((iSel>=AES)&&(iSel<=XOR256_STREAM));
	m_iMethod = iSel;
}

void CFileCryptDlg::ShowStringGroup(BOOL bShow)
{
	CWnd* poWnd;
	poWnd = GetDlgItem(IDC_STATIC5);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_EDTSTR);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_RADPLAIN);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_LBLHEXPLAIN);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_EDTSTRHEX);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_RADPLAINHEX);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_STATICBMP2);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_STATIC6);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_EDTENC);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_LBLHEXENC);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_LBLHEXENC);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_EDTENCHEX);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
}

void CFileCryptDlg::ShowFileGroup(BOOL bShow)
{
	CWnd* poWnd;
	poWnd = GetDlgItem(IDC_STATIC1);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_LBLDIR1);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_EDTDIR1);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_BTNDIR1);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_LBLEXT1);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_EDTEXT1);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_LBLFILE1);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_EDTFILE1);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_BTNFILE1);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	//
	poWnd = GetDlgItem(IDC_STATICBMP1);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	//
	poWnd = GetDlgItem(IDC_STATIC3);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_LBLDIR3);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_EDTDIR3);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_BTNDIR3);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_LBLEXT3);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_EDTEXT3);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_LBLFILE3);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_EDTFILE3);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
	poWnd = GetDlgItem(IDC_BTNFILE3);
	poWnd->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
}

void CFileCryptDlg::MoveStringGroup()
{
	//Get y ref position
	CRect oRect;
	CWnd* poWnd;
	poWnd = GetDlgItem(IDC_BORDER);
	poWnd->GetWindowRect(&oRect);
	int iYRef = oRect.bottom;
	poWnd = GetDlgItem(IDC_STATIC5);
	poWnd->GetWindowRect(&oRect);
	int iDelta = oRect.top - iYRef;
	//Move up with Delta
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_EDTSTR);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_RADPLAIN);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_LBLHEXPLAIN);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_EDTSTRHEX);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_RADPLAINHEX);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_STATICBMP2);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_STATIC6);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_EDTENC);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_LBLHEXENC);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_EDTENCHEX);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
}

void CFileCryptDlg::MoveFileGroup()
{
	//Get y ref position
	CRect oRect;
	CWnd* poWnd;
	poWnd = GetDlgItem(IDC_BORDER);
	poWnd->GetWindowRect(&oRect);
	int iYRef = oRect.bottom;
	poWnd = GetDlgItem(IDC_STATIC1);
	poWnd->GetWindowRect(&oRect);
	int iDelta = oRect.top - iYRef;
	//Move up with Delta
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_LBLDIR1);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_EDTDIR1);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_BTNDIR1);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_LBLEXT1);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_EDTEXT1);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_LBLFILE1);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_EDTFILE1);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_BTNFILE1);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_STATICBMP1);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_STATIC3);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_LBLDIR3);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_EDTDIR3);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_BTNDIR3);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_LBLEXT3);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_EDTEXT3);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_LBLFILE3);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_EDTFILE3);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
	//
	poWnd = GetDlgItem(IDC_BTNFILE3);
	poWnd->GetWindowRect(&oRect);
	ScreenToClient(oRect);
	poWnd->SetWindowPos(NULL, oRect.left, oRect.top-iDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
}

void CFileCryptDlg::OnRadfile() 
{
	ShowStringGroup(FALSE);
	ShowFileGroup(TRUE);
	CRect oRect, oRectDlg;
	CWnd* poWnd = GetDlgItem(IDC_STATIC3);
	poWnd->GetWindowRect(&oRect);
	GetWindowRect(&oRectDlg);
	SetWindowPos(NULL, 0, 0, oRectDlg.Width(), oRect.bottom-oRectDlg.top+15, SWP_NOMOVE|SWP_NOZORDER);
	m_iMode = FILE;
}

void CFileCryptDlg::OnRadstring() 
{
	ShowFileGroup(FALSE);
	ShowStringGroup(TRUE);
	CRect oRect, oRectDlg;
	CWnd* poWnd = GetDlgItem(IDC_STATIC6);
	poWnd->GetWindowRect(&oRect);
	GetWindowRect(&oRectDlg);
	SetWindowPos(NULL, 0, 0, oRectDlg.Width(), oRect.bottom-oRectDlg.top+15, SWP_NOMOVE|SWP_NOZORDER);
	m_iMode = STRING;
}

int CALLBACK CFileCryptDlg::BrowseCallbackProc(HWND hWnd, UINT uMsg, LPARAM lp, LPARAM pData)
{
	TCHAR szDir[MAX_PATH] = {0};
    if(BFFM_INITIALIZED == uMsg)
    {
		//Remove Context Help Button
		DWORD dwStyle = ::GetWindowLong(hWnd, GWL_EXSTYLE);
		::SetWindowLong(hWnd, GWL_EXSTYLE, dwStyle&~WS_EX_CONTEXTHELP);
		//Window Caption
		::SetWindowText(hWnd, _T("Browse for Directory"));
		//Initial Selection
		::SendMessage(hWnd, BFFM_SETSELECTION, TRUE, (LPARAM)LPCTSTR(sm_oStrDir));
	}
	else if(BFFM_SELCHANGED == uMsg)
	{
		//Fail if non filesystem  ie "//server" selected : BIF_RETURNONLYFSDIRS
		if(!::SHGetPathFromIDList((LPITEMIDLIST)lp, szDir))
			::EnableWindow(::GetDlgItem(hWnd, IDOK), FALSE); // disable the OK button
		//Set the status window to the currently selected path (or NULL).
		::SendMessage(hWnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szDir);
	}
	return 0;
}

BOOL CFileCryptDlg::BrowseDialog(CString& roStrPath)
{
	BOOL bRetStatus = FALSE;
	BROWSEINFO bi;
	LPITEMIDLIST pidl;
	LPMALLOC pMalloc; // set a pointer to the shell's IMalloc interface
	if(!(SUCCEEDED(::SHGetMalloc(&pMalloc)))) //No memory for shell
		return FALSE;
    // Populate browse info structure
	::ZeroMemory(&bi,sizeof(bi));
	bi.hwndOwner = NULL;
	bi.pidlRoot  = NULL;
	bi.pszDisplayName = NULL;
	bi.lpszTitle = _T("Selected Directory:");
	bi.ulFlags  = BIF_RETURNONLYFSDIRS; // Only "directories"
	bi.ulFlags |= BIF_STATUSTEXT;       // Show the status window
	bi.lpfn = BrowseCallbackProc;
    // Display browse dialog
    pidl = ::SHBrowseForFolder(&bi);
    if(pidl != NULL) // pidl == NULL if cancelled the selection
	{
		// FALSE if "//server" selected - but this is caught in the BrowseCallbackProc
		// FALSE if cancelled
		char strPath[MAX_PATH];
		bRetStatus = ::SHGetPathFromIDList(pidl, strPath);
		roStrPath = strPath;
		pMalloc->Free(pidl); // Free the PIDL returned by SHBrowseForFolder.
    }
	pMalloc->Release(); // Release the shell's allocator.
	return bRetStatus ? TRUE : FALSE;
}

BOOL CFileCryptDlg::PreTranslateMessage(MSG* pMsg)
{
	//Relay events to the ToolTip Control
	m_oToolTipCtrl.RelayEvent(pMsg);
	return CDialog::PreTranslateMessage(pMsg);
}

void CFileCryptDlg::OnExit() 
{
	CDialog::EndDialog(IDOK);
}

void CFileCryptDlg::OnHelp() 
{
	//Not Implemented
	//if(NULL == HtmlHelp(this->m_hWnd, "FileCrypt.chm::/FileCrypt-getting started.htm>FileCrypt", HH_DISPLAY_TOPIC, NULL))
	//{
	//	MessageBox(CString(T("Cannot Find Help File!"), g_oStrError, MB_OK|MB_ICONINFORMATION);
	//}
}

void CFileCryptDlg::OnChangeEdthex() 
{
	CEdit* poEdit = (CEdit*)GetDlgItem(IDC_EDTENCHEX);
	CString oStr;
	poEdit->GetWindowText(oStr);
	int iLength = oStr.GetLength();
	poEdit = (CEdit*)GetDlgItem(IDC_EDTENC);
	if(0==iLength)
		poEdit->SetWindowText(_T(""));
	iLength >>= 1;
	unsigned char* pucBin = new unsigned char[iLength+1];
	Hex2Binary(LPCTSTR(oStr), pucBin, iLength);
	pucBin[iLength] = 0;
	//Find out if any 0-es and replace them with 0x0A or any non graphic char
	for(int i=0; i<iLength; i++)
		if(0 == pucBin[i])
			pucBin[i] = 0x0A;	
	poEdit->SetWindowText(CString(pucBin));	
	delete [] pucBin;
}

void CFileCryptDlg::OnRadkey() 
{
	m_oEditKeyData.EnableWindow(TRUE);
	m_oEditKeyData.SetBkColor(m_oKeyBg);
	m_oEditKeyDataHex.EnableWindow(FALSE);
	m_oEditKeyDataHex.SetBkColor(m_oKeyBg1);
}

void CFileCryptDlg::OnRadkeyhex() 
{
	m_oEditKeyData.EnableWindow(FALSE);
	m_oEditKeyData.SetBkColor(m_oKeyBg1);
	m_oEditKeyDataHex.EnableWindow(TRUE);
	m_oEditKeyDataHex.SetBkColor(m_oKeyBg);
}

void CFileCryptDlg::OnRadplain() 
{
	m_oEdtStr.EnableWindow(TRUE);
	m_oEdtStr.SetBkColor(m_oPlainBg);
	m_oEdtStrHex.EnableWindow(FALSE);
	m_oEdtStrHex.SetBkColor(m_oPlainBg1);
}

void CFileCryptDlg::OnRadplainhex() 
{
	m_oEdtStr.EnableWindow(FALSE);
	m_oEdtStr.SetBkColor(m_oPlainBg1);
	m_oEdtStrHex.EnableWindow(TRUE);
	m_oEdtStrHex.SetBkColor(m_oPlainBg);
}

⌨️ 快捷键说明

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