创建MFC对话框让用户选择文件路径 您所在的位置:网站首页 getoptions 创建MFC对话框让用户选择文件路径

创建MFC对话框让用户选择文件路径

2023-03-27 06:17| 来源: 网络整理| 查看: 265

正如标题所说,我试图创建MFC基于对话框的应用程序,让用户选择文件目标文件夹。创建MFC对话框让用户选择文件路径

我正在使用CMFCShellTreeCtrl来做这件事。但是,不知何故,只有一个根目录是桌面。我想看到像我的电脑,C盘等所有项目

你能告诉我什么是错的,如何解决它。谢谢。

enter image description here

编辑:对不起,我忘了张贴我的代码。 (很简单的浏览对话框)

// BrowseDlg.cpp : implementation file // #include "stdafx.h" #include "MFC Grab to FTP.h" #include "BrowseDlg.h" #include "afxdialogex.h" // CBrowseDlg dialog IMPLEMENT_DYNAMIC(CBrowseDlg, CDialog) CBrowseDlg::CBrowseDlg(CWnd* pParent /*=NULL*/) : CDialog(CBrowseDlg::IDD, pParent) { } CBrowseDlg::~CBrowseDlg() { } void CBrowseDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_PATH, m_PathTree); } BEGIN_MESSAGE_MAP(CBrowseDlg, CDialog) ON_NOTIFY(TVN_SELCHANGED, IDC_PATH, &CBrowseDlg::OnTvnSelchangedMfcshelltree1) ON_BN_CLICKED(IDOK, &CBrowseDlg::OnBnClickedOk) END_MESSAGE_MAP() // CBrowseDlg message handlers BOOL CBrowseDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { BOOL bNameValid; CString strAboutMenu; bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); ASSERT(bNameValid); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog m_PathTree.Expand(m_PathTree.GetRootItem(),TVE_EXPAND); return TRUE; // return TRUE unless you set the focus to a control } void CBrowseDlg::OnTvnSelchangedMfcshelltree1(NMHDR *pNMHDR, LRESULT *pResult) { LPNMTREEVIEW pNMTreeView = reinterpret_cast(pNMHDR); // TODO: Add your control notification handler code here *pResult = 0; } void CBrowseDlg::OnBnClickedOk() { m_PathTree.GetItemPath(path,m_PathTree.GetSelectedItem()); // TODO: Add your control notification handler code here CDialog::OnOK(); }

//

#pragma once #include "afxshelltreectrl.h" // CBrowseDlg dialog // header file class CBrowseDlg : public CDialog { DECLARE_DYNAMIC(CBrowseDlg) public: CBrowseDlg(CWnd* pParent = NULL); // standard constructor virtual ~CBrowseDlg(); // Dialog Data enum { IDD = IDD_BROWSER }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support DECLARE_MESSAGE_MAP() public: afx_msg void OnTvnSelchangedMfcshelltree1(NMHDR *pNMHDR, LRESULT *pResult); CString path; CMFCShellTreeCtrl m_PathTree; afx_msg void OnBnClickedOk(); virtual BOOL OnInitDialog(); };

来源

2015-11-26 XiaoShun Tan

+0

你应该向我们展示你的代码开始, –



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有