Hiding ADXWordTaskpane by Default

Add-in Express™ Support Service
That's what is more important than anything else

Hiding ADXWordTaskpane by Default
 
Premkumar Elangovan




Posts: 14
Joined: 2018-12-28
Dear Team,
I am trying to hide the adxWordTaskPane by default when a user opens MS Word or opens a Word document. I migrated from VSTO to Add-in Express. I used to do this by directly using the taskPane.Visible property in VSTO. From the forums, I understand that it needs to be done slightly differently with Add-in Express. So I used the following approach proposed by the Add-In Express Team. This was working fine in Word 2007, 2010, 2013, 2016 and Office 365. Suddenly customers are complaining that the taskPane is always empty, and this is specifically happening with Office 365 on Windows 10. It works for some people and doesn?Â?Ð?ét for others. We figured out that this is happening with customers who signed up for the Office insider program. We have temporarily resolved the issue by commenting out the code that hides the taskPane so that adxTaskpane is always visible by default. Another way was to instruct the users to change their Office settings to ?Â?Ð?èOptimize for Compatibility?Â?Ð?é mode. I would appreciate your thoughts on this. Is there a simple way to just hide the taskPane completely by defualt rather than just minimizing it?


**AddinModule.cs**
public bool LetPaneShow { get; private set; }
  private void Button_OnClick(object sender, IRibbonControl control, bool pressed)
  {
     ResultsWordTaskPane taskPane =  ResultsWordTaskPane)this.adxWordTaskPanesCollectionResults.CurrentTaskPaneInstance;
     LetPaneShow = true;
     taskPane.Show();
     taskPane.RegionState = AddinExpress.WD.ADXRegionState.Normal;
  }
  
  private void adxWordAppEvents1_DocumentOpen(object sender, object hostObj)
  { 
    ResultsWordTaskPane taskPane = (ResultsWordTaskPane)this.adxWordTaskPanesCollectionResults.CurrentTaskPaneInstance;    
    if (taskPane != null)
    {
       LetPaneShow = false;
        taskPane.Hide();
	}
  }

  private void adxWordAppEvents1_NewDocument(object sender, object hostObj)
  { 
    ResultsWordTaskPane taskPane = (ResultsWordTaskPane)this.adxWordTaskPanesCollectionResults.CurrentTaskPaneInstance;    
    if (taskPane != null)
    {
	  LetPaneShow = false;
      taskPane.Hide();
	}
  }
  
  ** ResultsWordTaskPane.cs**
   private void ResultsWordTaskPane_ADXBeforeTaskPaneShow(object sender, ADXBeforeTaskPaneShowEventArgs e)
   {    
       this.Visible = REF_N_WRITE_AddIn.AddinModule.CurrentInstance.LetPaneShow;  
   }
Posted 08 Mar, 2019 08:44:39 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Premkumar,

Premkumar Elangovan writes:
I am trying to hide the adxWordTaskPane by default when a user opens MS Word or opens a Word document.


You prevent an ADXWordTaskPane from being shown by setting ADXWordTaskPane.Visible = false in the ADXWordTaskPane.ADXTaskPaneBeforeShow event. Although you do this in your code, you incorrectly expect that a task pane instance is available when the DocumentOpen and NewDocument occurs. The point is: Add-in Express deals with the windowing of the host application and this is wholly possible that the object model fires an event (such as DocumentOpen) while the actual window that should show the document is not created yet; in this scenario, Add-in Express creates the pane instance when the actual window is created.

I suggest that you modify your code in the following fashion. Currently, the ResultsWordTaskPane_ADXBeforeTaskPaneShow method checks the variable which is set by other parts of your add-in. Instead, it should initiate a request e.g. by calling a method in the add-in module. When doing the calls in this order, you guarantee that the form instance exists. You may need to know the document for which the pane is about to show: use ADXWordTaskPane.WindowObj. That property returns an object representing a Word.Window or Word.ProtectedViewWindow object; you may want to do the cast.

I suggest that you check section The UI Mechanics, see the PDF file in the folder {Add-in Express}\Docs on your development PC.

Premkumar Elangovan writes:
Suddenly customers are complaining that the taskPane is always empty


I assume you mean "the pane isn't shown"; if so, see the above. If, however, you mean "there're no controls on the pane" please let me know; I'll also need to know the build of AddinExpress.MSO.2005.dll and AddinExpress.WD.2005.dll referenced by your project.


Andrei Smolin
Add-in Express Team Leader
Posted 11 Mar, 2019 04:03:58 Top
Premkumar Elangovan




Posts: 14
Joined: 2018-12-28
Thanks for the response Andrei. The pane is shown correctly as it should, but there are no controls in it. We have a RichTextBox control in the pane. Please see the attached image that illustrates the problem. Build details are given below.

AddinExpress.MSO.2005.dll - 9.1.4620.0
AddinExpress.WD.2005.dll - 9.1.4620.0

User added an image
Posted 11 Mar, 2019 04:39:16 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Premkumar,

How do you populate the pane with controls? Does the issue occur if you pre-create some controls at the design time?


Andrei Smolin
Add-in Express Team Leader
Posted 11 Mar, 2019 05:06:51 Top
Premkumar Elangovan




Posts: 14
Joined: 2018-12-28
Hi Andrei,
I add controls in the designer view of the adxTaskPane, as shown in the attached image. The controls are very simple, just three richTextBoxes in three tabs. The text in TextBoxes are updated when the user interacts with the Add-In. I think the problem is to do with the mechanism of hiding the Pane. If I comment out the code that attempts to completely hide the Pane on loading by modifying the Visible property, it all works fine.




User added an image
Posted 11 Mar, 2019 07:25:46 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Premkumar,

We suppose the issue relates to multi-DPI support. It looks like the DPI context of the Word window is different from the DPI context of the pane itself.

You can try to bypass this issue in this way. Override the CreateHandle() method of the ADXWordTaskPane class. Before you call base.CreateHandle(), you should 1) call GetWindowDpiAwarenessContext() passing it this.HostHandle which contains the handle of the Word window, and 2) call SetThreadDpiAwarenessContext passing it the result of the previous call.

These Windows API functions are described at https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getwindowdpiawarenesscontext and https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setthreaddpiawarenesscontext. Note that they were introduced in Windows 10, version 1607.


Andrei Smolin
Add-in Express Team Leader
Posted 12 Mar, 2019 04:45:40 Top
Premkumar Elangovan




Posts: 14
Joined: 2018-12-28
Thanks Andrei. I will try it and let you know how it goes.
Posted 12 Mar, 2019 05:46:52 Top