[英]Opening a Windows Explorer Window in C++
I recently wrote the following code for a school project; 我最近为学校项目编写了以下代码; with my objective to make a basic encryption program.
我的目标是制作一个基本的加密程序。 Currently to encrypt a file with this program, the file name needs to be known and typed in to the console manually including the file extension.
当前,要使用此程序加密文件,需要知道文件名并手动将其输入控制台(包括文件扩展名)。 To improve the program's user-friendliness, I wanted to implement a function to open a Windows file explorer window so the user can select the file they want to encrypt.
为了提高程序的用户友好性,我想实现一个功能来打开Windows文件浏览器窗口,以便用户可以选择他们想要加密的文件。 After much searching on the internet, I was not able to find any way to implement this into my code.
在Internet上进行了大量搜索之后,我找不到任何将其实现到我的代码中的方法。 So my question is, does this functionality exist in the C++ library, and if so how could I implement it into my code.
所以我的问题是,该功能是否存在于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!
} }
The 'open file' dialog you're refering to is a part of the Windows API. 您引用的“打开文件”对话框是Windows API的一部分。 To add it you'd have to write a bunch of code and it's probably not worth it for the task at hand.
要添加它,您必须编写一堆代码,对于手头的任务来说可能不值得。 If you want to do it anyway, read more about it on the MSDN .
如果仍然要执行此操作,请在MSDN上阅读有关它的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.