1、在BCGPFormView中放入一个属性页,并且标签放在左边。具体做法如下:
首先,从新建一个单文档应用程序BCGPropShowChartView,view类派生于CBCGPFormView,然后添加两个PropPage对话框资源,并且对对话框资源添加类,CPropOne,和CPropTwo,在头文件和CPP文件中修改基类为CBCGPPropertyPage,这样属性页就暂时放在一边。
在BCGPropShowChartView的头文件中添加如下:
private:
CBCGPPropertySheet m_Sheet;
CPropOne m_PropOne;
CPropTwo m_PropTwo;
CBCGPFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
m_Sheet.SetLook(CBCGPPropertySheet::PropSheetLook_List);
m_Sheet.AddPage(&m_PropOne);
m_Sheet.AddPage(&m_PropTwo);
//m_Sheet.EnableVisualManagerStyle();
m_Sheet.Create(this, WS_CHILD|WS_VISIBLE|WS_TABSTOP,0);
CRect rect;
GetClientRect(&rect);
m_Sheet.MoveWindow(rect);
运行程序如下所示:
程序运行出现问题,右边会被遮挡住,经过仔细的发现在movewindow下面加上这句代码就可以了:
m_Sheet.SetActivePage(m_Sheet.GetPage(0));
现在要做的就是让屏幕尺寸缩放的时候page页跟着缩放,响应onsize函数,在size函数里添加如下代码:
CRect rect;
GetClientRect(&rect);
if(m_Sheet.GetSafeHwnd()!=NULL){
m_Sheet.MoveWindow(rect);
m_Sheet.SetActivePage(m_Sheet.GetActivePage());
}
m_Sheet.SetActivePage(m_Sheet.GetActivePage());
加上这句就强制刷新属性页,不会出现显示不全的问题。
窗口可以随意拖动,并且属性页随着窗口大小缩放而缩放。
2、在属性页one上添加图表,并且可以等比例缩放
首先在page的资源对话框中添加一个静态控件ID为IDC_PROP_SHOW,为该控件添加变量,m_PropShow,在属性页ONE的头文件中修改变量类型为如下:
CBCGPChartCtrl m_PropShow;
同时为属性页添加OnInitDialog函数,在OnInitDialog函数中添加如下代码:
CBCGPPropertyPage::OnInitDialog();
CWnd *pWnd = GetDlgItem(IDC_PROP_SHOW);
pWnd->SetWindowPos(this,0,0,100,100,SWP_NOZORDER | SWP_NOACTIVATE);
CBCGPChartVisualObject* pChart = m_PropShow.GetChart();
ASSERT_VALID(pChart);
BCGPChartType type = BCGP_CT_STACKED;
pChart->SetChartType(BCGPChartLine, type);
pChart->SetChartTitle(_T("Furniture Sales"));
CBCGPChartSeries* pSeries1 = pChart->CreateSeries(_T("Tables"));
CBCGPChartSeries* pSeries2 = pChart->CreateSeries(_T("Chairs"));
CBCGPChartSeries* pSeries3 = pChart->CreateSeries(_T("Cabinets"));
pSeries1->AddDataPoint(_T("2011"), 5.);
pSeries1->AddDataPoint(_T("2012"), 8);
pSeries1->AddDataPoint(_T("2013"), 12.);
pSeries1->AddDataPoint(_T("2014"), 13.);
pSeries1->AddDataPoint(_T("2015"), 15.);
pSeries2->AddDataPoint(9.);
pSeries2->AddDataPoint(15.);
pSeries2->AddDataPoint(19.);
pSeries2->AddDataPoint(21.);
pSeries2->AddDataPoint(23.);
pSeries3->AddDataPoint(2.);
pSeries3->AddDataPoint(3.);
pSeries3->AddDataPoint(16.);
pSeries3->AddDataPoint(19.);
pSeries3->AddDataPoint(19.);
CBCGPChartAxis* pYAxis = pChart->GetChartAxis(BCGP_CHART_Y_PRIMARY_AXIS);
ASSERT_VALID(pYAxis);
pYAxis->m_majorTickMarkType = CBCGPChartAxis::TMT_CROSS;
pYAxis->m_minorTickMarkType = CBCGPChartAxis::TMT_CROSS;
CBCGPChartAxis* pXAxis = pChart->GetChartAxis(BCGP_CHART_X_PRIMARY_AXIS);
ASSERT_VALID(pXAxis);
pXAxis->m_majorTickMarkType = CBCGPChartAxis::TMT_CROSS;
pXAxis->m_minorTickMarkType = CBCGPChartAxis::TMT_CROSS;
return TRUE;
并且添加OnSize函数添加如下代码:
CRect rect;
GetClientRect(&rect);
CWnd *pWnd = GetDlgItem(IDC_PROP_SHOW);
pWnd->SetWindowPos(this,0,0,rect.Width(),rect.Height(),SWP_NOZORDER | SWP_NOACTIVATE);
当窗口尺寸变化时,效果如下图: