操作系统win11,vs2012
#include <windows.h>
#include <Commdlg.h>
#include <stdio.h>
#include<graphics.h>
int FileDialog(char *path);
int main(char argc, char *argv[])
{
int i=0,num=0;
char szFile[MAX_PATH] = {0};
FileDialog(szFile); //1
printf("%s",szFile); //2如果删除这两行代码(即不调用这个函数),画布上能正常出现图片
initgraph(640,480,EX_SHOWCONSOLE | EX_NOCLOSE);
loadimage(NULL, _T("res/screenbk.png"));
getchar();
return 0;
}
// 通过 path 返回获取的路径
int FileDialog(char *path)
{
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn); // 结构大小
ofn.lpstrFile = path; // 路径
ofn.nMaxFile = MAX_PATH; // 路径大小
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0"; // 文件类型
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
return GetOpenFileName(&ofn);
}