[英]MFC how to get path from MFCEditBrowseControl and copy it to the edit control?
I am intended to get path from CMFCEditBrowseControl and copy it to the CEdit edit box. 我打算从CMFCEditBrowseControl获取路径并将其复制到CEdit编辑框。 I have done the following which is getting caption of a dialog not path, please let me know how to get the path using MFC and c++ to save particular file to the destination?
我已经完成了以下操作获取对话框的标题而不是路径,请让我知道如何使用MFC和c ++将特定文件保存到目标?
CString strTextone;
(CMFCEditBrowseCtrl *) GetDlgItem(IDC_MFCEDITBROWSE1)-&inFileCtrl;
GetWindowText(strTextone);
(CEdit *) GetDlgItem(IDC_EDIT2)-&e_Edit;
SetWindowText(strTextone);
This is my code. 这是我的代码。 I am beginner to this, so please correct my mistakes!
我是初学者,所以请纠正我的错误!
You can get a pointer to CWnd
: 你可以得到一个指向
CWnd
的指针:
CString strTextone;
CWnd* ptr = GetDlgItem(IDC_MFCEDITBROWSE1);
ptr->GetWindowText(strTextone);
ptr->SetWindowText(_T("something else"));
This will work because SetWindowText/GetWindowText
are CWnd
methods. 这将起作用,因为
SetWindowText/GetWindowText
是CWnd
方法。 You could use CMFCEditBrowseCtrl*
cast but that's not always safe. 您可以使用
CMFCEditBrowseCtrl*
cast但这并不总是安全的。 The preferred method is to declare a class member: 首选方法是声明一个类成员:
CMFCEditBrowseCtrl mfc_editbrowse;
And add subclass in DoDataExchange
. 并在
DoDataExchange
添加子类。
void CMyDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_MFCEDITBROWSE1, mfc_editbrowse);
}
Then you can use m_editbrowse
to access CMFCEditBrowseCtrl
methods. 然后,您可以使用
m_editbrowse
访问CMFCEditBrowseCtrl
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.