调用系统对话框来查找类型文件
void TcharToChar(const TCHAR* tchar, char* _char)
{
int iLength;
//Get the length of byte
iLength = WideCharToMultiByte(CP_ACP, 0, tchar, -1, NULL, 0, NULL, NULL);
//give the value of tchar to _char
WideCharToMultiByte(CP_ACP, 0, tchar, -1, _char, iLength, NULL, NULL);
}
//打开文件对话框
void CV3ImportFileDlg::OnBnClickedButtonFile()
{
// TODO: 在此添加控件通知处理程序代码
char FileTitle[100] = "", FileName[MAX_PATH] = "";
HWND hwnd;
CString strTestFile = _T("");
OPENFILENAME ofn;
wchar_t _tFileTiTle[100] = _T(""), _tFileName[MAX_PATH] = _T("");
BOOL bRegular = FALSE;
while (!bRegular)
{
m_file = _T("");
hwnd = ::GetActiveWindow();
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.hInstance = NULL;
ofn.lpstrFilter = _T("Xml files *.xml\0 *.xml\0AllFile *.*\0*.*\0\0");
ofn.lpstrCustomFilter = NULL;
ofn.nMaxCustFilter = 0;
ofn.nFilterIndex = 1;
ofn.lpstrFile = _tFileName;
ofn.nMaxFile = 500;
ofn.lpstrFileTitle = _tFileTiTle;
ofn.nMaxFileTitle = 99;
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = _T("Get Xml File");
ofn.Flags = OFN_FILEMUSTEXIST;
ofn.lpstrDefExt = _T("bmp");
ofn.lCustData = NULL;
ofn.lpfnHook = NULL;
ofn.lpTemplateName = NULL;
if (GetOpenFileName(&ofn))
{
TcharToChar(_tFileName, FileName);
m_file = FileName;
}
else break;
}
UpdateData(FALSE);
}
m_file是Edit控件的关联变量;
查找xml文件;
运行在Unicode字符集下。