#include<windows.h>
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCamdShow)
{
OPENFILENAME ofn;
char szFile[MAX_PATH];
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = TEXT('\0');
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1; //如果改为2的话就会显示txt格式的文件。
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if(GetOpenFileName(&ofn))
{
ShellExecute(NULL,"open",ofn.lpstrFile,NULL,NULL,SW_SHOWNORMAL);//第三个参数是要打开的文件的路径,在你打开的时候自动生成并传给函数,再以open的方式打开,打开的方式将以你电脑系统对该类型文件的打开方式有关。
}
return 0;
}
温馨提示:内容为网友见解,仅供参考