#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
猜你喜欢
转载自blog.csdn.net/c5113620/article/details/79995337
今日推荐
周排行