方法1.在WinCE7中,打开文件需要用ShellExecuteEx函数,头文件为shellapi.h,需要用到SHELLEXECUTEINFO结构体。
CStdioFile myFile;
CFileDialog open_txt(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT, _T("文本文件(*.txt)|*.txt"),NULL);
open_txt.m_ofn.lpstrInitialDir = _T("\\SD\\Data");
if(open_txt.DoModal() == IDOK)
{CString txt_select;txt_select = open_txt.GetPathName();SHELLEXECUTEINFO te;memset(&te,0x00,sizeof(SHELLEXECUTEINFO));//清空内存te.lpFile=txt_select;te.lpFile=L"SD\\Notepad.exe";//用指定应用打开txt文件,如果不指定则会使用默认打开txt的应用te.lpVerb=L"open";//要对文件执行的操作te.cbSize = sizeof(SHELLEXECUTEINFO);te.fMask = SEE_MASK_NOCLOSEPROCESS;te.hwnd = NULL;te.nShow = SW_SHOWNORMAL;ShellExecuteEx(&te); //打开文件// 等待进程结束WaitForSingleObject(te.hProcess,INFINITE);if( te.hProcess != NULL){TerminateProcess(te.hProcess,0);te.hProcess = NULL;}
}
方法2.用创建进程的方式打开
CStdioFile myFile;
CFileDialog open_txt(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT, _T("文本文件(*.txt)|*.txt"),NULL);
open_txt.m_ofn.lpstrInitialDir = _T("\\SD\\Data");
if(open_txt.DoModal() == IDOK)
{CString txt_select;txt_select = open_txt.GetPathName();PROCESS_INFORMATION pi;CreateProcess(_T("SD\\Notepad.exe"), txt_select, NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi);// 等待进程结束WaitForSingleObject( pi.hProcess, INFINITE );CloseHandle( pi.hProcess );CloseHandle( pi.hThread );
}