MFC Feature Pack CMFCPropertyGridCtrl控件的应用

 CMFCPropertyGridCtrl m_wndPropList;

CMFCPropertyGridProperty* pGroup11;
 CMFCPropertyGridProperty* pGroup12;
 CMFCPropertyGridProperty* pGroup21;
 //CMFCPropertyGridProperty pGroup22;
 CMFCPropertyGridProperty* pGroup3;

 

 

BOOL CProcessPage2::OnInitDialog()
  {
   CMFCPropertyPage::OnInitDialog();

   
   //读入默认参数文件里的参数项
   if (!ReadCardFile())
   {
    AfxMessageBox(_T("读入默认参数文件失败!"));
     return false;
   }
   

   CRect rectPropList;
   m_wndPropListLocation.GetClientRect(&rectPropList);
   m_wndPropListLocation.MapWindowPoints(this, &rectPropList);

   m_wndPropList.Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER, rectPropList, this, (UINT)-1);

   m_wndPropList.EnableHeaderCtrl(m_bHeader, _T("属性"),_T("取值"));
   m_wndPropList.EnableDescriptionArea(m_bDescrArea);
   m_wndPropList.SetVSDotNetLook(m_bDotNetLook);
   m_wndPropList.MarkModifiedProperties(m_bMarkChanged);

   m_wndPropList.SetAlphabeticMode(!m_bPropListCategorized);
   m_wndPropList.SetShowDragContext(m_bShowDragContext);


  //曲线重定向设置   

  

  pGroup11 = new CMFCPropertyGridProperty(_T("输入重定向"));
  pGroup12 = new CMFCPropertyGridProperty(_T("输出重定向"));
  //输入重定向
  for (int i=0;i<CurveInNum;i++)
  {
   pGroup11->AddSubItem(new CMFCPropertyGridProperty(strCurveInRunTimeName[i], (COleVariant)strCurveInCifFileName[i], _T("This is a description"),i));
  }
  //apGroup1->AddSubItem(pGroup11);
  
  
  //输出重定向
  for (int i=0;i<CurveOutNum;i++)
  {
   pGroup12->AddSubItem(new CMFCPropertyGridProperty(strCurveOutRunTimeName[i], (COleVariant)strCurveOutCifFileName[i], _T("This is a description"),i));
  }
   //apGroup1->AddSubItem(pGroup12); 
   //apGroup1->Expand(FALSE);
   m_wndPropList.AddProperty(pGroup11);
   m_wndPropList.AddProperty(pGroup12);


   //深度段
   
   pGroup21 = new CMFCPropertyGridProperty(_T("处理深度段"));

   pGroup21->AddSubItem(new CMFCPropertyGridProperty(_T("起始深度"),strStartDepth, _T("处理起始深度")));
   pGroup21->AddSubItem(new CMFCPropertyGridProperty(_T("结束深度"), strEndDepth, _T("处理结束深度")));
     
   m_wndPropList.AddProperty(pGroup21);

   
   //参数选择   

   pGroup3 = new CMFCPropertyGridProperty(_T("处理参数"));
   for (int i=0;i<ParameterNum;i++)
   {
    pGroup3->AddSubItem(new CMFCPropertyGridProperty(strParameterName[i], (COleVariant)strParameterValue[i], _T("This is a description"),i));
   }
     m_wndPropList.AddProperty(pGroup3);

   return TRUE;  // return TRUE unless you set the focus to a control

  }

