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

Opening a Windows Explorer Window in C++

本文关键字:Windows 资源管理器 窗口 C++      更新时间:2023-10-16

我最近为一个学校项目编写了以下代码;我的目标是制作一个基本的加密程序。目前要使用此程序加密文件,需要知道文件名并手动输入控制台,包括文件扩展名。为了提高程序的用户友好性,我想实现一个功能来打开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!

}

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