MFCEditBrowse控制访问路径名 [英] MFCEditBrowse Control accessing pathname
问题描述
如何在MFCEditBrowse控件中访问GetpathName。
我想将thar路径名传递给另一个控件。
谢谢。
How can I access GetpathName in MFCEditBrowse Control.
I want to pass thar pathname to another control.
Thank you.
推荐答案
当你使用 CMFCEditBrowseCtrl [ ^ ]类获得所选路径的方式与使用普通编辑控件的方式相同。即你使用GetWindowText()方法。
如您所知,可以使用三种模式创建控件:文件模式,文件夹模式和自定义模式。让我们把自定义模式放在一边,检查文件和文件夹模式。前者,根据MSDN:
When you use CMFCEditBrowseCtrl[^] class you get the selected path the same way you do with a normal edit control. I.e. you use GetWindowText() method.
As you know, the control can be created with three modes: file mode, folder mode and custom mode. Let''s put the custom mode aside and check file and folder modes. The former, according to MSDN:
当用户点击时,会显示标准文件选择对话框浏览按钮。
A standard file selection dialog box is displayed when the user clicks the browse button.
后者:
And the latter:
当用户点击浏览按钮时,会显示标准文件夹选择对话框。
A standard folder selection dialog box is displayed when the user clicks the browse button.
所以,如你所见,你可以使用文件夹和文件的控件。
你已经问过如何获取路径名。我假设您在文件模式下使用了控件,现在想要剥离文件部分并仅获取路径部分。您可以使用 PathRemoveFileSpec [ ^ ]功能。这是一个小例子:
So, as you see you can use the control for both Folders and Files.
You''ve asked how to get the path name. I assume you used your control in file mode and now want to strip the file part and get only the path part. You do this using PathRemoveFileSpec [^] function. Here is a small example:
CString strText;
m_edFile.GetWindowText(strText);
// strText now contains the full path of the selected file, i.e. c:\Temp\report.txt
::PathRemoveFileSpec(CStrBuf(strText, MAX_PATH));
// strText now contains the path of the selected file, i.e. c:\Temp\
您可以查看我的文章图像编目器 [ ^ ] ,我使用MFC功能包中的新控件
You can check my article Image Cataloguer[^], where I use the new controls from the MFC Feature pack
这篇关于MFCEditBrowse控制访问路径名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!