CProperySheet使用

来源:互联网 发布:淘宝不能打卡了 编辑:程序博客网 时间:2024/06/06 03:53

自己在做一个项目 需要使用到CProperySheet 

记得当初写框架的时候用过CProperySheet

现在都忘光了


刚好在弄界面美化 就复习复习了


第一步添加一个CPropertySheet变量

建议重写CPropertySheet

CMyPropertySheet m_sheet;

第二步 创建新的对话框资源 对话框资源的基类为CPropertyPage

// DlgFile.cpp : 实现文件//#include "stdafx.h"#include "MFC_PropertySheet_CTRL.h"#include "DlgFile.h"#include "afxdialogex.h"// CDlgFile 对话框IMPLEMENT_DYNAMIC(CDlgFile, CPropertyPage)CDlgFile::CDlgFile(): CPropertyPage(CDlgFile::IDD){}CDlgFile::~CDlgFile(){}void CDlgFile::DoDataExchange(CDataExchange* pDX){CPropertyPage::DoDataExchange(pDX);}BEGIN_MESSAGE_MAP(CDlgFile, CPropertyPage)ON_BN_CLICKED(IDOK, &CDlgFile::OnBnClickedOk)END_MESSAGE_MAP()// CDlgFile 消息处理程序void CDlgFile::OnBnClickedOk(){AfxMessageBox(L"File!\n");}

// DlgProcess.cpp : 实现文件//#include "stdafx.h"#include "MFC_PropertySheet_CTRL.h"#include "DlgProcess.h"#include "afxdialogex.h"// CDlgProcess 对话框IMPLEMENT_DYNAMIC(CDlgProcess, CPropertyPage)CDlgProcess::CDlgProcess(): CPropertyPage(CDlgProcess::IDD){}CDlgProcess::~CDlgProcess(){}void CDlgProcess::DoDataExchange(CDataExchange* pDX){CPropertyPage::DoDataExchange(pDX);}BEGIN_MESSAGE_MAP(CDlgProcess, CPropertyPage)ON_BN_CLICKED(IDOK, &CDlgProcess::OnBnClickedOk)ON_WM_SIZE()ON_WM_SHOWWINDOW()END_MESSAGE_MAP()// CDlgProcess 消息处理程序void CDlgProcess::OnBnClickedOk(){AfxMessageBox(L"Process!\n");}void CDlgProcess::OnSize(UINT nType, int cx, int cy){CPropertyPage::OnSize(nType, cx, cy);// TODO: 在此处添加消息处理程序代码}BOOL CDlgProcess::OnInitDialog(){CPropertyPage::OnInitDialog();return TRUE;}/*void CtestDlg::OnSize(UINT nType, int cx, int cy){CDialogEx::OnSize(nType, cx, cy);// TODO: 在此处添加消息处理程序代码// 子窗口随着父窗口变大变小if(m_ctrWeb.GetSafeHwnd()){m_ctrWeb.MoveWindow(0,0,cx,cy);}}*/void CDlgProcess::OnShowWindow(BOOL bShow, UINT nStatus){CPropertyPage::OnShowWindow(bShow, nStatus);}


第三步 在主窗口中添加对话框成员

CDlgFile m_DlgFile;
CDlgProcess m_DlgProcess;


第四步 在主窗口初始化函数中将对话框加入sheet 并创建sheet

this->m_sheet.AddPage(&m_DlgProcess);this->m_sheet.AddPage(&m_DlgFile);m_sheet.Create(this, WS_CHILD | WS_VISIBLE | WS_BORDER, WS_EX_CONTROLPARENT);


这里有点蛋疼的是主窗口跟sheet的大小不一致

我就写了这么几句 让其大小一致

CRect rect;m_sheet.GetWindowRect(&rect);CRect DlgRect;GetWindowRect(&DlgRect);POINT point;  point = DlgRect.TopLeft(); MoveWindow(point.x, point.y, rect.Width()+17, rect.Height()+40,TRUE); 

/*void CtestDlg::OnSize(UINT nType, int cx, int cy){CDialogEx::OnSize(nType, cx, cy);// TODO: 在此处添加消息处理程序代码// 子窗口随着父窗口变大变小if(m_ctrWeb.GetSafeHwnd()){m_ctrWeb.MoveWindow(0,0,cx,cy);}}*/


0 0
原创粉丝点击