ACPAddIn.ThisAddIn.Application_WindowActivate C# (CSharp) Method

Application_WindowActivate() private method

private Application_WindowActivate ( Microsoft.Office.Interop.Word Doc, Microsoft.Office.Interop.Word Wn ) : void
Doc Microsoft.Office.Interop.Word
Wn Microsoft.Office.Interop.Word
return void
        private void Application_WindowActivate(Word.Document Doc, Word.Window Wn)
        {
            // for User Testing
            endSwitchTime = DateTime.Now;
            appendSwitchWindowString();

            // Track the handle ID for the text editor (Microsoft Word)
            int tempHandle = (int)GetActiveWindow();
            if (handle != tempHandle)
            {
                handle = (int)GetActiveWindow();
                currentSelection = Application.Selection;

                // Retrieve handle of the Microsoft Word window.
                wordMain = new NativeWindow();
                wordMain.AssignHandle(new IntPtr(handle));

                // Hide the form off the screen
                autoCompleteForm.Location = new Point(-1000, -1000);
                notificationForm.Location = new Point(-1000, -1000);
                extendSuggestionForm.Location = new Point(-1000, -1000);

                // Reassign forms' parent
                autoCompleteForm.Visible = false;
                autoCompleteForm.showForm(wordMain); // Assign the form parent to the current active window
                autoCompleteForm.Focus(); // In order to make the child form appear infront of the parent form
                autoCompleteForm.Hide();

                notificationForm.Visible = false;
                notificationForm.Show(wordMain); // Assign the form parent to the current active window
                notificationForm.Focus(); // In order to make the child form appear infront of the parent form
                notificationForm.Hide();

                extendSuggestionForm.Visible = false;
                extendSuggestionForm.Show(wordMain);
                extendSuggestionForm.Focus();
                extendSuggestionForm.Hide();

                wordMain.ReleaseHandle();
            }

            if (!isEnabled && isDisablePopUp)
            {
                Globals.ThisAddIn.Dispatcher.Invoke(new displayMessageDelegate(displayMessage), new Object[] { ERROR_CONNECTION });

                // Disable the pop-up
                isDisablePopUp = false;
            }

            BackgroundWorker b = new BackgroundWorker();
            b.DoWork += delegate(object sender2, DoWorkEventArgs e2)
            {
                try
                {
                    if (isEnabled)
                    {
                        // Inform ACP to change destination document
                        logic.setDestinationDocument(handle);
                    }
                }
                catch (SocketException e)
                {
                    Globals.ThisAddIn.Dispatcher.Invoke(new displayMessageDelegate(displayMessage), new Object[] { ERROR_CONNECTION });
                    markServerDown();
                }
            };
            b.RunWorkerAsync();

            updateApplicationSizeDetail();
            SetActiveWindow(new IntPtr(tempHandle));
        }