Hide the Maximize, Minimize and Close Button of a Word Document

A

Aritra Saha

We need to hide the maximize, minimize and Close Button of a Word Document
Window(Microsoft.Office.Interop.Word.Document.Window). I have tried the
following approach using the Win32 API (user32.dll), however none of them
work.

IntPtr h = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
h = NativeMethods.FindWindowExW(h, new IntPtr(0), "_WwF", "");
h = NativeMethods.FindWindowExW(h, new IntPtr(0), "_WwB",
tempDoc.ActiveWindow.Caption);

const int GWL_STYLE = -16;
long windowLong = NativeMethods.GetWindowLong(h, GWL_STYLE);
windowLong = windowLong & -131073 & -65537;
NativeMethods.SetWindowLong(h, GWL_STYLE, (System.IntPtr)windowLong);

Another approach (not working !)
int remove = 1024;
int disable = 2;
IntPtr menu;
int itemCount;

//get the system menu of the application
menu = NativeMethods.GetSystemMenu(h, false);

//get the count of menu items in the system menu
itemCount = NativeMethods.GetMenuItemCount(menu);

//disable the "Close" command in the menu
NativeMethods.RemoveMenu(menu, itemCount - 1, disable |
remove);

NativeMethods.DrawMenuBar(h);


Please advice.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top