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.
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.