MFC属性页CPropertySheet的使用

1、修改或隐藏“帮助”“下一步”上一步“取消”四个按钮
自定义一个CPropSheet类继承CPropertySheet,并在初始化构造函数中进行修改

CPropSheet::CPropSheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
	:CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
	
}

CPropSheet::CPropSheet(LPCTSTR pszCaption,CWnd* pParentWnd, UINT iSelectPage)
	:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{

}

BOOL CPropSheet::OnInitDialog()
{
	BOOL bResult = CPropertySheet::OnInitDialog();

	// Hide Help buttons
	this->GetDlgItem(IDHELP)->ShowWindow(SW_HIDE);

	// 向左移动上一步按钮
	{
		CWnd *pWndBack =  this->GetDlgItem(ID_WIZBACK);
		CRect rectBack;
		pWndBack->GetWindowRect(&rectBack);//获得空间的绝对坐标
		ScreenToClient(&rectBack);//获得相对于主窗体的坐标
		CPoint& ptLT = rectBack.TopLeft();
		ptLT.x -= 40;
		CPoint& ptRB = rectBack.BottomRight();
		ptRB.x -= 40;
		pWndBack->MoveWindow(rectBack);
	}
	// 向右移动取消按钮
	{
		CWnd *pWndCancel =  this->GetDlgItem(IDCANCEL);
		CRect rect;
		pWndCancel->GetWindowRect(&rect);//获得空间的绝对坐标
		ScreenToClient(&rect);//获得相对于主窗体的坐标
		CPoint& ptLT = rect.TopLeft();
		ptLT.x += 30;
		CPoint& ptRB = rect.BottomRight();
		ptRB.x += 30;
		pWndCancel->MoveWindow(rect);
	}

	 //CWnd *pWndBack =  this->GetDlgItem(ID_WIZBACK);
	 //pWnd1->SetWindowText(_T("向上"));
	 //CWnd *pWnd1 =  this->GetDlgItem(ID_WIZNEXT);
	 //pWnd1->SetWindowText(_T("向下"));
	 //CWnd *pWnd2 =  this->GetDlgItem(ID_WIZFINISH);
	 //pWnd2->SetWindowText(_T("好了"));
	 //CWnd *pWnd4 =  this->GetDlgItem(IDCANCEL);
	 // pWnd4->SetWindowText(_T("取消了"));
	
	return bResult;
}

添加属性页

class CPropPage : public CPropertyPage
{
	DECLARE_DYNAMIC(CPropPage )

public:
	CPropPage (vector<CString> vecProName, CString strDefault, int nProType);
	virtual ~CPropPage ();

// 对话框数据
	enum { IDD = IDD_PROPPAGE_MANAGEPRO };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
	virtual BOOL OnInitDialog();

	DECLARE_MESSAGE_MAP()
public:
	virtual BOOL OnSetActive();
	virtual LRESULT OnWizardNext();
};

BOOL CPropPage ::OnInitDialog()
{
	CPropertyPage::OnInitDialog();

	// TODO:  在此添加额外的初始化
	for (auto proItor = m_vecProName.begin(); proItor != m_vecProName.end(); ++proItor)
	{
		m_cmbCopy.AddString(*proItor);
		m_cmbCur.AddString(*proItor);
	}

	if (!m_strDefault.IsEmpty())
	{
		int nFind = m_cmbCopy.FindStringExact(-1, m_strDefault);
		if( nFind <= 0 )
		{
			nFind = 0;
		}
		m_cmbCopy.SetCurSel(nFind);

		nFind = m_cmbCur.FindStringExact(-1, m_strDefault);
		if( nFind <= 0 )
		{
			nFind = 0;
		}
		m_cmbCur.SetCurSel(nFind);
	}
	else
	{
		m_cmbCopy.SetCurSel(0);
		m_cmbCur.SetCurSel(0);
	}

	return TRUE; 
}


BOOL CPropPage ::OnSetActive()
{
	// TODO: 在此添加专用代码和/或调用基类
	((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_NEXT);
	return CPropertyPage::OnSetActive();
}


LRESULT CPropPage ::OnWizardNext()
{
	// TODO: 在此添加专用代码和/或调用基类
		class vector_finder
		{
		public:
			vector_finder(const CString sName)
			{
				m_sName = sName;
			}

			bool operator ()(const CString &value)
			{
				return value == m_sName;
			}

		private:
			CString m_sName;                    
		};

		auto findItor = std::find_if(m_vecProName.begin(),m_vecProName.end(),vector_finder(m_strPlanName));
		if (findItor != m_vecProName.end())
		{
			MessageBox(_T("方案名称不能重复,请重新输入!"),_T("方案管理"),MB_ICONWARNING); 
			GetDlgItem(IDC_EDIT_NEWPRO)->SetFocus();
			return -1;
		}
	}
	else
	{
		m_cmbCur.GetWindowText(m_strPlanName);
	}
	return CPropertyPage::OnWizardNext();
}

	m_proPage = new CPropPage ();

	CPropSheet propSheet(_T("方案"));
	
	propSheet.AddPage(m_proPage );

你可能感兴趣的:(MFC,CPropertySheet,修改)