#include <windows.h>
#include <Commdlg.h>
#include <stdio.h>
OPENFILENAME ofn;
// a another memory buffer to contain the file name
char szFile[100];
int main()
{
// open a file name
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFile = 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))
{
// Now simpley display the file name
MessageBox(NULL, ofn.lpstrFile, L"File Name", MB_OK);
}
else
{
printf("user cancle\n");
}
return 0;
}
c语言--windows文件选择对话框--windows api--GetOpenFileName
最新推荐文章于 2021-11-08 11:02:20 发布