用C ++打开Windows资源管理器窗口

时间:2013-10-14 14:03:33

标签: c++ encryption

我最近为学校项目编写了以下代码;我的目标是制作一个基本的加密程序。目前,要使用此程序加密文件,需要知道文件名并手动输入控制台,包括文件扩展名。为了提高程序的用户友好性,我想实现一个打开Windows文件浏览器窗口的功能,以便用户可以选择要加密的文件。经过互联网搜索后,我无法找到任何方法将其实现到我的代码中。所以我的问题是,这个功能是否存在于C ++库中,如果是这样,我怎么能在我的代码中实现它。

#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!

}

1 个答案:

答案 0 :(得分:0)

您所引用的“打开文件”对话框是Windows API的一部分。要添加它,你必须编写一堆代码,这对于手头的任务来说可能不值得。如果您还想这样做,请在MSDN上了解更多相关信息。