Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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)
@dhermosillo
Copy link

dhermosillo commented Mar 17, 2015

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

JairoQuispe commented Aug 11, 2017

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