none
WindowActivate not called with maximizing window in 2007 RRS feed

  • Question

  •  

    My problem is exactly what it sounds like.  I have a com addin that puts up a menu on windowactivate.  In Word 2007, however, after minimizing the Word window, maximizing the same Word document does not initiate the WindowActivate event.  Any suggestions welcome! Thanks!
    Monday, September 17, 2007 9:18 PM

Answers

  • Hi Jennifer,

     

    Yes, I can reproduce your issue. But at this time, I cannot tell if this is designed to behave like this way. So maybe the most important thing at this stage is trying to find some walk around for that.

    Since the WindowsActivate does not work as our expected when minimize and restore it. We should find an event can be triggered in that situation instead, and add some logic test to make it work.  I use WindowsSize event to do that. I spent some time to write out the following code, wish it can help more or less. (I write it in a VSTO SE Add In project, not Com Add In)

    Code Snippet

            public bool flag = false;

     

            private void ThisAddIn_Startup(object sender, System.EventArgs e)

            {

                this.Application.WindowActivate += new Microsoft.Office.Interop.Word.ApplicationEvents4_WindowActivateEventHandler(Application_WindowActivate);

                this.Application.WindowSize += new Microsoft.Office.Interop.Word.ApplicationEvents4_WindowSizeEventHandler(Application_WindowSize);

            }

     

            void Application_WindowSize(Microsoft.Office.Interop.Word.Document Doc, Microsoft.Office.Interop.Word.Window Wn)

            {

                if (flag)

                {

                    Application_WindowActivate(Doc, Wn);

                }

                if (isMinimized(Wn))

                {

                    flag = true;

                }

            }

     

            void Application_WindowActivate(Microsoft.Office.Interop.Word.Document Doc, Microsoft.Office.Interop.Word.Window Wn)

            {

                MessageBox.Show("Activated!");

                flag = false;

            }

     

            bool isMinimized(Word.Window Wn)

            {

                if (23 == Wn.Height &&

                   120 == Wn.Width &&

                   -24000 == Wn.Left &&

                   -24000 == Wn.Top)

                {

                    return true;

                }

                else

                {

                    return false;

                }

            }

     

     

    Thanks

    Ji

     

    Thursday, September 20, 2007 7:59 AM
    Moderator