我用c++ d出文件管理对话框,选择文件后怎么得到所选文件路径啊

我用c++ d出文件管理对话框,选择文件后怎么得到所选文件路径啊,第1张

 CFileDialog dlg(TRUE,_T(""),_T(""),OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT|OFN_ENABLESIZING,

        _T("All Music Files|mp3;wav;wma;mid;midi;rmi;ape;cue|\

           MP3 File (mp3)|mp3|\

           Wav File (wav)|wav|\

           Wma File (wma)|wma|\

           Midi File (mid;midi;rmi)|mid;midi;rmi|"));

    char szPath[2048];

    memset(szPath, 0, sizeof(szPath));

    dlgm_ofnlpstrFile = szPath;

    dlgm_ofnnMaxFile = sizeof(szPath);

    if (IDOK == dlgDoModal())

    {

        m_iFileCount = 0;

        CString strPath;

        POSITION pos = dlgGetStartPosition();

        while (NULL != pos)

        {

            strPathEmpty();

            strPath =dlgGetNextPathName(pos);

           

        }

    }

    else

    {

        return;

    }

用GetOpenFileName

OPENFILENAME ofn; // common dialog box structure

char szFile[260]; // buffer for filename

HWND hwnd; // owner window

HANDLE hf; // file handle

// Initialize OPENFILENAME

ZeroMemory(&ofn, sizeof(OPENFILENAME));

ofnlStructSize = sizeof(OPENFILENAME);

ofnhwndOwner = hwnd;

ofnlpstrFile = szFile;

ofnnMaxFile = sizeof(szFile);

ofnlpstrFilter = "All\0\0Text\0TXT\0";

ofnnFilterIndex = 1;

ofnlpstrFileTitle = NULL;

ofnnMaxFileTitle = 0;

ofnlpstrInitialDir = NULL;

ofnFlags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

// Display the Open dialog box

if (GetOpenFileName(&ofn)==TRUE)

hf = CreateFile(ofnlpstrFile, GENERIC_READ,

0, (LPSECURITY_ATTRIBUTES) NULL,

OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,

(HANDLE) NULL);

引用:msdn

ofnlpstrFile 就是选中的文件

JFileChooser 就行, 参考以下帮助文档JFileChooser chooser = new JFileChooser();

FileNameExtensionFilter filter = new FileNameExtensionFilter(

"JPG & GIF Images", "jpg", "gif");

choosersetFileFilter(filter);

int returnVal = choosershowOpenDialog(parent);

if(returnVal == JFileChooserAPPROVE_OPTION) {

Systemoutprintln("You chose to open this file: " +

choosergetSelectedFile()getName());

}

以下是我的代码,已经测试通过:

Dim fso As Object

Dim wsh As Object

Dim DesktopPath As String

Dim bReady As Boolean

Public Function formatPath(sPath As String) As String

formatPath = sPath

If Right(sPath, 1) <> "\" Then formatPath = sPath & "\"

End Function

Private Sub Form_Load()

Set fso = CreateObject("ScriptingFileSystemObject")

Set wsh = CreateObject("WScriptShell")

DesktopPath = wshSpecialFolders("Desktop") & "\" '获取桌面路径

bReady = False

End Sub

Private Sub Form_Unload(Cancel As Integer)

Set fso = Nothing

Set wsh = Nothing

End Sub

Private Sub Dir1_Change()

File1Path = Dir1Path ' 当目录改变时,设置文件路径

End Sub

Private Sub File1_Click()

sPath = formatPath(Dir1List(Dir1ListIndex)) '获取选择的路径

Text1Text = sPath & File1FileName

bReady = True

End Sub

Private Sub Command1_Click() '复制

If bReady = True Then fsoCopyFile Text1Text, DesktopPath & File1FileName

End Sub

Private Sub Command2_Click() '删除

If bReady = True Then fsoDeleteFile Text1Text: File1Refresh

End Sub

Private Sub Command3_Click() '剪切

If bReady = True Then fsoMoveFile Text1Text, DesktopPath & File1FileName: File1Refresh

End Sub

以上就是关于我用c++ d出文件管理对话框,选择文件后怎么得到所选文件路径啊全部的内容,包括:我用c++ d出文件管理对话框,选择文件后怎么得到所选文件路径啊、VC中如何获得选中文件的路径、页面上通过文件选择器获取文件夹的物理路径等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/10157685.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存