如上楼 效果要是这样的 获得的路径要能用在fopen()中#include <stdio.h>FILE *stream, *stream2;void main( void ) { int numclosed; /* Open for read (will fail if file "data" does not exist) */ if( (stream = fopen( "data", "r" )) == NULL ) printf( "The file 'data' was not opened\n" ); else printf( "The file 'data' was opened\n" ); /* Open for write */ if( (stream2 = fopen( "data2", "w+" )) == NULL ) printf( "The file 'data2' was not opened\n" ); else printf( "The file 'data2' was opened\n" ); /* Close stream */ if( fclose( stream ) ) printf( "The file 'data' was not closed\n" ); /* All other files are closed: */ numclosed = _fcloseall( ); printf( "Number of files closed by _fcloseall: %u\n", numclosed ); }
CString csFileName;
if( dlg.DoModal() == IDOK )
{
csFileName = dlg.GetPathName(); //选择的文件路径
}
NULL,
OFN_FILEMUSTEXIST | OFN_SHAREAWARE | OFN_PATHMUSTEXIST,
TEXT("PNG图片 (*.png)|*.png|所有文件(*.*)|*.*|"),
NULL);
if(dlg.DoModal()==IDOK)
{
CString strPathName = dlg.GetPathName();
}strPathName 为文件路径
{
CString FilePathName;
CFileDialog dlg(TRUE);
if (dlg.DoModal()==IDOK)
{
FilePathName = dlg.GetPathName(); 这样可以打开并获得你选择文件的完整路径
}
// TODO: 在此添加控件通知处理程序代码
}
{
int numclosed; /* Open for read (will fail if file "data" does not exist) */
if( (stream = fopen( "data", "r" )) == NULL )
printf( "The file 'data' was not opened\n" );
else
printf( "The file 'data' was opened\n" ); /* Open for write */
if( (stream2 = fopen( "data2", "w+" )) == NULL )
printf( "The file 'data2' was not opened\n" );
else
printf( "The file 'data2' was opened\n" ); /* Close stream */
if( fclose( stream ) )
printf( "The file 'data' was not closed\n" ); /* All other files are closed: */
numclosed = _fcloseall( );
printf( "Number of files closed by _fcloseall: %u\n", numclosed );
}
BROWSEINFO bBrowInfo;
char Buffer[MAX_PATH];
//初始化入口参数开始
bBrowInfo.hwndOwner = NULL;
bBrowInfo.pidlRoot = NULL;
bBrowInfo.pszDisplayName = Buffer;//此参数如为NULL则不能显示对话框
bBrowInfo.lpszTitle="请选择替换路径";//选择对话框提示语言
bBrowInfo.ulFlags = 0;
bBrowInfo.lpfn = NULL;
bBrowInfo.iImage=NULL;
//初始化入口参数bi结束
LPITEMIDLIST pIDList = SHBrowseForFolder(&bBrowInfo);//调用显示选择对话框
if(pIDList)
{
SHGetPathFromIDList(pIDList, Buffer);
//取得文件夹路径到Buffer里
sFolderPath = Buffer;//将路径保存在一个CString对象里
}