2013-10-14 707 views
0

我最近爲一個學校項目編寫了下面的代碼;我的目標是制定一個基本的加密程序。目前要使用此程序加密文件,需要知道文件名並手動輸入到控制檯,包括文件擴展名。爲了提高程序的用戶友好性,我想實現一個功能來打開一個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! 

}

+0

你使用WinRT還是純C WinAPI? WinRT使這個*更容易,但只適用於更現代的Windows系統。 –

+0

這裏顯示的代碼如何與問題相關? –

回答

0

你指的 '開放式文件' 對話框是Windows API的一部分。要添加它,你必須編寫一堆代碼,這對於手頭的任務來說可能是不值得的。無論如何,如果你想這樣做,請在MSDN上閱讀更多關於它的信息。

+0

事實並非如此。最難的是知道你需要'GetConsoleWindow'中的HWND。 – MSalters

+0

非常感謝您的回答。你知道任何教程在某種程度上展示如何實現這個嗎?或者顯示其他人如何在過去實現這一點的代碼示例? –

+0

[MSDN](http://msdn.microsoft.com/en-us/library/windows/desktop/ff381399(v = vs.85).aspx)包含一些簡單的教程,對於我推薦的更高級的東西你找一些書(編程Windows等)。 – Alexander

相關問題