代码之家  ›  专栏  ›  技术社区  ›  Daniel

VisualStudio插件开发——在C++项目中获取目录路径

  •  1
  • Daniel  · 技术社区  · 14 年前

    VSNewFile . 所以它只是一个简单的扩展,它提供了一个更快的方法来创建新文件。VSNewFile的问题是它不适用于C++项目,我需要它。

    我的问题是:

    (string)((ProjectItem)parent).Properties.Item("FullPath").Value;

    虽然这是在C项目中工作,但它不是在C++项目中。在C++项目中 selectedItem.Project selectedItem.ProjectItem 两者都是 null 当我选择一个目录时。

    重要提示: 我不是说过滤器!我是说真正的目录。


    谢谢

    1 回复  |  直到 14 年前
        1
  •  0
  •   Daniel    14 年前

    也许这会帮助其他有同样问题的人:
    http://social.msdn.microsoft.com/forums/en-US/vsx/thread/bd738463-ba24-4880-beea-f3ec110d981e

    // Subscribe to the SVsShellMonitorSelection service somewhere:  
    public void mySetupMethod()  
    {  
         IVsMonitorSelection monitorSelection = 
         (IVsMonitorSelection)Package.GetGlobalService(
         typeof(SVsShellMonitorSelection));     
         monitorSelection.AdviseSelectionEvents(this, out cookie);    
    }  
    
    // This class (as used in AdviseSelection) must implement the IVsSelectionEvents interface  
    // To get the folder path use the following  
    public int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld,   
      IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld,   
      IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)  
    {  
      string fullPath;  
      // Get the full path
      pHierNew.GetCanonicalName(itemidNew, out fullPath);  
    
      // Do something with the path...  
      return VSConstants.S_OK;  
    }