基础类1:
class CBaseEditor
{
public:
bool CBaseEditor::ImportTemplate(CWnd* pParent)
{
CFileDialog dlgImport(TRUE,
_T(".XSL"), _T(""),
OFN_ALLOWMULTISELECT | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY,
_T("FilterText"), pParent);
}
}
基础类2:
class CResizingDialog : public CDialogEx
{
}
对话框类,从两个基础派生:
class CFieldServiceGroupReportDlg : public CResizingDialog, public CBaseEditor
{
private:
void SuneFunc()
{
ImportTemplate(this);
}
}
我的
ImportTemplate
函数,是否可以让调用者访问“this”而不必传递“this”?
根据提供的评论,我得出的结论是,最好的办法是更改我现有的构造函数(字段类已被重命名):
CPublishersDatabaseViewerDlg::CPublishersDatabaseViewerDlg(CWnd* pParent /*=nullptr*/)
: CResizingDialog(L"GroupsReport", IDD_DIALOG_PUBLISHERS_DATABASE_VIEWER, pParent)
, m_strPreviewXSL(L"")
{
m_strPreviewXSL = theApp.GetStringSetting(L"Options", L"PublisherDB_Style", L"PublisherDB--Field Service Groups");
}
根据设计,对话框类接受父级。同样,我应该改变
CBaseEditor
以某种方式接受合适的父母。这样我就不需要一直通过它了。这是我的基本构造函数:
CResizingDialog::CResizingDialog(const CString& strWindowID, UINT nIDTemplate, CWnd* pParent /* nullptr */, bool bOnlyStorePosition /* false */)
: CDialogEx(nIDTemplate, pParent)
, m_bDoNotShowResizeIcon(false)
, m_bOnlyStorePosition(bOnlyStorePosition)
, m_bLimitToHorizontalResizing(false)
, m_strWindowID(strWindowID)
{
m_rcInit.SetRect(0, 0, 0, 0);
}
CBaseEditor::CBaseEditor() noexcept(false)
{
Init();
}