我最近爲一個學校項目編寫了下面的代碼;我的目標是制定一個基本的加密程序。目前要使用此程序加密文件,需要知道文件名並手動輸入到控制檯,包括文件擴展名。爲了提高程序的用戶友好性,我想實現一個功能來打開一個Windows文件瀏覽器窗口,以便用戶可以選擇他們想要加密的文件。在互聯網上進行了大量搜索之後,我無法找到任何方法將其實施到我的代碼中。所以我的問題是,這個功能是否存在於C++庫中,如果可以的話,我怎樣才能將它實現到我的代碼中。在C++中打開Windows資源管理器窗口
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
using namespace std;
#define ENCRYPTION_FORMULA (int) Byte * 25
#define DECRYPTION_FORMULA (int) Byte/25
int Encrypt (char * FILENAME, char * NEW_FILENAME)
{
std::ifstream inFile;
std::ofstream outFile;
char Byte;
inFile.open(FILENAME, ios::in | ios::binary);
outFile.open(NEW_FILENAME, ios::out | ios::binary);
while(!inFile.eof())
{
char NewByte;
Byte = inFile.get();
if (inFile.fail())
return 0;
NewByte = ENCRYPTION_FORMULA;
outFile.put(NewByte);
}
inFile.close();
outFile.close();
return 1;
}
int Decrypt (char * FILENAME, char * NEW_FILENAME)
{
std::ifstream inFile;
std::ofstream outFile;
char Byte;
inFile.open(FILENAME, ios::in | ios::binary);
outFile.open(NEW_FILENAME, ios::out | ios::binary);
while(!inFile.eof())
{
char NewByte;
Byte = inFile.get();
if (inFile.fail())
return 0;
NewByte = DECRYPTION_FORMULA;
outFile.put(NewByte);
}
inFile.close();
outFile.close();
return 1;
}
int main()
{
char EncFile[200];
char NewEncFile[200];
char DecFile[200];
char NewDecFile[200];
int Choice;
cout << "NOTE: You must encrypt the file with the same file extension!"<<endl;
cout << "Enter 1 to Encrypt/2 to Decrypt"<<endl;
cin >> Choice;
switch(Choice)
{
case 1:
cout << "Enter the current Filename: ";
cin >> EncFile;
cout << "Enter the new Filename: ";
cin >> NewEncFile;
Encrypt(EncFile, NewEncFile);
break;
case 2:
cout << "Enter the current Filename: ";
cin >> DecFile;
cout << "Enter the new Filename: ";
cin >> NewDecFile;
Decrypt(DecFile, NewDecFile);
break;
}
return 0; //Exit!
}
你使用WinRT還是純C WinAPI? WinRT使這個*更容易,但只適用於更現代的Windows系統。 –
這裏顯示的代碼如何與問題相關? –