本文共 723 字,大约阅读时间需要 2 分钟。
OPENFILENAME结构参考MSDN。
HANDLE OpenDataFile(HWND hWnd){ OPENFILENAME ofn; HANDLE hFile; char szFileName[MAX_PATH]; strcpy(szFileName, "file.txt"); memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hWnd; ofn.lpstrFilter = "Text Files (*.TXT)\0*.txt\0\ ASCII Files (*.ASC)\0*.asc\0\ All Files (*.*)\0*.*\0\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.lpstrTitle = "Open File"; ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; if(GetOpenFileName(&ofn)) hFile = CreateFile(szFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); else MessageBox(0, "Cannot open the file", "Open File", MB_ICONSTOP | MB_OK); return hFile;}
转载地址:http://nssli.baihongyu.com/