使用GetOpenFileName 获取打开文件
#include <Windows.h>
string TCHAR2STRING(TCHAR* str)
{
// Function: TCHAR2STRING
// Description : TCHAR转string
// Input : str:待转化的TCHAR* 类型字符串
// Return : 转化后的string类型字符串
std::string strstr;
try
{
int iLen = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
char* chRtn = new char[iLen * sizeof(char)];
WideCharToMultiByte(CP_ACP, 0, str, -1, chRtn, iLen, NULL, NULL);
strstr = chRtn;
}
catch (exception e)
{
}
return strstr;
}
String filename;
OPENFILENAME ofn = { 0 };
TCHAR strFileName[MAX_PATH] = { 0 }; //用于接收文件名
ofn.lStructSize = sizeof(OPENFILENAME); //结构体大小
ofn.hwndOwner = NULL; //拥有着窗口句柄
ofn.lpstrFilter = TEXT("All\0*.*\0jpg\0*.jpg\0bmp\0*.bmp\0\0"); //设置过滤
ofn.nFilterIndex = 1; //过滤器索引
ofn.lpstrFile = strFileName; //接收返回的文件名,注意第一个字符需要为NULL
ofn.nMaxFile = sizeof(strFileName); //缓冲区长度
ofn.lpstrInitia