Here is the code:
internal static class Utilities { [DllImport("user32.dll")] internal extern static int SetWindowLong(IntPtr hwnd, int index, int value); [DllImport("user32.dll")] internal extern static int GetWindowLong(IntPtr hwnd, int index); internal static void HideMinimizeAndMaximizeButtons(IntPtr hwnd) { const int GWL_STYLE = -16; const long WS_MINIMIZEBOX = 0x00020000L; const long WS_MAXIMIZEBOX = 0x00010000L; long value = GetWindowLong(hwnd, GWL_STYLE); SetWindowLong(hwnd, GWL_STYLE, (int)(value & ~WS_MINIMIZEBOX & ~WS_MAXIMIZEBOX)); } }
As stated in Daniel Moschmondor's answer , you need to find the Excel Windows descriptor, and then just call the above code as follows:
Utilities.HideMinimizeAndMaximizeButtons(windowHandle);
NB
Perhaps depending on how you start the Excel process, you may already have a process or window handle, so just use it without calling Process.GetProcessesByName(...) / Process.GetProcesses()
EDIT:
If you start Excel using
ApplicationClass _excel = new ApplicationClass();
Just use the following code:
IntPtr windowHandle = new IntPtr(_excel.Hwnd); Utilities.HideMinimizeAndMaximizeButtons(windowHandle);
source share