Visual studio automation: Enumerate opened windows

2019-08-07 09:11发布

How to enumerate opened code windows (i.e. those windows where you edit documents) upon solution loading using macros?

As you probably know, MSVS remembers opened documents, i.e. when you load solution, IDE will load previously opened files. What I want to do is to perform some actions with those windows upon solution loading.

I tried to access these windows in SolutionEvents_Opened handler. But have no luck - it seems that mentioned windows are not available at the moment SolutionEvents_Opened invoked. DTE.Documents is empty and DTE.Windows.Items doesn't contain them.

I need some code like:

Private Sub SolutionEvents_Opened() Handles SolutionEvents.Opened
   Dim window As Window = DTE.Documents.Item(?).Windows // one of the opened windows
   ...
End Sub

1条回答
神经病院院长
2楼-- · 2019-08-07 09:56

One way I've found to enumerate the window is on DocumentEvents.DocumentOpened event, but it fires it always and not only during the loading of a solution. It does not seem that the SolutionEvents.Opened gets fired at all in my experience otherwise a static variable could be changed in it.

This might help explain it though.

查看更多
登录 后发表回答