如题,现在使用VC2017,听说可以使用OpenFileDialog,刚入门小白,请问具体需要怎么用,感谢各位大神
4条回答 默认 最新
- threenewbee 2018-07-11 23:29关注
这是原生C++的做法:
// Q694481_Win32.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <windows.h> #include <Commdlg.h> #include <stdio.h> OPENFILENAME ofn; char szFile[300]; int main() { ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = NULL; ofn.lpstrFile = (LPWSTR)szFile; ofn.lpstrFile[0] = '\0'; ofn.nMaxFile = sizeof(szFile); ofn.lpstrFilter = L"All\0*.*\0Text\0*.TXT\0"; ofn.nFilterIndex = 1; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; ofn.lpstrInitialDir = NULL; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; if (GetOpenFileName(&ofn)) { wprintf(L"%s\n", ofn.lpstrFile); } else { printf("user cancelled\n"); } return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 4无用