是否可以使用C#删除另一个应用程序的大小调整和关闭?
我想知道是否可以删除使用C#关闭其他窗口的功能 我知道您可以重写windows的close()方法,但其他进程也可以这样做吗?那么将另一个进程的窗口样式更改为fixed_uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu 到目前为止,我已经获得了应用程序的主窗口句柄,并且删除了所有按钮和菜单,但我仍然需要找出如何使其不可关闭和不可调整 以下是我得到的:是否可以使用C#删除另一个应用程序的大小调整和关闭?,c#,winapi,computer-science,C#,Winapi,Computer Science,我想知道是否可以删除使用C#关闭其他窗口的功能 我知道您可以重写windows的close()方法,但其他进程也可以这样做吗?那么将另一个进程的窗口样式更改为fixed_uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu 到目前为止,我已经获得了应用程序的主窗口句柄,并且删除了所有按钮和菜单,但我仍然需要找出如何使其不可关闭和不可调整 以下是我得到的: using System; using System.Collecti
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace ThirdTest
{
class Program
{
#region Constants
//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);
[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);
//assorted constants needed
public static uint MF_BYPOSITION = 0x400;
public static uint MF_REMOVE = 0x1000;
public static int GWL_STYLE = -16;
public static int WS_CHILD = 0x40000000; //child window
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 static int WS_SYSMENU = 0x00080000; //window menu
#endregion
public static void WindowsReStyle()
{
Process[] Procs = Process.GetProcesses();
foreach (Process proc in Procs)
{
Console.WriteLine("Found process: " + proc.ProcessName.ToString());
if (proc.ProcessName.StartsWith("notepad"))
{
IntPtr pFoundWindow = proc.MainWindowHandle;
int style = GetWindowLong(pFoundWindow, GWL_STYLE);
//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);
SetWindowLong(pFoundWindow, GWL_STYLE, (style & ~WS_SYSMENU));
SetWindowLong(pFoundWindow, GWL_STYLE, (style & ~WS_CAPTION));
}
}
}
static void Main(string[] args)
{
WindowsReStyle();
}
}
}
使用系统;
使用System.Collections.Generic;
使用系统诊断;
使用System.Linq;
使用System.Runtime.InteropServices;
使用系统文本;
使用System.Threading.Tasks;
命名空间第三名
{
班级计划
{
#区域常数
//按类名查找窗口
[DllImport(“USER32.DLL”)]
公共静态外部IntPtr FindWindow(字符串lpClassName,字符串lpWindowName);
//将一个窗口设置为另一个窗口的子窗口
[DllImport(“USER32.DLL”)]
公共静态外部IntPtr SetParent(IntPtr hWndChild、IntPtr hwndnnewparent);
//设置窗口属性
[DllImport(“USER32.DLL”)]
公共静态外部intsetWindowLong(IntPtr hWnd、intnindex、intdwnewlong);
//获取窗口属性
[DllImport(“USER32.DLL”)]
公共静态外部intgetWindowLong(IntPtr hWnd,intnindex);
[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;
公共静态int GWL_STYLE=-16;
公共静态int WS_CHILD=0x40000000;//子窗口
公共静态int WS_BORDER=0x00800000;//带边框的窗口
public static int WS_DLGFRAME=0x00400000;//带有双边框但没有标题的窗口
public static int WS_CAPTION=WS_BORDER | WS_DLGFRAME;//带有标题栏的窗口
公共静态int WS_SYSMENU=0x00080000;//窗口菜单
#端区
公共静态void WindowsReStyle()
{
Process[]Procs=Process.getprocesss();
foreach(过程中的过程)
{
WriteLine(“找到的进程:+proc.ProcessName.ToString());
if(proc.ProcessName.StartsWith(“记事本”))
{
IntPtr pFoundWindow=proc.MainWindowHandle;
int style=GetWindowLong(pFoundWindow,GWL_样式);
//获取菜单
IntPtr HUMENU=GetMenu(程序MainWindowHandle);
//获取项目计数
int count=GetMenuItemCount(HMENU);
//循环和移除
for(int i=0;i
有什么想法吗?(:
正如我在评论中所说,以下是关于这个问题的更多细节:
我需要两个应用程序并排在显示器上。
它们都不能关闭或调整大小。一个是浏览器,另一个是名为“Z-tree”的应用程序。
我已经修复了Z-tree的问题,因为默认情况下,Z-tree运行时没有关闭按钮,也没有调整大小,您可以在命令行中指定Z-tree的大小和位置。如果您使用以下选项启动internet explorer,则可以强制它进入“无法使用”的全屏模式:
iexplore -k www.google.com
这就是商店和其他东西让它运行的方式,所以没有人可以关闭它。当然,你可以通过任务管理器关闭它,但这只会让大多数用户很难关闭它
(CTRL-W将关闭它还有一个想法,创建一个winforms项目并设置窗口,使其无法调整大小。然后在表单中嵌入一个WebBrowser控件,并在表单加载中导航到您的页面:
private void Form1_Load(object sender, EventArgs e)
{
//catch form closing event to prevent form being closed using alt-f4
FormClosing += Form1_FormClosing;
//remove close button from toolbar and remove window border to prevent
//moving and resizing
this.ControlBox = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
//set position to half of the screen
this.Left = Screen.PrimaryScreen.Bounds.Width / 2;
this.Top = 0;
this.Width = Screen.PrimaryScreen.Bounds.Width / 2;
this.Height = Screen.PrimaryScreen.Bounds.Height;
//mark the window as a top level window, reducing users ability to alt-tab away
TopMost = true;
webBrowser1.Navigate("www.google.com");
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
//prevent form being closed
e.Cancel = true;
}
//the only way to close the form
void DoExit()
{
//remove the closing handler first or it won't close
FormClosing -= Form1_FormClosing;
Close();
}
当然不是。任何人都可以用任务管理器扼杀流程,而这个窗口就要消失了。在替代方案如此简单的情况下采取过度的应对措施是没有效果的。你是在谈论托管应用程序还是其他任何应用程序?@HansPassant:这是一个一次性的科学项目。没有人会使用任务管理器-我只是不希望他们能够公然关闭它。@WeylandYutani:一个特定的应用程序(Internet Explorer或Google Chrome),你可以创建一个没有关闭框的全屏窗口,其中包含一对控件。这不是我想要的-我需要两个并排运行的应用程序(都不可关闭)。这其实不是一个坏主意!我能使Form1不可关闭、不可缩放并占据50%的屏幕吗?是的,将ControlBox设置为false,将formbordersize设置为fixedtoolwindow将删除所有工具栏按钮并阻止调整大小。然后,您只需使用正确的宽度和高度对其进行初始化,事实上,将FormBorderStyle设置为None更好,因为它完全删除了边框,并防止用户移动窗口。我已更新了代码,以防止用户使用ALT-F4U关闭窗口。谢谢