C# 如何使用windows API删除应用程序的菜单栏?

C# 如何使用windows API删除应用程序的菜单栏?,c#,winapi,api,C#,Winapi,Api,我正在使用下面的代码删除一个应用程序的标题栏,它在记事本上运行得非常好。现在我想删除菜单栏也。如何实现 //Finds a window by class name [DllImport("USER32.DLL")] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); //Sets a window to be a child win

我正在使用下面的代码删除一个应用程序的标题栏,它在记事本上运行得非常好。现在我想删除菜单栏也。如何实现

  //Finds a window by class name
        [DllImport("USER32.DLL")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        //Sets a window to be a child window of another window
        [DllImport("USER32.DLL")]
        public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        //Sets window attributes
        [DllImport("USER32.DLL")]
        public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

        //Gets window attributes
        [DllImport("USER32.DLL")]
        public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
        static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);


        //assorted constants needed
        public static int GWL_STYLE = -16; 
        public static int WS_BORDER = 0x00800000; //window with border
        public static int WS_DLGFRAME = 0x00400000; //window with double border but no title
        public static int WS_CAPTION = WS_BORDER | WS_DLGFRAME; //window with a title bar

        public void WindowsReStyle()
        { 
            Process[] Procs = Process.GetProcesses();
            foreach (Process proc in Procs)
            {

                if (proc.ProcessName.StartsWith("notepad"))
                {
                    IntPtr pFoundWindow = proc.MainWindowHandle;
                    int style = GetWindowLong(pFoundWindow, GWL_STYLE);
                    SetWindowLong(pFoundWindow, GWL_STYLE, (style & ~WS_CAPTION));
                }
            }
    }

你不能隐藏它们,你需要使用API来移除它们,根据这样做的结果

    [DllImport("USER32.DLL")]
    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
    static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);

    [DllImport("user32.dll")]
    static extern IntPtr GetMenu(IntPtr hWnd);

    [DllImport("user32.dll")]
    static extern int GetMenuItemCount(IntPtr hMenu);

    [DllImport("user32.dll")]
    static extern bool DrawMenuBar(IntPtr hWnd);

    [DllImport("user32.dll")]
    static extern bool RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags);

    public static uint MF_BYPOSITION = 0x400;
    public static uint MF_REMOVE = 0x1000;

    public static void WindowsReStyle() {
        Process[] Procs = Process.GetProcesses();
        foreach (Process proc in Procs) {

            if (proc.ProcessName.StartsWith("notepad")) {
                //get menu
                IntPtr HMENU = GetMenu(proc.MainWindowHandle);
                //get item count
                int count = GetMenuItemCount(HMENU);
                //loop & remove
                for (int i = 0; i < count; i++)
                    RemoveMenu(HMENU, 0, (MF_BYPOSITION | MF_REMOVE));

                //force a redraw
                DrawMenuBar(proc.MainWindowHandle);
            }
        }
    }
[DllImport(“USER32.DLL”)]
公共静态外部IntPtr FindWindow(字符串lpClassName,字符串lpWindowName);
[DllImport(“user32.dll”,EntryPoint=“FindWindow”,SetLastError=true)]
静态外部IntPtr FindWindowByCaption(IntPtr zeronly,字符串lpWindowName);
[DllImport(“user32.dll”)]
静态外部IntPtr GetMenu(IntPtr hWnd);
[DllImport(“user32.dll”)]
静态外部int GetMenuItemCount(IntPtr hMenu);
[DllImport(“user32.dll”)]
静态外部布尔图菜单栏(IntPtr hWnd);
[DllImport(“user32.dll”)]
静态外部布尔删除菜单(输入菜单、单元上移菜单、单元下移菜单);
公共静态uint MF_BYPOSITION=0x400;
公共静态uint MF_REMOVE=0x1000;
公共静态void WindowsReStyle(){
Process[]Procs=Process.getprocesss();
foreach(过程中的过程){
if(proc.ProcessName.StartsWith(“记事本”)){
//获取菜单
IntPtr HUMENU=GetMenu(程序MainWindowHandle);
//获取项目计数
int count=GetMenuItemCount(HMENU);
//循环和移除
for(int i=0;i
我需要同样的。但在我的应用程序中应用这段代码时,它隐藏了在上面进行一些鼠标交互(如拖放等)的标题栏。你能告诉我根本原因吗?