1、C++、MFC
ShellExecute
原型如下:
HINSTANCE ShellExecute(
HWND hwnd, //父窗口句柄
LPCTSTR lpOperation, //操作, 打开方式 "edit","explore","open","find","print","NULL"
LPCTSTR lpFile, //文件名,前面可加路径
LPCTSTR lpParameters, //参数
LPCTSTR lpDirectory, //默认文件夹
INT nShowCmd //显示方式
);
使用方法如下:
ShellExecute(NULL,_T("open"),_T("C:\\Users\\Administrator\\Desktop\\test.txt"), NULL, NULL, SW_SHOWNORMAL); // 打开文件
ShellExecute(NULL, "open", "http://www.baidu.com", NULL, NULL, SW_SHOWNORMAL); // 打开网页http://www.baidu.com
ShellExecute(NULL, _T("open"), _T("C:\\Users"), NULL, NULL, SW_SHOWNORMAL); // 打开目录D:\C++
ShellExecute(NULL,"print","C:\\Test.txt",NULL,NULL , SW_HIDE); // 打印文件C:\Test.txt
这个函数可以打开任意文件,会调用系统注册的程序来打开对应后缀名的文件。
2、C#
string m_File = @"data//1.txt";
System.Diagnostics.Process.Start(Path.GetFullPath(m_File)).Close();//.WaitForExit();