BOOL CProcessPage2::WriteNewCardFile()
 {

  
  

  CString   defaultCardFilePath;
  CProcessPropSheet* sheet = (CProcessPropSheet*) GetParent( ); //获得父对像的指针,通过该指针获得父对像的成员变量值。
  

  defaultCardFilePath=sheet->m_DefaultParmaFilePath;

  CString NewCardFilePath;
  NewCardFilePath= defaultCardFilePath;
  
  //准备要写入的参数
  //先清空变量
  for (int i=0;i<CurveInNum;i++)
  {
  strCurveInCifFileName[i].Empty();

  }

  for (int i=0;i<CurveOutNum;i++)
  {
   strCurveOutCifFileName[i].Empty();
  }

  for (int i=0;i<ParameterNum;i++)
  {
   strParameterValue[i].Empty();
  }

  //
  CMFCPropertyGridProperty *pProperty;//定义一个指向子项的指针

  //输入重定向
  for (int i=0;i<CurveInNum;i++)
  {
   pProperty=pGroup11->GetSubItem(i) ;//获得子项的指针
   const COleVariant &strValue=pProperty->GetValue();//获得子项值
   strCurveInCifFileName[i]=(CString)strValue;
  }

  //输出重定向
  for (int i=0;i<CurveOutNum;i++)
  {
   pProperty=pGroup12->GetSubItem(i) ;//获得子项的指针
   const COleVariant &strValue=pProperty->GetValue();//获得子项值
   strCurveOutCifFileName[i]=(CString)strValue;
  }
  
  //深度段

  //始深
  pProperty=pGroup21->GetSubItem(0) ;//获得子项的指针
  const COleVariant &strValue=pProperty->GetValue();//获得子项值
   strStartDepth =(CString)strValue;

   //终深
   pProperty=pGroup21->GetSubItem(1) ;//获得子项的指针
   strEndDepth=(CString)pProperty->GetValue();//获得子项值
  
 
  //参数选择 
  for (int i=0;i<ParameterNum;i++)
  {

   pProperty=pGroup3->GetSubItem(i) ;//获得子项的指针
   const COleVariant &strValue=pProperty->GetValue();//获得子项值
   strParameterValue[i]=(CString)strValue;

  }


  //下面代码是写新的参数文件
  NewCardFilePath.Replace(_T(".inp"),_T(".new.inp"));//将默认的参数文件拷贝为.new.inp文件应用为当前参数文件

  if(!(CopyFile(defaultCardFilePath,NewCardFilePath,FALSE)))
  {
   AfxMessageBox(_T("备份参数文件失败"));
   return false;
  }

  //用CSTdioFile按行写
  CStdioFile OutFile;
  //打开文件
  if(!OutFile.Open(NewCardFilePath, CFile::modeCreate|CFile::modeWrite| CFile::typeText))
  {
   TRACE(_T("写入参数文件错误/n"));
   return false;
  }

  //逐行写入字符串 
  CString szLine=_T("");

  //连接输入重定向字符
  if (CurveInNum!=NULL)
  {
   for (int i=0;i<CurveInNum;i++)
   {
    szLine+=strCurveInRunTimeName[i];
    szLine+=_T('<');
    if (i<CurveInNum-1)
    {
     szLine+=strCurveInCifFileName[i];
     szLine+=_T(',');
    }
    else
     szLine+=strCurveInCifFileName[i];

   }

   szLine+=_T("/n");
  }
  
  

  //连接输出重定向字符

  if (CurveOutNum!=NULL)
  {
   for (int i=0;i<CurveOutNum;i++)
   {
    szLine+=strCurveOutRunTimeName[i];
    szLine+=_T('>');
    if(i<CurveOutNum-1)
    {
     szLine+=strCurveOutCifFileName[i];
     szLine+=_T(',');

    }
    else
     szLine+=strCurveOutCifFileName[i];

   }

   szLine+=_T("/n");
  }
 
  

  //连接深度行字符串
  
  szLine+=strStartDepth;
  szLine+=_T(',');
  szLine+=strEndDepth;

        szLine+=_T("/n");


  //连接参数字符串 
  
     if (ParameterNum!=NULL)
     {
      for (int i=0;i<ParameterNum;i++)
      {

       szLine+=strParameterName[i];
       szLine+=_T('=');
       if (i<ParameterNum-1)
       {
        szLine+=strParameterValue[i];
        szLine+=_T(',');
       }
       else
        szLine+=strParameterValue[i];


      }

      szLine+=_T("/nEND/n");
     }
  

  OutFile.WriteString(szLine);//写入字符串  

   OutFile.Close();

   sheet->m_SheetPage1->m_CardFilePath=NewCardFilePath;
   sheet->m_SheetPage1->UpdateData(FALSE);

   return true;
  }

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值