#include<bits/stdc++.h>
#include<windows.h>
#include<commdlg.h>
#pragma comment(lib,"comdlg32.lib")
using namespace std;
int main(){
	OPENFILENAMEW ofn;
	wchar_t szFile[256]={0};
	ZeroMemory(&ofn,sizeof(ofn));
	ofn.lStructSize=sizeof(ofn);
	ofn.hwndOwner=NULL;
	ofn.lpstrFile=szFile;
	ofn.nMaxFile=sizeof(szFile)/sizeof(wchar_t);
	ofn.lpstrFilter=L"文本文件(*.txt)\0*.txt\0";
	ofn.lpstrTitle=L"打开";
	ofn.Flags=OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;
	if(GetOpenFileNameW(&ofn)){
		wstring wstrFile(szFile);
		string strFile(wstrFile.begin(),wstrFile.end());
		cout<<strFile<<endl;
	} else{
		cout<<CommDlgExtendedError()<<endl;
	}
	return 0;
}

