C++ 选择文件对话框 函数 GetOpenFileName 使用的一个demo

来源:互联网 发布:淘宝哪家紫砂壶是真的 编辑:程序博客网 时间:2024/05/23 19:14
#include <windows.h>#include <commdlg.h>int main()  {  //     OPENFILENAME ofn;      // 公共对话框结构。   TCHAR szFile[MAX_PATH]; // 保存获取文件名称的缓冲区。             // 初始化选择文件对话框。   ZeroMemory(&ofn, sizeof(OPENFILENAME));  ofn.lStructSize = sizeof(OPENFILENAME);  ofn.hwndOwner = NULL;  ofn.lpstrFile = szFile;  ofn.lpstrFile[0] = '\0'; ofn.nMaxFile = sizeof(szFile);  ofn.lpstrFilter = "All(*.*)\0*.*\0Text(*.txt)\0*.TXT\0\0";  ofn.nFilterIndex = 1;  ofn.lpstrFileTitle = NULL;  ofn.nMaxFileTitle = 0;  ofn.lpstrInitialDir = NULL;  ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;  //ofn.lpTemplateName =  MAKEINTRESOURCE(ID_TEMP_DIALOG);  // 显示打开选择文件对话框。   if ( GetOpenFileName(&ofn) )  {  //显示选择的文件。   OutputDebugString(szFile);  OutputDebugString("\r\n");  } system("pause");return 0;} 


原创粉丝点击