Skip to content

Instantly share code, notes, and snippets.

@hinchley
Created January 18, 2015 09:03
Show Gist options
  • Save hinchley/f4bd00110ff1d155be0b to your computer and use it in GitHub Desktop.
Save hinchley/f4bd00110ff1d155be0b to your computer and use it in GitHub Desktop.
Disable Microsoft Office 2013 Border Shadow with PowerShell
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
namespace Utilities {
public static class Display {
private const uint WM_USER = 0x0400;
private const uint WM_MSO = WM_USER + 0x0900;
private const uint WM_MSO_WPARAM_OMFRAMEENABLESHADOW = 0x0075;
private const uint WM_MSO_LPARAM_SHADOW_DISABLED = 0x0000;
private const uint WM_MSO_LPARAM_SHADOW_ENABLED = 0x0001;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(
IntPtr hWnd,
UInt32 Msg,
IntPtr wParam,
IntPtr lParam
);
public static void DisableShadows(IntPtr hwndOfficeApp) {
SendMessage(
hwndOfficeApp,
(UInt32) WM_MSO,
(IntPtr) WM_MSO_WPARAM_OMFRAMEENABLESHADOW ,
(IntPtr) WM_MSO_LPARAM_SHADOW_DISABLED
);
}
public static void EnableShadows(IntPtr hwndOfficeApp) {
SendMessage(
hwndOfficeApp,
(UInt32) WM_MSO,
(IntPtr) WM_MSO_WPARAM_OMFRAMEENABLESHADOW ,
(IntPtr) WM_MSO_LPARAM_SHADOW_ENABLED
);
}
}
}
"@
$hwnd = @(Get-Process winword)[0].MainWindowHandle
[Utilities.Display]::DisableShadows($hwnd)
@joshuavorbiszW
Copy link

I get:
Cannot convert argument "0", with value: "", for "DisableShadows" to type "System.IntPtr": "Cannot convert null to type
"System.IntPtr"."
At line:1 char:36

  • [Utilities.Display]::DisableShadows <<<< ($hwnd)
    • CategoryInfo : NotSpecified: (:) [], MethodException
    • FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

@JairoQuispe
Copy link

How to enable by default "DisableShadow" ?

@wdnz
Copy link

wdnz commented Jan 25, 2018

@benyaminl
Copy link

benyaminl commented Jan 3, 2021

Is there anyway to make it permanent?
Thanks


Still work with Office 2019 and O365, Just tried as I wrote this question. Seems the article above is already taken down and M$ have no intention to make it as an option for a default option. So Sad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment