Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6545717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:37:13+00:00 2026-05-25T11:37:13+00:00

I have a managed syntax highlighter using the new VS extensibility API’s and it

  • 0

I have a managed syntax highlighter using the new VS extensibility API’s and it gives me an ITextBuffer, which is great.

In another part of my extension I am getting a DTE object and attaching to the active window changed event, which gives me an EnvDTE.Window object.

var dte = (EnvDTE.DTE)this.GetService(typeof(EnvDTE.DTE));
dte.Events.WindowEvents.WindowActivated += WindowEvents_WindowActivated;
// ...

private void WindowEvents_WindowActivated(EnvDTE.Window GotFocus, EnvDTE.Window LostFocus)
{
  // ???
  // Profit
}

I would like to get the ITextBuffer out of Window in this method. Can anyone tell me a straight forward way to do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:37:13+00:00Added an answer on May 25, 2026 at 11:37 am

    The solution I used was to get the Windows path then use it in conjuction with IVsEditorAdaptersFactoryService and VsShellUtilities.

    var openWindowPath = Path.Combine(window.Document.Path, window.Document.Name);
    var buffer = GetBufferAt(openWindowPath);
    

    and

    internal ITextBuffer GetBufferAt(string filePath)
    {
      var componentModel = (IComponentModel)GetService(typeof(SComponentModel));
      var editorAdapterFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>();
      var serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(MetaSharpPackage.OleServiceProvider);
    
      IVsUIHierarchy uiHierarchy;
      uint itemID;
      IVsWindowFrame windowFrame;
      if (VsShellUtilities.IsDocumentOpen(
        serviceProvider,
        filePath,
        Guid.Empty,
        out uiHierarchy,
        out itemID,
        out windowFrame))
      {
        IVsTextView view = VsShellUtilities.GetTextView(windowFrame);
        IVsTextLines lines;
        if (view.GetBuffer(out lines) == 0)
        {
          var buffer = lines as IVsTextBuffer;
          if (buffer != null)
            return editorAdapterFactoryService.GetDataBuffer(buffer);
        }
      }
    
      return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an old project written using Managed C++ syntax. I would like to
I have managed to create a custom action in C# using MakeSfxCA which is
If I have managed to locate and verify the existence of a file using
I have an assembly which I have managed to make visible to VB6 and
I've deconstructed a standard WPF button using Blend and have managed to create a
I am new to .net . I have a managed C++ library. It looks
I have a website solution that used to be managed using VS2008. Now since
I have managed to set up Cassandra + Thrift and the Python wrapper for
I have managed to get a cron job to run a rake task by
So far I have managed to write some code that should print the source

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.