Results 1 to 5 of 5

Thread: Programatically Clear the output window

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    Programatically Clear the output window

    Hi,
    Is there a way to programatically clear the Output window of the IDE? Tried searching for it on the Internet but to no avail.
    Thanks.
    BTW, I'm still in VS.Net 2003.

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Programatically Clear the output window

    You would have to use the EnvDTE classes and namespace, by adding a reference to it. This is an addin that lets you control the IDE objects (I believe). Searched around and found a link below of an example of using it to get a handle on the output window, and once you do that, there is an OutPutWindow.ActivePane.Clear() method that you can run in order to clear it...

    http://www.codeproject.com/macro/VSReadFileOutWin.asp

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    Re: Programatically Clear the output window

    Thanks gigemboy, seems it might solve my problem. So far I've tried this (but no success as yet)
    VB Code:
    1. Dim dte As EnvDTE.DTE
    2. dte = System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE")
    3. Dim mwin As Window = dte.Windows.Item(EnvDTE.Constants.vsext_wk_OutputWindow) '  .vsWindowKindOutput)
    4. Dim ow As OutputWindow = mwin.Object
    5. Dim tmp As OutputWindowPane
    6. For Each tmp In ow.OutputWindowPanes
    7.     tmp.Clear()
    8. Next
    It runs fine but doesn't clear out the Output window. Seems to be a minor flaw. Will see it later (need to get onto another task for now.)
    Last edited by rjv_rnjn; Aug 22nd, 2006 at 04:00 PM. Reason: format of code.

  4. #4
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Programatically Clear the output window

    I worked with it a little and was able to do it. The GetActiveObject call needs to change due to you using 2003, and I think that code was for the original 2002. You just need to change the object to "VisualStudio.DTE.7.1", and it should work, with just calling the .ActivePane.Clear method of the "ow" outputwindow object, like below:
    VB Code:
    1. '***Note - this code requires option strict to be off, otherwise you will have to cast the objects
    2.         Dim dte As EnvDTE.DTE
    3.         'below uses the 7.1 DTE for 2003
    4.         dte = System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.7.1")
    5.         Dim mwin As Window = dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
    6.         Dim ow As OutputWindow = mwin.Object
    7.         ow.ActivePane.Clear()
    It was tested in 2003, and cleared the output window fine...

    This code can be used in 2005 by changing the DTE to "VisualStudio.DTE.8.0"
    Last edited by gigemboy; Aug 22nd, 2006 at 05:43 PM.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    Resolved Re: Programatically Clear the output window

    Thanks gigemboy, that solved it. And the loop was one of the trials after the initial ow.ActivePane.Clear() was not working. Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width