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;
  }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章