一个考核软件,交卷后会弹出分数窗口,我要做一个小窗口,讲他覆盖,我要加一个我做的这个小窗口前置,不在下面菜刀任务栏显示,然后我点确定后后面这个分数窗口自动关闭


一个考核软件,交卷后会弹出分数窗口,我要做一个小窗口,讲他覆盖,我要加一个我做的这个小窗口前置,不在下面菜刀任务栏显示,然后我点确定后后面这个分数窗口自动关闭


以下内容由AIGC及阿里嘎多学长共同生成、有用望采纳:
要实现您所描述的功能,您需要编写一个小程序或脚本,这个程序需要能够创建自定义窗口、控制窗口的显示层级以及与操作系统进行交互以关闭其他窗口。以下是一些基本的步骤和示例代码,以帮助您开始实现这些功能:
在Windows系统中,您可以使用C#和WinForms来创建自定义窗口。以下是一个简单的示例:
using System;
using System.Windows.Forms;
public class CustomDialog : Form
{
public CustomDialog()
{
this.Text = "自定义窗口";
this.Width = 300;
this.Height = 200;
this.StartPosition = FormStartPosition.CenterScreen;
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.TopMost = true; // 窗口始终在最前
this.Controls.Add(new Button { Text = "确定", DialogResult = DialogResult.OK });
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.BringToFront(); // 确保窗口在最前
}
}
public class Program
{
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var customDialog = new CustomDialog();
customDialog.ShowDialog();
}
}
在上面的代码中,this.TopMost = true; 属性确保了窗口在最前显示。this.BringToFront(); 方法在窗口加载时将其置于最顶层。
要关闭另一个窗口,您需要知道该窗口的句柄(HWND)。以下是一个使用C#和Windows API的示例,它发送一个关闭消息给指定的窗口:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class CustomDialog : Form
{
// ... 其他代码 ...
private const int WM_CLOSE = 0x10;
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
private void Button_Click(object sender, EventArgs e)
{
// 假设您已经找到了分数窗口的标题或类名
string windowTitle = "分数窗口的标题";
string windowClass = "分数窗口的类名";
IntPtr hWnd = FindWindow(windowClass, windowTitle);
if (hWnd != IntPtr.Zero)
{
PostMessage(hWnd, WM_CLOSE, 0, 0);
}
this.Close();
}
}
// ... Program 类 ...
请注意,您需要替换 windowTitle 和 windowClass 为实际的分数窗口的标题或类名。您可以使用工具如Spy++(包含在Visual Studio中)来获取这些信息。
这些代码只是一个起点,您可能需要根据您的具体需求进行调整。此外,确保您了解并遵守所有相关的安全和隐私法规,特别是当您的程序与其他应用程序交互时。