Treeview与特征遍历结合(使用CTreeCtrl的实例)

Treeview与特征遍历结合(使用CTreeCtrl的实例)

MFC DLL程序框架,无ug styler对话框,只贴重要代码段

TreeView.cpp

/////////////////////////////////////////////////////////////////////////////
// The one and only CTreeViewApp object

CTreeViewApp theApp;

extern “C” __declspec(dllexport) void ufusr(char *param, int *retcode, int rlen)
{

  int  response   = 0;
                int  error_code = 0;
  tag_t part;
  char  part_name[256 + 1];  

  UF_initialize();

  part = UF_PART_ask_display_part( );

  if(part != NULL_TAG)
  {
  UF_CALL(UF_PART_ask_part_name(part, part_name));

  AFX_MANAGE_STATE(AfxGetStaticModuleState());
  CTreeViewDlg dlg;
  dlg.m_PartName = part_name;
  dlg.m_PartTag = part;
  dlg.DoModal();  
                }
  else
  {
  uc1601(“请打开或新建一个prt文件!“,1);
  }
  UF_terminate();
}

TreeViewDlg.cpp

BOOL CTreeViewDlg::OnInitDialog()  
{
    CDialog::OnInitDialog();
    int feature_count = 0;
    int type;
    tag_t feature;
    char *feature_name = NULL;
    int   dialog_response = 0;

    /* 设定TreeView控件的显示参数*/
   DWORD dwStyle = GetWindowLong(m_ctrTree.m_hWnd,GWL_STYLE);
   dwStyle |= TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT;
   SetWindowLong(m_ctrTree.m_hWnd,GWL_STYLE,dwStyle);

   if (!UF_CALL(UF_initialize()))
  {
      /* 加入TreeView的根节点*/  
     m_hRoot = m_ctrTree.InsertItem(“features”);
     /* 定义遍历和显示的为当前part文件中的特征feature,同样可以定义遍历实体body等*/
     type = UF_feature_type;  
     feature = NULL_TAG;
    /* 传入一个NULL_TAG提示系统开始遍历*/
    UF_CALL(UF_OBJ_cycle_objs_in_part(m_PartTag, type, [$feature))]
    /* 遍历part中的所有特征feature,直到最后一个*/
   while ( feature != NULL_TAG )
   {
      /* 纪录特征个数*/
      feature_count++;

     if(feature != NULL_TAG)
    {
        /* 在TreeView控件中加入遍历到的特征名称,作为子节点*/
       UF_CALL(UF_MODL_ask_feat_name(feature,[$feature_name))]
       HTREEITEM hChild = m_ctrTree.InsertItem(feature_name,m_hRoot);
    }
    /* 遍历语句*/
    UF_CALL(UF_OBJ_cycle_objs_in_part(m_PartTag, type, [$feature))]
   }

     UF_CALL(UF_terminate());
}

    m_strFeatNum.Format(“%d”,feature_count);

    UpdateData(FALSE);  
    /* 打开TreeView的所有节点*/
   m_ctrTree.Expand(m_hRoot,TVE_EXPAND);

   return TRUE;  // return TRUE unless you set the focus to a control
        // EXCEPTION: OCX Property Pages should return FALSE
}

。。。。。。

void CTreeViewDlg::OnSelchangedTree2(NMHDR* pNMHDR, LRESULT* pResult)  
{
    NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
    TVITEM item = pNMTreeView->itemNew;
    char name[30+1];
    tag_t  set;
    CString ItemText;
   // TODO: Add your control notification handler code here
    if(item.hItem == m_hRoot)
  return;
    if (!UF_CALL(UF_initialize()))
    {
        UF_DISP_refresh();
       /* 取得当前所选TreeView控件的子节点*/
        HTREEITEM hTreeCurrent = m_ctrTree.GetSelectedItem();
        ItemText = m_ctrTree.GetItemText(hTreeCurrent);
        strcpy(name,ItemText.GetBuffer(ItemText.GetLength()));  
        /* 从名称得到feature的tag */
       UF_CALL(UF_MODL_ask_set_from_name (name, [$set))]  
       if(m_highlight != NULL_TAG)
      {
          UF_CALL(UF_DISP_set_highlight (m_highlight, 0));
      }
      /* 高亮显示所选feature,与UG的Feature列表相关联*/
     UF_CALL(UF_DISP_set_highlight (set, 1));
     m_highlight = set;
     UF_CALL(UF_terminate());
    }
     *pResult = 0;
}

您可以RSS 2.0订阅。 留言,或者引用 Trackback

留下评论

XHTML:您可以使用以下标签:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>