4

アクティブなドキュメントをパラメーターとして受け取るアドインを作成しました。そのため、アクティブなドキュメントが変更されるたびに、それを知る必要があります。そのために、DTE2 オブジェクトの「Events.DocumentEvents.DocumentOpened」イベントを使用したいと考えました。しかし問題は、アクティブなドキュメントを変更してもイベントが発生しないことです。

コード スニペットは次のとおりです。

        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
    {
        _applicationObject = (DTE2)application;

        _applicationObject.Events.DocumentEvents.DocumentOpened += new _dispDocumentEvents_DocumentOpenedEventHandler(DocumentEvents_DocumentOpened);

         ... 
    }

        void DocumentEvents_DocumentOpened(Document Document)
    {
        MessageBox.Show("Not called");
    }

DocumentEvents も試しましたが、成功しませんでした。何か案は?

4

1 に答える 1

3

間違ったイベントに焦点を合わせていたことに気付きました。それが原因で、イベントが発生しませんでした。以下のコードで、私が意図したものを手に入れました。そのため、DocumentEvents の代わりに WindowEvents を使用する必要がありました。

          ....            

   _applicationObject.Events.WindowEvents.WindowActivated += new _dispWindowEvents_WindowActivatedEventHandler(WindowEvents_WindowActivated);

    }

    void WindowEvents_WindowActivated(Window GotFocus, Window LostFocus)
    {
        if (ucCAST != null && GotFocus.Document != null)
            ((CAST)ucCAST).refreshCode(GotFocus.Document.Name);
    }
于 2011-03-03T13:34:26.007 に答える