/* Reload the ribbon on Office Applications.
*
* Word (and some other Office applications) only seem to reload the ribbon when changing between different Word
* windows. So, if two Word windows are open then WM_ACTIVATE is sent to each one to simulate this. If only a single
* window is open then a new one is created and closed before sending WM_ACTIVATE.
*
* Copyright 2019 Raising the Floor - International
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* The R&D leading to these results received funding from the
* Department of Education - Grant H421A150005 (GPII-APCP). However,
* these results do not necessarily represent the policy of the
* Department of Education, and you should not assume endorsement by the
* Federal Government.
*
* You may obtain a copy of the License at
* https://github.com/GPII/universal/blob/master/LICENSE.txt
*/
namespace GPIIOffice
{
using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
#if GOT_OFFICE
// GOT_OFFICE can be defined during development if the Office PIAs are installed.
// (Put it in a project and add a reference to Microsoft.Office.Interop.Word)
using Word = Microsoft.Office.Interop.Word;
#endif
public class RibbonReload
{
private const int WM_ACTIVATE = 0x6;
private const int HWND_TOPMOST = -1;
private const int HWND_NOTOPMOST = -2;
private const int SWP_NOMOVE = 0x0002;
private const int SWP_NOSIZE = 0x0001;
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);
[DllImport("user32.dll")]
private static extern bool SetWindowPos(int hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, int uFlags);
[DllImport("user32.dll")]
private static extern bool LockSetForegroundWindow(uint uLockCode);
#if STANDALONE
static void Main(string[] args)
{
new RibbonReload().Invoke(new { applicationName = "Word" }).Wait();
}
#endif
///
/// Entry point for edge.js
///
/// object containing 'applicationName'
/// true on success
public async Task