关于属性页和属性单的应用总结
1、属性页(CPropertyPage)中获取
(1) 程序主框架指针:CMainFrame* pMainFrame=(CMainFrame*)AfxGetMainWnd();
(2) 程序子框架指针:CChildFrame* pframe=(CChildFrame*)((CMainFrame*)AfxGetMainWnd())->GetActiveFrame();
(3) 程序活动文档指针:CEMCDoc* m_pDoc=(CEMCDoc*)pframe->GetActiveDocument();//获取活动的文档
(4) 属性单(CPropertySheet)指针:CMyPropertySheet* pSheet=(CMyPropertySheet*)this->GetParent();// 获取CMyPropertySheet指针
(5) 程序活动视图指针:CEMCView* pView=(CEMCView*)pframe->GetActiveView();// 获取活动视图
2、在属性单(CPropertySheet)单击OK按钮后,程序框架将逐个遍历加载的CPropertyPage(从GetPage(0)~GetPage(N-1)),查询是否
有CPropertyPage重载了OnOK(),若有则执行重载的代码,否则执行默认的CPropertyPage::OnOK()。
3、CPropertySheet和加载的CPropertyPage通信,可以在CPropertySheet中定义
CPPageContentMode* pCM=(CPPageContentMode*)this->GetPage(0);
然后利用pCM操作CPPageContentMode中的成员变量。
也可以在CPropertyPage中获取CPropertySheet的指针。
4、两个或多个加载的CPropertyPage之间通信,可以借助于CPropertySheet实现。
5、对CPropertySheet标准按钮的操作
(1)更改标准按钮的标题:
CWnd* pWnd=GetDlgItem(IDOK);
pWnd->SetWindowTextW(_T("开始"));
(2)去掉“应用”按钮:
pWnd=GetDlgItem(ID_APPLY_NOW);
pWnd->ShowWindow(FALSE);
(3)移动标准按钮至对话框中间
CPropertyPage*pPage;
pPage=this->GetPage(0);
//CRectrectPage;
pPage->GetWindowRect(&rectPage);
CWnd*pWndOK=GetDlgItem(IDOK);
CWnd*pWndCancel=GetDlgItem(IDCANCEL);
CRectrectOK,rectCancel;
pWndOK->GetWindowRect(&rectOK);
pWndCancel->GetWindowRect(&rectCancel);
intBtnCenter=(rectCancel.right-rectOK.left)/2;//OK和CANCEL按钮中轴线
intPageCenter=(rectPage.right-rectPage.left)/2;//属性单的中轴线
intdist=PageCenter-BtnCenter;
rectOK.left+=dist;
rectOK.right+=dist;
rectCancel.left+=dist;
rectCancel.right+=dist;
ScreenToClient(&rectOK);
ScreenToClient(&rectCancel);
pWndOK->MoveWindow(&rectOK);
pWndCancel->MoveWindow(&rectCancel);
本文总结了属性页(CPropertyPage)与属性单(CPropertySheet)在MFC中的使用方法,包括如何获取主框架、子框架、活动文档及视图的指针,属性页与属性单间的通信方式,以及如何定制属性单的标准按钮。

被折叠的 条评论
为什么被折叠?



